Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <02a90baafce39d328db5c93a18fdf9663b99afbc@i2pn2.org>
Deutsch   English   Français   Italiano  
<02a90baafce39d328db5c93a18fdf9663b99afbc@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: fir <fir@grunge.pl>
Newsgroups: comp.lang.c
Subject: Re: 'thatenums' in practice & function names as enums
Date: Tue, 20 Aug 2024 14:14:01 +0200
Organization: i2pn2 (i2pn.org)
Message-ID: <02a90baafce39d328db5c93a18fdf9663b99afbc@i2pn2.org>
References: <f0df618e6d4f6af0e48fc42d3894ce082ec99fe9@i2pn2.org> <2999e12cff5a1d64afc3f1dbc47797ec09a501af@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 20 Aug 2024 12:14:02 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="3228095"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <2999e12cff5a1d64afc3f1dbc47797ec09a501af@i2pn2.org>
Bytes: 5844
Lines: 190

fir wrote:
> fir wrote:
>>
>>
>> i get back for a while to coding (though my health
>> is real disaster)
>>
>> i think about maybe not even writing some 'paragraph'
>> game (i mean game that writes paragraph of text, then gives
>> options to chose A) B) C) .. then writes next paragraph and
>> this is a game
>>
>> coding it is itself easy, especially if someone has
>> learned a library for this it mainly look like this
>>
>> CastleScreen()
>> {
>>    clear_screan();
>>    text("Youre in a Castle of Baron blblabla..")
>>    text("a) talk with baron")
>>    text("b) go to kitchen")
>>    //...
>> }
>>
>> runFrame()
>> {
>>    if(screen=='castle') CastleScreen();
>>    if(screen=='river') RiverScreen();
>>    //.... and so on tens of that
>>
>> }
>>
>> OnKeyDown(int key)
>> {
>>    if(screen=='castle)
>>    {
>>      if(key=='A') screen == 'baron'
>>      if(key=='B') screen == 'kitchen'
>>    }
>>
>>    //.....
>> }
>>
>> and thats it its basically all of it
>> (add yet few state variables like kitchen_visited
>> atc to make soem mechanics)
>>
>> one question i had in mind was it that could be
>> yet simplified , bot in c or as extension in soem langage
>>
>> it seem that there is some Simplification and it is to
>> use callback like CurrantScreen and assign pointers
>> to screen functions to it
>>
>> it is bold/brave though and im not sure if i should
>> do that - there seem to be tremendous advantage not
>> having this kind of enums at all (real advantage
>> as if game has hundreds of screens - and probably
>> would need it like books has hundreds of pages) then
>> you damn type hundred of enums and function names
>> and there is a lot of (sadly not much 'scalable') code
>> jumping and resolving typos (which is monkeyish
>> work)
>>
>> second advantage is that Fuction names can be enough long
>> and 'thiskind' of enums are not  (below on this)
>>
>> this idea to getting rid of this literal enums
>> is somewhat bold/brave as i said and i not rethinked
>> what this danger may be? do you maybe know?
>>
>> second thing is using this 'literal enums '
>> for signs like 'sdas' is for sure not enough
>> for this use case so i need at least eight or
>> more
>>
>> doeas maybe someone know how to enforce it
>> (im using 32bit mode mingw/gcc)
>>
>> need i write
>>
>> unsigned long long screen;
>>
>> and then type "screen='aasasas'" and "if(screen=='aasasas')"
>> or i need something more to be safe (liek adding L before
>> like L'aasasas'
>>
>> im terribly sick and weary and not made initial
>> experimentation what work... if i use those long literals
>> it seem to work (compiles) but it seem some reduce
>> to teh same (probably last 4 being significant) and it makes errors
>>
>> ?
>> tnx for answer
>
> i tested it a bit and it seem callbacks are far better
> 1 enums vanish and trupbles with them
> 2 there is good separation of functions
> like castle_screen() {} and catsle_keys() {}
> where in prevoius one screens was separate and
> keys was in one giant switch
>
> hovever the switching those screen/keys pairs could be
> imporoved as i can have
>
> screen=castle_screen;
> keys=castle_keys;
>
> or (better imo) using structure
>
> call = {castle_screen, keys};
>
> but in fact if there woudl be some of function structures
>
> castle
> {
>    void screen() {}
>    void keys(int key) {}
> }
>
> then one could just swich by writing call = castle
> and that would further improve code
>

in those examples above

castle
{
   void screen() {}
   void keys(int key) {}
}

river
{
   void screen() {}
   void keys(int key) {}
}

ant the usesge like

current = castle;
current = river;

current.screen()
current.keys(key)

this "castle" or "river" are just part of names
and the current is a callback structure

but i could try to think how to generalise it
(though my form is specialy bad btw, and thinking
not much glues this months)

one think if this current structure shouldnt be defined
authomatically (it could but probably not necessary)

here "river*" could also be understand as a pointer
to 2 pointers - though as something like this not
exist - becouse those 2 pointers must be hold
together wich takes ram - so i think river* is
more like structure of 2 pointers

okay at least that

the question is what if there are more functions


castle
{
   void screen() {}
   void keys(int key) {}
   void foo() {}
}

river
{
   void screen() {}
   void keys(int key) {}
   void bar() {}
========== REMAINDER OF ARTICLE TRUNCATED ==========