Oxygen Basic

Programming => Example Code => Topic started by: Peter on March 02, 2013, 04:05:57 AM

Title: Programming Fun
Post by: Peter on March 02, 2013, 04:05:57 AM
Deleted
Title: Re: Programming Fun
Post by: JRS on March 02, 2013, 09:15:49 AM
Peter,

This is your second warning. If you do not provide source with your SDL wrapper I will ask Charles to remove all your posts that violate the GNU license and file a complaint. This is one thing I take very seriously as it's the foundation of open source and it's success.

John
Title: Re: Programming Fun
Post by: Charles Pegge on March 02, 2013, 09:35:06 AM
It's ok John, Peter's code does not contain SDL, though I miss seeing Peter's lib source code. I love its elegant simplicity and there is so much one can learn by sharing expertise.
Title: Re: Programming Fun
Post by: JRS on March 02, 2013, 10:07:13 AM
That will save you court costs. Using open source software in a closed project is just like stealing. It doesn't matter if you're trying to make a buck off it or not. If developing graphic libraries is your passion then purchase a commercial package that allows you royalty free use or purchase a commercial license to SDL.

I don't think it's fair to jeopardize the OxygenBasic open source project or my contributions of facilitating the project by hosting illegal software. There are plenty of file sharing networks to distribute bootleg software so maybe that is a better venue for your efforts.  
Title: Re: Programming Fun
Post by: Aurel on March 02, 2013, 11:54:58 AM
Come one John ,why such a reaction ?
Peter provide many many times whole set of functions for GDI graphics and some other stuff.
From your point of view if something is in dll is contra open-source .
I think that this is simple over-reaction from you .
Title: Re: Programming Fun
Post by: JRS on March 02, 2013, 12:36:31 PM
I have had my site shutdown by a user of a forum I had many years ago when he claimed (and filed) copyright violation when I wouldn't remove his posts.

Where would the open source community be today if everyone just looked the other way when software licensees are being violated?

The real question is why has Peter taken the stand he has and refusing to release source knowing before writing a single line of code that his work is based on open source efforts of people that came before him. Do we need to gather donations to buy Peter a license to a graphics package so he can keep Simple Windows to himself?

I manage a open source project LGPL that allows free use (open source or commercial) and promote the project in that way. Projects come with a license to use and we must respect the contributors wishes.

Quote
Licensing the Simple DirectMedia Layer library

    SDL 1.2 and older are available under the GNU LGPL license .

    SDL 2.0 and newer are available under the zlib license .


 This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

It seems you are free to use SDL in any way you wish.

Please ignore my license warnings for the SDL package but I take back nothing when it comes to violating open source licensing.

Title: Re: Programming Fun
Post by: Charles Pegge on March 02, 2013, 02:59:45 PM

Ice? Nooo! On the contrary, I drink Gunpowder tea  ;D

I they knew what it does to me, they would ban it!


(http://images.ethicalsuperstore.com/images/68949%20-%20QI%20Gunpowder%20Pearl%20Loose%20Tea.jpg)
Title: Re: Programming Fun
Post by: JRS on March 02, 2013, 03:14:50 PM
I finally understand what the T_ means in C programming.  :D
Title: Re: Programming Fun
Post by: JRS on March 02, 2013, 05:37:58 PM
Peter,

Do you have a test program for this latest release?

John
Title: Re: Programming Fun
Post by: JRS on March 02, 2013, 06:02:10 PM
It wasn't included within the zip is the reason I asked.

The SDL library is coming along nicely based and what you have shared.

Thanks for updating your post with the test code.

Who is Peter Pan?
Quote
Peter is mainly an exaggerated stereotype of a boastful and careless boy. He is quick to point out how great he is, even when such claims are questionable. Peter has a nonchalant, devil-may-care attitude, and is fearlessly cocky when it comes to putting himself in danger. Peter can also be quite selfish and arrogant. Peter either symbolizes or personifies the selfishness of childhood through constant forgetfulness and self-centered behavior. Peter appears very judgmental and pompous, nonetheless, he has a strong sense of justice and is always quick to assist those in danger.

To live will be an awfully big adventure.

X
Title: Re: Programming Fun
Post by: JRS on March 03, 2013, 11:13:51 PM
Being able to fly and never grow old are also positive attributes.  ;)
Title: Re: Programming Fun
Post by: Charles Pegge on March 04, 2013, 10:02:15 PM
Hi Peter,

2 ways: (our arrays are not implicitly pointered like c)

sys *keystate
&keystate = SDL_GetKeyState(null)
if keystate[SDLK_TAB] then print "TAB was pressed"



sys keystate at (SDL_GetKeyState(null))
if keystate[SDLK_TAB] then print "TAB was pressed"



Title: Re: Programming Fun
Post by: Charles Pegge on March 04, 2013, 10:46:01 PM
Enumerations:

You can use enumeration literals by providing an enumeration tag word then using dotted keywords


typedef enum tag_alphabet
{
 a=1,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
} alphabet

print tag_alphabet.d 'result: 4

I will try to improve this situation by making it work with alpahabet

Charles
Title: Re: Programming Fun
Post by: JRS on March 05, 2013, 12:43:19 AM
Here is a Linux SDL example in Vala

(http://files.allbasic.info/Vala/vala_sdl_demo.png)

Code: [Select]
using SDL;
using SDLGraphics;

public class SDLSample : Object {

    private const int SCREEN_WIDTH = 640;
    private const int SCREEN_HEIGHT = 480;
    private const int SCREEN_BPP = 32;
    private const int DELAY = 10;

    private unowned SDL.Screen screen;
    private GLib.Rand rand;
    private bool done;

    public SDLSample () {
        this.rand = new GLib.Rand ();
    }

    public void run () {
        init_video ();

        while (!done) {
            draw ();
            process_events ();
            SDL.Timer.delay (DELAY);
        }
    }

    private void init_video () {
        uint32 video_flags = SurfaceFlag.DOUBLEBUF
                           | SurfaceFlag.HWACCEL
                           | SurfaceFlag.HWSURFACE;

        this.screen = Screen.set_video_mode (SCREEN_WIDTH, SCREEN_HEIGHT,
                                             SCREEN_BPP, video_flags);
        if (this.screen == null) {
            stderr.printf ("Could not set video mode.\n");
        }

        SDL.WindowManager.set_caption ("Vala Linux SDL Demo", "");
    }

    private void draw () {
        int16 x = (int16) rand.int_range (0, screen.w);
        int16 y = (int16) rand.int_range (0, screen.h);
        int16 radius = (int16) rand.int_range (0, 100);
        uint32 color = rand.next_int ();

        Circle.fill_color (this.screen, x, y, radius, color);
        Circle.outline_color_aa (this.screen, x, y, radius, color);

        this.screen.flip ();
    }

    private void process_events () {
        Event event;
        while (Event.poll (out event) == 1) {
            switch (event.type) {
            case EventType.QUIT:
                this.done = true;
                break;
            case EventType.KEYDOWN:
                this.on_keyboard_event (event.key);
                break;
            }
        }
    }

    private void on_keyboard_event (KeyboardEvent event) {
        if (is_alt_enter (event.keysym)) {
            WindowManager.toggle_fullscreen (screen);
        }
    }

    private static bool is_alt_enter (Key key) {
        return ((key.mod & KeyModifier.LALT)!=0)
            && (key.sym == KeySymbol.RETURN
                    || key.sym == KeySymbol.KP_ENTER);
    }

    public static int main (string[] args) {
        SDL.init (InitFlag.VIDEO);

        var sample = new SDLSample ();
        sample.run ();

        SDL.quit ();

        return 0;
    }
}
Title: Re: Programming Fun
Post by: Charles Pegge on March 05, 2013, 02:20:31 AM
Peter, John,

I'm going to change Oxygen's enumeration system to conform to C. That is: all enumeration members behave like simple equates. This will avoid a lot of trouble, and I can throw out large hunks of code :)

Charles
Title: Re: Programming Fun
Post by: Aurel on March 05, 2013, 03:34:03 AM
Charles..
I don't use ENUM very much but i found that old way is simple to use
so do you will make this optional ?
Title: Re: Programming Fun
Post by: Charles Pegge on March 05, 2013, 04:13:50 AM
Hi Aurel,

you can define enumerations in the same way as before. The only difference is that all the enumeration members become equates, and you wont need dotted names to access them directly.

SDL example:

Code: [Select]
typedef enum {
  SDL_GL_RED_SIZE,
  SDL_GL_GREEN_SIZE,
  SDL_GL_BLUE_SIZE,
  SDL_GL_ALPHA_SIZE,
  SDL_GL_BUFFER_SIZE,
  SDL_GL_DOUBLEBUFFER,
  SDL_GL_DEPTH_SIZE,
  SDL_GL_STENCIL_SIZE,
  SDL_GL_ACCUM_RED_SIZE,
  SDL_GL_ACCUM_GREEN_SIZE,
  SDL_GL_ACCUM_BLUE_SIZE,
  SDL_GL_ACCUM_ALPHA_SIZE,
  SDL_GL_STEREO,
  SDL_GL_MULTISAMPLEBUFFERS,
  SDL_GL_MULTISAMPLESAMPLES,
  SDL_GL_ACCELERATED_VISUAL,
  SDL_GL_SWAP_CONTROL
} SDL_GLattr

print SDL_GL_BLUE_SIZE 'result: 2



Charles

Title: Re: Programming Fun
Post by: Peter on March 05, 2013, 05:23:50 AM
But  what is when the numeration isn't  1-2-3-4,  rather  0-0-1-8-9-20-21 !
Title: Re: Programming Fun
Post by: Peter on March 05, 2013, 05:41:26 AM
Hi John,

Is this vala source code from another star ?
I didn't know that Aliens have pseudo C.

This is a bit better readable.
Code: [Select]
include "sdl.inc"

LoadWinIcon "img/hase.bmp"
Window 640,480,1
SetCaption "Random Circles"

Type CIRCLE
  sys x
  sys y
  sys c
  sys a
End Type

CIRCLE cir[500]
sys i

for i=1 to 500
    cir[i].x = Rnd(0,640)
    cir[i].y = Rnd(0,480)
    cir[i].a = Rnd(10,100)
    cir[i].c = RGBA(Rnd(64,255),Rnd(64,255),Rnd(64,255),Rnd(64,255))
next

while Key(27)=0
  Cls RGB(255,255,255)
  for i=1 to 500
      filledCircleColor @screen,cir[i].x,cir[i].y,cir[i].a,cir[i].c
  next  
  Sync()
wend

Quit()
Title: Re: Programming Fun
Post by: Charles Pegge on March 05, 2013, 06:05:06 AM
Aurel,
Specifying enumeration values:

Code: [Select]
typedef enum {
  SDLK_UNKNOWN     = 0,
  SDLK_FIRST     = 0,
  SDLK_BACKSPACE    = 8,
  SDLK_TAB     = 9,
  SDLK_CLEAR     = 12,
  SDLK_RETURN     = 13,
  SDLK_PAUSE     = 19,
  SDLK_ESCAPE     = 27,
  SDLK_SPACE     = 32,
  SDLK_EXCLAIM     = 33,
...
Title: Re: Programming Fun
Post by: Charles Pegge on March 05, 2013, 06:10:44 AM

The new simplified enumeration system compatible with C enums:

Also fixes nasty little bug affecting inner functions

X
Title: Re: Programming Fun
Post by: Aurel on March 05, 2013, 06:37:21 AM
Thanks Charles...
I don't ask about random or not continued enumeration then Peter ask
however ,so if we need not-continued way we must use enum-assign way which is ok for me.. :)

Hmm...Vala looks like ObjectOrientedBisexual child of C... ;D
And Genie is a little bit better OOB child of Vala :D
Title: Re: Programming Fun
Post by: JRS on March 05, 2013, 08:20:45 AM
Quote
Hmm...Vala looks like ObjectOrientedBisexual child of C.

The Vala/Genie language is based on the GObject framework.

Check out the GObject Reference Manual (https://developer.gnome.org/gobject/unstable/).

@Peter: Check out the Vala SDL API definition file I attached. I find it helpful  as a reference to the SDL library in general. SDL.h only, see other {SDL}.vapi files for other aspects of the library.

Quote
C APIs are defined by a set of functions and global variables which are usually exported from a binary. C functions have an arbitrary number of arguments and one return value. Each function is thus uniquely identified by the function name and the set of C types which describe the function arguments and return value. The global variables exported by the API are similarly identified by their name and their type.

A C API is thus merely defined by a set of names to which a set of types are associated. If you know the function calling convention and the mapping of the C types to the machine types used by the platform you are on, you can resolve the name of each function to find where the code associated to this function is located in memory, and then construct a valid argument list for the function. Finally, all you have to do is trigger a call to the target C function with the argument list.

The concept DLLC is based on.

ScriptBasic is in many ways an early adoption of the GObject concept. (released over 10 years ago and why it still runs today using one source tree for all platforms)

X