Main Menu

Some Qs

Started by Jonsul, November 07, 2010, 09:49:53 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jonsul

Okay I've been rolling around what kind of questions I want to ask lately, and I think I'm ready to ask now after looking around. First what kind of programming paradigms are used or possible in bennu? Like functional programming, object oriented programming...

Next can someone explain frames a bit more for me. I understand that it's parallel programming, or like a way to automatically multithread multiple parts of your program. I also think I get it that a process is like a function until it reaches a "frame" keyword, then it continues to the next part of code after the process call while running the remaining code in the process as well. Is this correct? I just have one question though, I've seen examples running multiple frames within the same process. What does this accomplish? Isn't it already running in parallel?

Lastly, struct is really similar to defining your own type. But then what's the difference from making a datatype with the "type" keyword? It seems that the only difference is that you can make multiple instances of your datatype :/

Making arrays are rather odd, I saw the example: int numbers[9]
and that it makes an array of 10 numbers, so does every datatype have the possibility to become an array?

Also in lisp one can give functions as arguments to other functions and can return functions as well, is this possible?

[edit]
Oh yeah, I think I get public variables but it's still a little hazy. It's almost similar to OO programming in that you access the variables through the namespace. Also if you want any other program or function to use them anywhere in the program you can declare them at
the top.

Thanks alot guys :D
take care

handsource-dyko

Bennu, as I have always understood is not truely a object oriented language, but has some ideas from it.
Processes can run in parallel, you have see it like a form cooperative multitasking. If you omit frame statements
in a REPEAT-UNTIL and WHILE-END an LOOP-END loops, you block the system. The FRAME statement let's the
process scheduler know that it can move to the next bit of code. The reason, again is because of the semi-parallel
thing.

As you probably know, you can also use functions, that can return value's. I believe (but I'm not sure) that processes
can't do this. You can put functions into arguments, but I don't know if they can return functions, actually I've never
heard of this concept and I don't know where to use it for.

O, by the way, you can also use the FRAME statement with an argument like FRAME(1000); then it acts as a delay, wich
can be usefull on keyboard scanning and text writing/deleting. After I use th key() function I generally put something like
frame(100), to buffer the input. Otherwise, the key is responds to quickly, so you can use it to slow things down if
necessary.

I'f never seen any benifit from TYPE, as I rarely use it. I use structs any time, and I like to nest them too. Also, you can
even make struct-array's like pascal records. I've never seen any example of this in C. Actually, it's a nice feature, also
because you can save/load them as DAT files with the save() and load() functions. Save and Load are magical commands,
as they work out all the fopen and fread stuff for you, even if you make very mixed data structures with strings in 'em.

Unfortunately there's no documentation on how these two functions work, so they are not advisable for files that need to
be read by programs made in other languages. (Splinter, please tell us how it works so C/freepascal/visual basic/whatever
programs can be made to read/write varspace binary files.)

O, yeah, as final note you can also do things like   string mystring[9]; to create a table of 10 strings.

Jonsul

Actually I'm not sure why I asked about returning functions as that's a very Lispy thing. lol  It's useful to make a function that creates and returns another function that could be slightly altered every time you run it. It's very useful to help cut back on code bloat by removing several similar code blocks that are only slightly different.

Well my question with the frame statements was kinda about something like this:
Process int SayHelloWorld()
Begin
    say("SayHelloWorld: 1"); // this gets run in the first frame
    frame; // wait for the second frame to start
    say("SayHelloWorld: 2"); // this one in the second frame
    frame; // wait for the third frame to start
    say("SayHelloWorld: 3"); // this one in the third frame
End

That's an example in the beginner tutorial.

I actually think I'm going to use TYPE a lot, as it's a common thing done in my home language Lisp. Hmmm your right, save and load seems like a pretty nice, but I could use them with my own datatypes still right?

Thanks a lot!

handsource-dyko

In the example you showed, the frame statement doesn't seem to do anything meaningfull. I guess you should try this
example in combination with the set_fps function, and try see if different fps settings have any effect on this.

You can use save and load with you're own data types, especially structs, but also arrays. I think it also works on types.
Save and load are more convenient then the traditional fopen/fread/fwrite approach. As I said earlier, load and save hide a
lot of messy details for you, but they are a black box. I wouldn't know how read files made with save in another language.

Maybe Splinter could explain more about this, maybe give some examples on how to deal with load and save dat files in C or
whatever.

Drumpi

#4
Let see.

Bennu works running all process at same time (well, it isn't true, but it's for explanation). All code is based on FPS or Frames Per Second, so, it must show X images per second. So, between image and image (frame and frame) Bennu execute code.
As i said, all process executes at same time so you need to sync them. In C, you get a process, and process scheduler runs it until time (or resources, or code, or anything else) runs out, and execute other process, but you can run first process 10 times and second 3 times.

So, FRAME is a function who can sync your process to execute one time per frame (this is why it calls FRAME): every process execute his code until it reach FRAME statement, then it wait until all remaining process reach their owns FRAME, and then Bennu puts an image on screen.

Yes, you can put many FRAMEs on your process, because you need to execute 3 tasks on 3 different frames (first move up, then down, making a earthquake), but you need to make a FRAME on every process to show in screen. If not, process will run forever, because it didn't sync, it not complete a 100% frame.

And this is brackets meaning: FRAME(200) means this process complete a 200% of a frame, so it has been "executed" 2 times, so next frame it doesn't will execute. But if you use FRAME(50), you only execute 50% of a frame, you still need to execute 50% frame, so, when every process has it's frame, it will execute again before show the actual image to reach it's own 100% frame or more. And this percent is accumulative for the next frame.


Functions are similar to process: you still can use frame, but it freezes his father (the process/function who calls it) and can return a data.

Struct and Types are very similar, but type don't define a variable, just a type. Struct can be "declared" as Global, Local, Private or Public, but you can't use them as a parameter for a functions/process (yes if you use pointers). Type can be used it that way.

If you use save, you only save an struct or a variable, so, if you save an int (SAVE(my_int)) you get a 4bytes file (little/big endian depends on your device), if you save a word, you will get a 2bytes file.
If you save:

type my_type
int a;
byte b,c,d;
word e;
end

my_type my_variable;
save("file.dat",my_variable);


You will get a 9bytes "file.dat" file: a+b+c+d+e=4+1+1+1+2=9bytes

You can do the same with FWRITE:

id_file=fopen("file.dat",o_write);
fwrite(id_file,my_variable);
fclose(id_file);


You will get the same file.
If you want to add a header, a "magic" string or else, you need to add to your struct or use FWRITE some times.


About OO, you can do it if you want, but not in C++ way: you can make some functions/process to manage part of your code, but you can't package them in a container (maybe you can put on another file and use INCLUDE to "paste" in your code), compile alone or get a private zone (you always see all code). I did some functions/process to manage a tiled scroll engine, just calling 3 functions, but it's still bennu code that you can modify.

I hope i could explain myself crystal clear, my english isn't good enough ^^U
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

Jonsul

Okay, interesting reads on the wiki! Here's a quick question for anyone who can answer, why are there multiple files for the same thing it seems. Like fpg and fgc or fh and inc? Are the fgc and fh legacy formats from fenix?

Thanks^^

Drumpi

FGC was a new FPG format for Fenix. Years ago we had some "legals troubles" with DIV rights owners, who said we cannot use DIV formats, so we try to create a new FPG format (FGC: Fenix Graphic Collection) and MAP format (FBM: Fenix BitMap). But some time later, that company go bankrupcy, so we still used FPG format.

FGC its the same as FPG, because Fenix made a new FPG standar (if you look for FPG format, you can see old FPG format (DIV format), and new F16 and F32 format).
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

Jonsul

#7
Thanks a lot guys
So what exactly is the reason for the fpg file, besides the obvious benefit of quickly loading all your graphics in one call? Or is that it. Also I heard some limitations using fpgs with wiz and caanoo, like a limit on the depth. Is that true?

[edit]
LOL I didn't see your last post Drumpi. Don't worry about your english skills you explained a lot to me about using FRAME, you should probably upload that in the wiki lol. It's kinda interesting to see how there are little bits of OO design here and there. I'm actually not an OO fanboy, I just see the use when it's appropriate, and gaming it can be useful I think.

Drumpi

Wiz and CAANOO had a limitation with bpp: they can't use 32bits mode, i don't know if a hardware issue or a SDL limitation.
FPG is only a bitmap container. You can load 999 images with one call... and that's all. But there are some functionally that are hidden and must think of it to find: one can be that you can change an animation only with FILE variable, you dont need to change GRAPH value (you can use one FPG for a low level character, and when it grows, just unload an FPG, and load a new FPG, and don't need to change GRAPH asignations or an animation array.

Maybe you can find more utilities, but FPG it's only a graphs container and only can be viewed with FPG editors and DIV-likes languajes.

There is a problem with me and wiki: i don't know the edit keywords, and all text needs a correction, i just only write a basic english, and don't want to put a low level english on wiki. Sorry :P
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)