Page 7 of 8 FirstFirst ... 5678 LastLast
Results 61 to 70 of 79

Thread: Further Developments in Asmosphere I.

  1. #61

    Re: Further Developments in Asmosphere


    Just posted the updated help manual containing the beginnings of Omerlin's code spells. The experiment went well today and I hope this will be useful to all, enabling code to be generated without trying to work it out from scratch. . I certainly envisage using it myself to generate error-free code skeletons.

    http://community.thinbasic.com/index.php?topic=1637

  2. #62
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: Further Developments in Asmosphere

    Hi Charles,

    thanks for OMerlin,
    really useful - two clicks and code mini-template is ready to copy and paste


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #63
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Further Developments in Asmosphere

    This is a first for me, seeing something interactive (beyond just clicking on a hyperlink) in a help file.

    Charles you had mentioned it would be very easy, well if one knew what they were doing I suppose, to make classes with the new tools.

    Can you write an example, when you have some time?

    If it could show how a base class would be implemented and then inherited in a new class, which would add its own members that would be super.
    I know it is asking a lot, but thought I would ask anyways

    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #64

    Re: Further Developments in Asmosphere


    Hi Kent,

    Inheriting properties is exremely simple - an example of double inheritance and then adding a couple of other members:

    type color 1 blue 1 green 1 red 1 alpha
    type xyzvec 4 x 4 y 4 z
    type ColorPoint Color, xyzec, 4 id, 12 name


    then mapping out the vars:

    var ColorPoint c1 c2 c3 ca(100,2) etc


    on the other hand

    C++ style classes with methods and static members is a little more complicated and I have one further ingredient to add for building virtual function tables more easily called labeladdress

    Do you have one or two examples in mind, Kent. Perhaps something you were doing in C++ or TankWars so we can make it more concrete.


  5. #65
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Further Developments in Asmosphere

    I know this is going to be sweet once I understand it all.

    About an idea for a more concrete example. Can I put up something written in C++ or would you like me to write pseudo code Charles?
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  6. #66
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Further Developments in Asmosphere

    I am excited by the possibilities so I thought I would go ahead and put something in c++ that I had:

    Point.h :
    #ifndef POINT_H
    #define POINT_H
    #include <iostream>
    using namespace std;

    class Point
    {
    public:
    //constructor, same name as the class
    Point(float f_x = 1.2, float f_y = 1.5, float f_z = 1.7); //this now eliminates the need for the above method
    //destructor
    ~Point(); //never any arguements for the destructor
    void getXYZ(float &X, float &Y, float &z);
    float getX();
    float getY();
    float getZ();
    void setXYZ(float X, float Y, float Z);
    void setX(float X);
    void setY(float Y);
    void setZ(float Y);
    Point operator =(Point &p);
    //float x, y, z;
    private:
    float x, y, z;

    protected:
    //float x, y, z;
    };

    ostream &operator <<(ostream &stream, Point &P);
    istream &operator >>(istream &stream, Point &P);

    #endif
    Vector.h :
    #ifndef VECTOR_H
    #define VECTOR_H

    #include "Point.h"

    class Vector : public Point
    {
    public:
    Vector(float X=0,float Y=0, float Z=0);
    Vector operator +(Vector &p);
    Vector operator -(Vector &p);
    Vector operator *(float scale);
    };

    #endif
    Point.cpp :
    #include <iostream>
    using namespace std;
    #include "Point.h"

    Point::Point(float f_x, float f_y, float f_z)
    {
    x = f_x;//if no parameters the default values are used from the definition
    y = f_y;
    z = f_z;
    cout << "we are in the constructor with arguements" << int(this) << endl;
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
    cout << "z = " << z << endl;
    }

    Point::~Point()
    {
    cout << "we are in the destructor" << (int)this << endl;
    }
    Point Point:perator =(Point &p)
    {
    setXYZ(p.getX(),p.getY(),p.getZ());
    return *this;
    }
    void Point::getXYZ(float &X, float &Y, float &Z)
    {
    X = getX();
    Y = getY();
    Z = getZ();
    }
    float Point::getX()
    {
    return x;
    }
    float Point::getY()
    {
    return y;
    }
    float Point::getZ()
    {
    return z;
    }
    void Point::setXYZ(float X, float Y, float Z)
    {
    setX(X);
    setY(Y);
    setZ(Z);
    }
    void Point::setX(float X)
    {
    x = X;
    }
    void Point::setY(float Y)
    {
    y = Y;
    }
    void Point::setZ(float Z)
    {
    z = Z;
    }


    ostream &operator <<(ostream &stream, Point &P)
    {
    stream << P.getX() << " " << P.getY() << " " << P.getZ();
    return stream;
    }
    istream &operator >>(istream &stream, Point &P)
    {
    float x, y, z;
    stream >> x >> y >> z;
    P.setXYZ(x, y, z);
    return stream;
    }
    Vector.cpp :
    #include "Vector.h"
    Vector::Vector(float X, float Y, float Z) : Point(X,Y,Z)
    {
    }

    Vector Vector:perator +(Vector &p)
    {
    Vector vout;
    vout.setX(getX() + p.getX());
    vout.setY(getY() + p.getY());
    vout.setZ(getZ() + p.getZ());
    return vout;
    }

    Vector Vector:perator -(Vector &p)
    {
    Vector vout;
    vout.setX(getX() - p.getX());
    vout.setY(getY() - p.getY());
    vout.setZ(getZ() - p.getZ());
    return vout;
    }

    Vector Vector:perator *(float scale)
    {
    Vector vout;
    vout.setX(getX() * scale);
    vout.setY(getY() * scale);
    vout.setZ(getZ() * scale);
    return vout;
    }

    // Vector operator *(float scale, Vector v) // this worked also
    Vector operator *(const float &scale, Vector &v)
    {
    Vector vout;
    vout.setX(v.getX() * scale);
    vout.setY(v.getY() * scale);
    vout.setZ(v.getZ() * scale);
    return vout;
    }
    This should cover a lot of what would be needed. It covers some of the great things about classes in c++. Let me know if this is Ok?
    And THANKS!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  7. #67
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Further Developments in Asmosphere

    In thinking about it, that c++ one is really hard because of the overloading of operators.

    Here is a simpler no overloading of operators, perhaps operator overloading will be possible with Asmosphere, I really don't know. But just in case here is pseudo code situation.

    type t_xyz
    x as double
    y as double
    z as double
    end type

    type t_rgb
    r as long
    g as long
    b as long
    end type

    class vector
    public
    getX(), returns double
    getY(), returns double
    getZ(), returns double
    setX(x as double)
    setY(y as double)
    setZ(z as double)
    getXYZ(), returns t_xyz
    setXYZ(vec as t_xyz)
    private
    vec as t_xyz
    end class

    class Color
    public
    getR(), returns long
    getG(), returns long
    getB(), returns long
    setR(x as long)
    setG(y as long)
    setB(z as long)
    getRGB(), returns t_rgb
    setRGB(col as t_rgb)
    private
    col as t_rgb
    end class

    class actor
    public
    getName(), returns string
    setName(name as string)
    private
    name as string
    pos as Vector
    col as Color
    end class

    class enemy derived from class actor
    public
    setWeapon(name as string)
    getWeapon(), returns string
    setDamage(damage as long)
    getDamage(), returns long
    setShield(shield as long)
    getShield(), returns long
    private
    weapon as string
    damage as long
    shield as long
    end class

    class player derived from class enemy
    setMagic(magic as long)
    getMagic(), returns long
    private
    magic as long
    end class

    Hope this is easier, and probably there are even better ways to do it, just off of the top of my head all I can come up with.

    Of course player would inherit all of the properties and methods from previous classes that it is derived from.
    So there would be:
    dim p as new player
    p.setName("Hero Henry")
    p.pos.setXYZ(100,0,200)
    p.col.setRGB(100,100,100)
    p.setWeapon("Axe")
    p.setMagic(50)
    p.setDamage(10)
    p.setShield(100)

    Sorry for the mess of examples Charles, just wanted to make sure you had something before tomorrow as night time here now and early morning on your side of the Atlantic.


    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  8. #68

    Re: Further Developments in Asmosphere

    In deep thought all day

    Classes and their virtual tables are dynamically created - some very interesting constructs without adding extra features to the Oxygen kernel so far.

    C++ OOP hides considerable complexity.


  9. #69

    Re: Further Developments in Asmosphere

    This is a sketch to show what is entailed in setting up OOP with methods, hidden members and inheritance. There is a sample of three methods - enough to work on the principle anyway. It can be packed down quite a bit but shows how much work the CPU has to do in setting up the tables and other structures. But once the objects are up and running then the OOP overhead is not too bad compared with normal function calls.

    Here, virtual tables are embedded in the code string but they could also be patched into thinBasic variables allowing other modules to access the methods.



    mov edi,ecx ; code string base

    type vecvta 4 ptr 4 len


    indexers "esi" offset 0 ascending
    esi=getmemory 1000

    type t_xyz 8 x 8 y 8 z ; doubles
    type t_rgb 4 r 4 g 4 b ; longs

    type vector 4 ? t_xyz ? t_rgb ? ; public declaration

    var vecvta vector_info parent_info

    ( ; capsule hiding the inner workings of vector

    type vector
    (
    ; private definition
    4 vt_methods
    t_xyz vec
    t_rgb col
    )


    o2 !4 e8 00 00 00 00 e9 xl 90 90 90 ' where-am-I left on stack
    ;-------------------------------------
    ; 00 04 08 12
    ;-------------------------------------
    o2 ga getX ga getY ga getZ ' virtual table
    ;
    ; instantiate class methods
    .getX
    indexers "esi" offset 0 ascending
    var vector this
    push ebp
    mov ebp,esp
    push esi
    mov esi [ebp+8] ; this pointer
    fld this.vec.x
    pop esi
    mov esp,ebp
    pop ebp
    ret 4
    .getY
    ;...
    ret 4
    .getZ
    ; ...
    ret 4
    ; store vt info
    ) ; end of vector encapsulation
    ;
    pop eax ; store whereami
    add eax,7
    mov vector_info.ptr,eax
    mov vector_info.len,12 ; store length of entries
    mov edx,parent_info.len ; length of parant table
    mov eax,vector_info.ptr
    add eax,vector_info.len
    copyn eax.ptr,parent_info.ptr,parent_info.len ' copy parental vt in edx
    mov eax,vector_info.len
    add eax,parent_info.len
    mov vector_info.len,eax
    ; add offsets to table to make absolute addresses
    mov ecx,12
    shr ecx,2
    mov edx,vector_info.ptr
    mov eax,edx
    (
    dec ecx
    jl exit
    add eax,4
    add [eax],edi
    repeat
    )
    ;
    def create_vector
    (
    ; calling methods
    def %1_getX
    (
    lea eax,%1
    push eax
    mov eax %1
    proc [eax+0]
    )
    def %1_getY
    (
    lea eax,%1
    push eax
    mov eax %1
    proc [eax+4]
    )
    def %1_getZ
    (
    lea eax,%1
    push eax
    mov eax %1
    proc [eax+8]
    )
    ; now setup the variable with its vt address
    var vector %1
    mov eax,vector_info.ptr
    mov %1,eax
    ) ; end of def


    Create_vector p1

    var 4 x y z

    ; try the methods
    x=p1_getX
    y=p1_getY
    z=p1_getZ

    freememory esi
    ret



  10. #70
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Further Developments in Asmosphere

    Charles, the first scan through your post my eyes came out of their sockets But I have been going through it and after many passes it is making more sense, could I write this from scratch, no, but I am able to follow along and kind of get how it all goes together.

    One minor question:


    Create_vector p1

    var 4 x y z

    ; try the methods
    x=p1_getX
    y=p1_getY
    z=p1_getZ

    freememory esi
    ret

    Shouldn't var 4 xyz be var 8 xyz at that point in the code?

    That is neat to see a behind the scenes of what goes on behind the scenes when working with oop, that is for sure!! Thanks.

    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Page 7 of 8 FirstFirst ... 5678 LastLast

Similar Threads

  1. Further Developments in Asmosphere III
    By Charles Pegge in forum Legacy
    Replies: 30
    Last Post: 22-09-2008, 22:55

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •