Ejemplo n.º 1
0
short _FastMap( long _WCI86FAR *colours, short num )
//=============================================

{
    short               i;
    long                colour;
    struct rgb          *rgb;

    i = _RoundUp( sizeof( struct rgb ) * num );
    if( _stackavail() - i <= 0x100 ) {
        return( FALSE );
    } else {
        rgb = __alloca( i );
    }
    for( i = 0; i < num; ++i ) {
        colour = *colours;
        rgb[ i ].blue = ( (unsigned long)colour & 0x00ff0000 ) >> 16;
        rgb[ i ].green = (unsigned short)( colour & 0x0000ff00 ) >> 8;
        rgb[ i ].red = colour & 0x000000ff;
        ++colours;
    }
    VideoIntDAC( _BIOS_SET_PALETTE + 0x12, 0, num, rgb );
    return( TRUE );
}
Ejemplo n.º 2
0
void _L1GetPic( short x1, short y1, short x2, short y2,
/*===============================*/ struct picture _WCI86HUGE *image )

/*  Copy that portion of the screen inside the viewport to the buffer
    pointed by 'image'. */

{
    short               dx;             /* width of rectangle in pixels     */
    short               dy;             /* height of rectangle in pixels    */
    short               t;
#if defined( _DEFAULT_WINDOWS )
    WPI_PRES            dc;
    short               srcy;
#else
    short               line_len;       /* length of each line in bytes     */
  #if !defined( __386__ )
    unsigned short      new_off;
  #endif
    char                *tmp;
    gr_device _FARD     *dev_ptr;       /* pointer to _CurrState->deviceptr */
    char _WCI86HUGE     *pic;           /* buffer to store image            */
    copy_fn             *copy;          /* pointer to copy routine          */
    setup_fn            *setup;
#endif

    if( x1 > x2 ) {         // ensure x1 < x2
        t = x1;
        x1 = x2;
        x2 = t;
    }
    if( y1 > y2 ) {         // ensure y1 < y2
        t = y1;
        y1 = y2;
        y2 = t;
    }
    if( _L0BlockClip( &x1, &y1, &x2, &y2 ) != 0 ) {     /* clip image to    */
        image->picwidth = 0;                            /* active viewport  */
        image->picheight = 0;
        _ErrorStatus = _GRNOOUTPUT;
        return;
    }
    dx = x2 - x1 + 1;                               /* row width in pixels  */
    dy = y2 - y1 + 1;                               /* height in pixel rows */
    image->picwidth = dx;                   /* save width in image picture  */
    image->picheight = dy;                  /* save height in image picture */
#if defined( _DEFAULT_WINDOWS )
    dc = _Mem_dc;

// Create a memory DC to put the image in
    image->buffer = _wpi_createcompatiblepres( dc, _GetInst(), &( image->pdc ) );
    image->bmp = _wpi_createcompatiblebitmap( dc, dx, dy );
    if( ( image->buffer == NULL ) || ( image->bmp == NULL ) ) {
         _ErrorStatus = _GRINSUFFICIENTMEMORY;
         return;
    }
    _wpi_selectbitmap( image->buffer, image->bmp );

// Transfer the image to a memory DC
  #if defined( __OS2__ )
    srcy = _wpi_cvth_y( y2, _GetPresHeight() );
  #else
    srcy = y1;
  #endif
    _wpi_bitblt( image->buffer, 0, 0, dx, dy, dc, x1, srcy, SRCCOPY );

#else
    image->bpp = _CurrState->vc.bitsperpixel;   /* save bpp - never used ?  */
    line_len = _RowLen( dx );                   /* width of row in bytes    */

    _StartDevice();

    dev_ptr = _CurrState->deviceptr;
    copy = dev_ptr->readrow;
    pic = &image->buffer;
    tmp = NULL;
    setup = dev_ptr->setup;
    for( ; y1 <= y2; ++y1 ) {               /* copy screen image to buffer  */
        ( *setup )( x1, y1, 0 );
  #if !defined( __386__ )
        // check whether the entire row will fit in the buffer
        new_off = FP_OFF( pic ) + line_len - 1;
        if( new_off < FP_OFF( pic ) ) {
            if( tmp == NULL ) {     // may have been already allocated
                if( _stackavail() - line_len > 0x100 ) {
                    tmp = __alloca( _RoundUp( line_len ) );
                }
            }
            if( tmp != NULL ) {
                ( *copy )( tmp, _Screen.mem, dx, _Screen.bit_pos, 0 );
                for( t = 0; t < line_len; ++t ) {
                    *pic = tmp[ t ];
                    ++pic;      // the PIA function will handle this properly
                }
            } else {
                _ErrorStatus = _GRINSUFFICIENTMEMORY;
                pic += line_len;
            }
        } else {
  #endif
            ( *copy )( pic, _Screen.mem, dx, _Screen.bit_pos, 0 );
            pic += line_len;
  #if !defined( __386__ )
        }
  #endif
    }

    _ResetDevice();
#endif
}
Ejemplo n.º 3
0
_WCRTLINK short _WCI86FAR _CGRAPH _polygon_wxy( short fill, short numpts,
/*============================*/ struct _wxycoord _WCI86FAR *points )

/* This routine draws or fills a polygon specified by the array
   points[], in window coordinates. */

{
    short                   i;
    short                   needed_bytes;
    short                   x1, y1, x2, y2;
    short                   success;
    struct xycoord _WCI86FAR *   stack;


    if( numpts <= 2 ) {
        _ErrorStatus = _GRINVALIDPARAMETER;
        return( 0 );
    }
    success = 0;                            /* assume not successful    */
    if( _GrProlog() ) {
        if( fill == _GFILLINTERIOR ) {
            needed_bytes = _RoundUp( numpts * sizeof( struct xycoord ) );
#if defined( _DEFAULT_WINDOWS )
            stack = _MyAlloc( needed_bytes );
#else
            if( _stackavail() - needed_bytes > 0x100 ) {
                stack = __alloca( needed_bytes );
#endif
                for( i = 0; i < numpts; i++ ) {
                    stack[i].xcoord = _WtoPhysX( points[i].wx );
                    stack[i].ycoord = _WtoPhysY( points[i].wy );
                }
                success = _L1FillArea( numpts, stack );
#if defined( _DEFAULT_WINDOWS )
            _MyFree( stack );
            _GrEpilog();
#else
            } else {
                _ErrorStatus = _GRINSUFFICIENTMEMORY;
            }
#endif
        } else {
            x1 = _WtoPhysX( points[numpts-1].wx );
            y1 = _WtoPhysY( points[numpts-1].wy );
            for( i = 0; i < numpts; i++ ) {
                x2 = _WtoPhysX( points[i].wx );
                y2 = _WtoPhysY( points[i].wy );
                if( y1 < y2 ) {
                    _L1Line( x2, y2, x1, y1 );
                } else {
                    _L1Line( x1, y1, x2, y2 );
                }
                x1 = x2;
                y1 = y2;
            }
            success = 1;
        }
        _GrEpilog();
    }
    return( success );
}
Ejemplo n.º 4
0
void Organism::evolve()
{   // user-mediated evolution procedure
    char key = 0;
    drawTree(leftChild != NULL && !leftChild->terminal,
             midChild != NULL && !midChild->terminal,
             rightChild != NULL && !rightChild->terminal);
    // grow the parent and two children until a key is pressed
    // try a new child while this is happening
    Organism *newChild = spawnChild();
    assert(newChild != NULL);
    do
    {   // repeat this loop until the space key is pressed
        plotAt(vc.numxpixels/2, vc.numypixels*3/4);
        nextGen();

        if (leftChild == NULL)
            leftChild = spawnChild();    // make new left child
        else
            leftChild->plotAt(vc.numxpixels/6, vc.numypixels/3);
        assert(leftChild != NULL);
        leftChild->nextGen();

        if (midChild == NULL)
            midChild = spawnChild();    // make new mid child
        else
            midChild->plotAt(vc.numxpixels/2, vc.numypixels/4);
        assert(leftChild != NULL);
        midChild->nextGen();

        if (rightChild == NULL)
            rightChild = spawnChild();    // make new left child
        else
            rightChild->plotAt(vc.numxpixels*5/6, vc.numypixels/3);
        assert(leftChild != NULL);
        rightChild->nextGen();

        terminal = 0;    // if the node was terminal before, its not now

        if (newChild->age < 25)
            newChild->nextGen();
        else if (leftChild->terminal == 1 &&
                 newChild->fitness()*0.7 > leftChild->fitness())
        {   // replace the left child with the new child
            delete leftChild;
            leftChild = newChild;
            newChild = spawnChild();
            assert(newChild != NULL);
        } else if (midChild->terminal == 1 &&
                   newChild->fitness()*0.7 > midChild->fitness())
        {   // replace the left child with the new child
            delete midChild;
            midChild = newChild;
            newChild = spawnChild();
            assert(newChild != NULL);
        } else if (rightChild->terminal == 1 &&
                   newChild->fitness()*0.7 > rightChild->fitness())
        {   // replace the left child with the new child
            delete rightChild;
            rightChild = newChild;
            newChild = spawnChild();
            assert(newChild != NULL);
        } else if (newChild->age > 50)
        {   // new child is 50 generations old and still has not promoted
            delete newChild;
            newChild = spawnChild();
            assert(newChild != NULL);
        } else
            newChild->nextGen();

        if (kbhit())
        {   // read the key and see what needs to be done
            key = getch();
            if (_stackavail() > 0x0400)
            {   // only process child branch if there is enough stack space
                if (key == 'A' || key == 'a')
                    leftChild->evolve();
                else if (key == 'G' || key == 'g')
                    midChild->evolve();
                else if (key == 'L' || key == 'l')
                    rightChild->evolve();
                drawTree(leftChild != NULL && !leftChild->terminal,
                         midChild != NULL && !midChild->terminal,
                         rightChild != NULL && !rightChild->terminal);
            };  // if
        } else
            key = 0;
    } while (key != ' ');
    delete newChild;
};  // Organism::evolve()