Dark Bit Factory & Gravity

ARCHIVE => Archive => Cobra => Topic started by: GrahamK on March 13, 2007

Title: Cobra 'mini'
Post by: GrahamK on March 13, 2007
A new little teaser for you, just to show I'm taking demo coders seriously  :||

I've started on a 'bare bones' engine, based around the ptc stuff I've seen in other parts of the forum.. It's pretty basic at the moment, but it runs shocky's raster code reasonably well so far, while still retaining a lot of cobra functionality (as in core functionality, rather than gfx engine functionality).

At present it provides the ability to create frambuffers and read/write to them on a pixel by pixel basis, that's about it at the moment (full keyboard support is in there though).

Here is an example of the raster code:
Code: [Select]
// RASTER EFFECT BY SHOCKWAVE.
// ---------------------------
// FEBRUARY 2007.
// LAME I KNOW, BUT FROM LITTLE ACORNS ETC....!!!!
// updated to test the use of 'cobramini', a new low level lib for cobra.
//----------------------------------------------------------------------------------------------------------------------------------
PROGRAM USES cobramini, KEYSET
//----------------------------------------------------------------------------------------------------------------------------------
CONST XRES = 640
CONST YRES = 480
VAR
GADD : REAL =0
GADD2: REAL =0
GADD3: REAL =0
v,r,j:integer
//----------------------------------------------------------------------------------------------------------------------------------
        PROCEDURE INITIALISE()
        BEGIN
            OPENSCREEN( XRES , YRES)
        END         
//----------------------------------------------------------------------------------------------------------------------------------                 
//----------------------------------------------------------------------------------------------------------------------------------       
// MAIN PROGRAM
//----------------------------------------------------------------------------------------------------------------------------------

VAR
  Y        : INTEGER   
  RD,GR,BL : REAL
  t1,t2,d:real 
  frames,fps:integer
  ImagePointer:integer
BEGIN
INITIALISE()
frames = 0
t1 = millisecs
WHILE NOT KEYDOWN (VK_ESCAPE)
      GADD=GADD+1
    GADD2=GADD2+2
    GADD3=GADD3+3
             
    if Millisecs-t1< 1000 then
        inc(frames)
    else
        fps = frames
        frames = 0
        t1 = millisecs
    endif
    ImagePointer = currentmembuffer                 
   
        FOR Y=0 TO YRES-1       
            RD = 125+((SIN(Y+GADD3)*50)+(COS(Y+GADD2)*50)-(SIN(Y+GADD)*24))
            GR = 125+((SIN(Y+GADD2)*50)+(COS(Y+GADD)*50)+(SIN(Y+GADD3)*24))
            BL = 125+((SIN(Y+GADD)*50)-(COS(Y+GADD3)*50)-(SIN(Y+GADD2)*24))
            r = ToRGB(rd,gr,bl)
            v = ImagePointer + (y*xres*4)
            j=xres     
           
            asm
                @mov eax,[!r]     
                @mov ecx,[!j]
                @mov edi,[!v]
                @rep stosd
            endasm

        NEXT

   
    FLIP
WEND
  MessageBox('FPS:'+fps)
END

Nice thing is, it also compiles down much smaller, ok not the 40k you can get with freebasic, 271k which is still a quarter of the usual exe size for cobra.

So, the question is... If I develop this further, what features would you, as demo coders, want in there ? (remembering that I would want to try and keep this as a low level library).

Things on the list so far (note excessive use of the word "simple")
1. Simple sound engine (probably just mod's, maybe wave files)
2. Simple drawing commands (including writing text to a buffer, as that can be a pain)
3. Simple image loader (probably restricted to bmp, or at a push include png)

I've attached the above code as an exe for you to have a look at.

Title: Re: Cobra 'mini'
Post by: Shockwave on March 13, 2007
That runs at around 540fps here, that's more than acceptable :D

As for what features, I don't just want to spout off a load of things here, I need to think about this, and post back later or tomorrow, but two things that spring to mind immediately are the ability to draw windows fonts and music playability with some way of monitoring the sound levels in the sound channels...

I could see it getting some fans :)

Btw, is this packed already? Upx says it is :)
Title: Re: Cobra 'mini'
Post by: GrahamK on March 13, 2007
Cobra includes it's own packer as part of it's build.

Working on getting hold of a 'mod' module, not sure on monitoring the sound levels (but I know what you are getting at ;) ) Fonts drawing "shouldn't" be an issue.
But have a good think, I'm not rushing at this, its been more of a diversion at the moment. But I'm willing to put some effort in if it's something people like.
Title: Re: Cobra 'mini'
Post by: Clyde on March 13, 2007
Thats way cool, grand job Graham dude.
btw, 413 Fps.
Title: Re: Cobra 'mini'
Post by: GrahamK on March 14, 2007
Ok, I've included support for XM playback, thanks to the most excellent uFMOD :D
Also added limited text output (no control as yet, just basic text output to screen).

Updated download demo up on the first post....
Title: Re: Cobra 'mini'
Post by: Clyde on March 14, 2007
Very cool addition dude, nice going :)
Title: Re: Cobra 'mini'
Post by: Shockwave on March 14, 2007
That's fantastic!

Nice that the sound and everything is resourced into the exe too :D

Tell me, what are the numbers next to the fps?

There are two in brackets and then a timer..

What are the two numbers in brackets? :)

Thanks!
Title: Re: Cobra 'mini'
Post by: GrahamK on March 14, 2007
According to the uFmod docs..

The uFMOD_GetStats function returns the current RMS volume coefficients
 in L and R channels.
 --------------
 Return Values:
    low-order word : RMS volume in R channel
    hi-order  word : RMS volume in L channel


Not entirely sure what that means myself, going to have a play around tonight. Kinda looks like its some data that could be used for a vu-meter (or summat!)

Title: Re: Cobra 'mini'
Post by: Shockwave on March 14, 2007
RMS is sound level then, so ufmod is spitting out a longword with the sound values :D

Sweet. This will make sync very simple with cobra. Nice one Graham.
Title: Re: Cobra 'mini'
Post by: Clyde on March 14, 2007
Looks to me like stereo channels, left and right speakers.
Title: Re: Cobra 'mini'
Post by: Shockwave on March 14, 2007
Yep, that's what Graham said ;)

L + R Channels = Left and Right :)

You'd like this Clyde, you love doing your synced demos, this would be a nice thing for you.
Title: Re: Cobra 'mini'
Post by: Steve Elliott on March 14, 2007
Whoah!  Now that's faster!  :D

Cobra runs most programs very quickly indeed - Shockwave found something it didn't do quite so well.  Good idea to try and resolve it Graham - hope the talented guys here can come up with some cool demos and show off what Cobra is capable of - you have to include PNG support though.
Title: Re: Cobra 'mini'
Post by: GrahamK on March 14, 2007
It should have jpg, png and bmp (fingers crossed), this will also be coming to the sunday cobra patch  (in fact, it IS the patch on sunday ;) )

here is another example, using the L-R values...

Title: Re: Cobra 'mini'
Post by: Shockwave on March 14, 2007
That's almost a cracktro :D

I just noticed that the music isn't resourced inside the exe.. Is it a pain in the arse to one file it?
Title: Re: Cobra 'mini'
Post by: GrahamK on March 14, 2007
at the moment yeah :(
Saying that, I've been tinkering (again) and I may have an approach soon. Rather than have something 'just' for cobra mini, I want to try and get something more general, as it would be bloody useful for the rest of cobra too :D

I think for demo's it would be a real plus (I guess that is what you are getting at!) so I'll certianly be looking into it.
Title: Re: Cobra 'mini'
Post by: rdc on March 15, 2007
You might want to look at the bin2bas program. It converts a file to a binary representation. You should be able to do something like that in Cobra.

Title: Re: Cobra 'mini'
Post by: Shockwave on March 15, 2007
I use a version of bin2bas at the moment indeed. It was coded by rbraz and converts a resource file into and array of unsigned bytes. I get along with it just fine, it confuses some people though.
Title: Re: Cobra 'mini'
Post by: GrahamK on March 15, 2007
it's probably going to end up as

Code: [Select]
BINARY myfile "filename.something"

with a couple of supporting commands
Code: [Select]
        addr = binaryptr(myfile)
        ln = binarylength(myfile)

I'm also thinking about adding "dataptr" to allow access to raw data statements via assembler.

Title: Re: Cobra 'mini'
Post by: Steve Elliott on March 15, 2007
I love the sound of this low level stuff.  Perhaps Cobra could be 'promoted' to the main set of languages now?  ;)
Title: Re: Cobra 'mini'
Post by: GrahamK on March 15, 2007
I think a few more users are needed first ;)
Title: Re: Cobra 'mini'
Post by: Steve Elliott on March 15, 2007
LOL - maybe.  But not many developers ask a demo coder what they want - deserves a push in my opinion.  Shockwave's decision ofcourse.
Title: Re: Cobra 'mini'
Post by: GrahamK on March 15, 2007
Ok, last bit of pimpage.... ;)

Here is the latest little demo of the cobramini module..
Added in line drawing, and quad / tri commands from pure2d, allowing some demo's being very easily, while still allowing people to get into the low level stuff.

Now, back to finishing my 20second Intro :D
If I can crack the music, I'll upload it tonight.
Title: Re: Cobra 'mini'
Post by: Clyde on March 15, 2007
Nice one GK :)
Title: Re: Cobra 'mini'
Post by: mike_g on March 15, 2007
I like :)
Title: Re: Cobra 'mini'
Post by: Shockwave on March 15, 2007
Codeuerrrr Colourzz! I love that :D I've seen such techniques in 256 byte intros :D
As far as promoting a language here, the main thing that has to govern it is popularity :D If there is enough Cobra interest, we could host the section.. I have a registered copy of Cobra myself so adminning it would not be a problem :)

Graham, I'm looking forward to your entry!
Title: Re: Cobra 'mini'
Post by: GrahamK on March 15, 2007
On it's way ;)
Title: Re: Cobra 'mini'
Post by: Shockwave on March 16, 2007
Hehe, looking good :)
Title: Re: Cobra 'mini'
Post by: GrahamK on March 18, 2007
I've just released this module as part of Cobra's update cycle... So if you've bought a copy of Cobra you will be able to have a mess about with it yourself..

Feel free to suggest updates / new commands. I'm all ears ..
Title: Re: Cobra 'mini'
Post by: Shockwave on March 19, 2007
I need to have a play with this on the weekend :) Hope I'm not working.