Example #1
0
HRESULT IDirect3DDevice9New::CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle)
{
  dbgf("dev: CreateCubeTexture: %d %d levels %s %s %s", EdgeLength, Levels, getPool(Pool), getUsage(Usage), getMode(Format));
  if(Pool == D3DPOOL_MANAGED)
  {
    dbg("WARNING: Emulating managed cube texture with D3DUSAGE_DYNAMIC");
    Pool = D3DPOOL_DEFAULT;
    Usage |= D3DUSAGE_DYNAMIC;
  }

  HRESULT ret = dev->CreateCubeTexture(EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture, pSharedHandle);
  return ret;
}
Example #2
0
int ZIntHistogram::getMode() const
{
    return getMode(getMinValue(), getMaxValue());
}
  Variant appendOrPrependFilter(const Resource& stream,
                 const String& filtername,
                 const Variant& readwrite,
                 const Variant& params,
                 bool append) {
    const char* func_name =
      append ? "stream_filter_append()" : "stream_filter_prepend()";

    if (!m_registeredFilters.exists(filtername)) {
      raise_warning("%s: unable to locate filter \"%s\"",
                    func_name,
                    filtername.data());
      return false;
    }

    auto file = cast<File>(stream);
    int mode = readwrite.toInt32();
    if (!mode) {
      auto str = file->getMode();
      /* The documentation says a read filter is only created for 'r' and '+'
       * modes, but the implementation will always create one unless
       * STREAM_FILTER_WRITE is passed.
       *
       * This branch is only executed if no STREAM_FILTER* args were passed,
       * so we always create a READ filter.
       */
      mode = k_STREAM_FILTER_READ;
      if (str.find('+') != -1 || str.find('w') != -1 || str.find('a') != -1) {
        mode |= k_STREAM_FILTER_WRITE;
      }
    }
    if (!(mode & k_STREAM_FILTER_ALL)) {
      return false;
    }

    // If it's ALL we create two resources, but only return one - this
    // matches Zend, and is the documented behavior.
    SmartPtr<StreamFilter> ret;
    if (mode & k_STREAM_FILTER_READ) {
      auto resource = createInstance(func_name,
                                     file,
                                     filtername,
                                     params);
      if (!resource) {
        return false;
      }
      ret = resource;
      if (append) {
        file->appendReadFilter(resource);
      } else {
        file->prependReadFilter(resource);
      }
    }
    if (mode & k_STREAM_FILTER_WRITE) {
      auto resource = createInstance(func_name,
                                     file,
                                     filtername,
                                     params);
      if (!resource) {
        return false;
      }
      ret = resource;
      if (append) {
        file->appendWriteFilter(resource);
      } else {
        file->prependWriteFilter(resource);
      }
    }
    return Variant(std::move(ret));
  }
void draw_city(SDL_Renderer* ren)
{
    Point p;
    int x,y;
    SDL_Rect *clip;
    for(x=1; x<MAP_SIZE_X; x++) {
        bool drew_in_this_x = false;
        for(y=1;y<MAP_SIZE_Y; y++) {
            p.x = x*GRID_TILE_SIZE;
            p.y = y*GRID_TILE_SIZE;
            twoDToIso(&p);
            p.x += screen_x;
            p.y += screen_y;
            clip = getTileClip(map_value[x][y]);

            if(p.x < -clip->w) {
                break;
            } else if( p.y > (window_size_y + clip->h) ) {
                break;
            }
            drew_in_this_x = true;
            drawTile(ren, &p, clip);
            draw_animation_tile(ren, x, y);
        }
        if(!drew_in_this_x && p.y > (window_size_y + clip->h)) {
            break;
        }
    }
    p.x = down_point.x*GRID_TILE_SIZE;
    p.y = down_point.y*GRID_TILE_SIZE;
    //printf("(%d,%d) -> ", p.x, p.y);
    twoDToIso(&p);
    //printf("(%d,%d)\n", p.x, p.y);
    p.x += screen_x;
    p.y += screen_y;
    drawTile(ren, &p, getTileClip(TILE_HIGHLIGHT_BLUE));

    p.x = up_point.x*GRID_TILE_SIZE;
    p.y = up_point.y*GRID_TILE_SIZE;
    //printf("(%d,%d) -> ", p.x, p.y);
    twoDToIso(&p);
    //printf("(%d,%d)\n", p.x, p.y);
    p.x += screen_x;
    p.y += screen_y;
    drawTile(ren, &p, getTileClip(TILE_HIGHLIGHT_BLUE));

    if(ready_to_place) {
        Point p2;
        switch(getMode()) {
            case MODE_BUILD_ROAD:
                p = plan_down;

                p2 = plan_down;
                draw_highlight(ren, &plan_down);
                plan_down = p2;
                while(p.x != plan_up.x) {
                    if(p.x < plan_up.x) {
                        p.x += 1;
                    } else {
                        p.x -=1;
                    }
                    p2 = p;
                    draw_highlight(ren, &p);
                    p = p2;
                }
                while(p.y != plan_up.y) {
                    if(p.y < plan_up.y) {
                        p.y += 1;
                    } else {
                        p.y -=1;
                    }
                    p2 = p;
                    draw_highlight(ren, &p);
                    p = p2;
                }
                break;
            case MODE_BUILD_RESIDENTIAL_1:
            case MODE_BUILD_RESIDENTIAL_2:
            case MODE_BUILD_RESIDENTIAL_3:
            case MODE_BUILD_DESTROY:
            case MODE_BUILD_LANDFILL:
            case MODE_BUILD_RETAIL:
            case MODE_BUILD_POWER_SOLAR:
            case MODE_BUILD_POWER_WIND:
            ;
                //p = plan_down;
                //p2 = plan_down;
                //drawTileFromGridPoint(ren, &plan_down, getTileClip(TILE_HIGHLIGHT_GREEN));
                //plan_down = p2;
                int x, y;
                for(x = MIN(plan_down.x, plan_up.x); x<=MAX(plan_down.x, plan_up.x); x++) {
                    for(y = MIN(plan_down.y, plan_up.y); y<=MAX(plan_down.y, plan_up.y); y++) {
                        p.x = x;
                        p.y = y;
                        draw_highlight(ren, &p);
                    }
                }
                break;
            case MODE_BUILD_HOSPITAL:
            case MODE_BUILD_POLICE:
            ;
                p.x = plan_up.x;
                p.y = plan_up.y;
                draw_highlight(ren, &p);
                break;
            case MODE_BUILD_POWER_GAS:
            case MODE_BUILD_POWER_NUCLEAR:
            case MODE_BUILD_SCHOOL:
            case MODE_BUILD_PARK:
            ;
                p.x = plan_up.x;
                p.y = plan_up.y;
                draw_highlight(ren, &p);
                p.x = plan_up.x+1;
                p.y = plan_up.y;
                draw_highlight(ren, &p);
                p.x = plan_up.x;
                p.y = plan_up.y+1;
                draw_highlight(ren, &p);
                p.x = plan_up.x+1;
                p.y = plan_up.y+1;
                draw_highlight(ren, &p);
                break;
            case MODE_BUILD_STADIUM:
            ;
                int x1, y1;
                for(x1 = 0; x1<4; x1++) {
                    for(y1 = 0; y1<4; y1++) {
                        p.x = plan_up.x+x1;
                        p.y = plan_up.y+y1;
                        draw_highlight(ren, &p);
                    }
                }
                break;
			default:
				break;
        }
    }

    draw_animation_overlay(ren);
}
 void start(int _mode)
 {
     assure(_mode == getMode(), "compound collector starting with wrong mode" );
     doStart(_mode);
     started = true;
 }
Example #6
0
void Screen::ShowCharacter(unsigned short c)
{
  // Note that VT100 does wrapping BEFORE putting the character.
  // This has impact on the assumption of valid cursor positions.
  // We indicate the fact that a newline has to be triggered by
  // putting the cursor one right to the last column of the screen.

  int w = konsole_wcwidth(c);

  if (w <= 0)
     return;

  if (cuX+w > columns) {
    if (getMode(MODE_Wrap)) {
      lineProperties[cuY] = (LineProperty)(lineProperties[cuY] | LINE_WRAPPED);
      NextLine();
    }
    else
      cuX = columns-w;
  }

  // ensure current line vector has enough elements
  int size = screenLines[cuY].size();
  if (size == 0 && cuY > 0)
  {
          screenLines[cuY].resize( qMax(screenLines[cuY-1].size() , cuX+w) );
  }
  else
  {
    if (size < cuX+w)
    {
          screenLines[cuY].resize(cuX+w);
    }
  }

  if (getMode(MODE_Insert)) insertChars(w);

  lastPos = loc(cuX,cuY);

  // clear selection on text input
  clearSelection ();

  Character& currentChar = screenLines[cuY][cuX];

  currentChar.character = c;
  currentChar.foregroundColor = ef_fg;
  currentChar.backgroundColor = ef_bg;
  currentChar.rendition = ef_re;

  int i = 0;
  int newCursorX = cuX + w--;
  while(w)
  {
     i++;
   
     if ( screenLines[cuY].size() < cuX + i + 1 )
         screenLines[cuY].resize(cuX+i+1);
     
     Character& ch = screenLines[cuY][cuX + i];
     ch.character = 0;
     ch.foregroundColor = ef_fg;
     ch.backgroundColor = ef_bg;
     ch.rendition = ef_re;

     w--;
  }
  cuX = newCursorX;
}
Example #7
0
eFbLCD::eFbLCD(const char *fb)
{
	m_manual_blit = -1;
	instance = this;
	locked = 0;
	_buffer = 0;
	m_available = 0;
	m_cmap.start = 0;
	m_cmap.len = 256;
	m_cmap.red = m_red;
	m_cmap.green = m_green;
	m_cmap.blue = m_blue;
	m_cmap.transp = m_trans;
	m_alpha = 255;
	m_gamma = 128;
	m_brightness = 128;

	lcdfd = open(fb, O_RDWR);
	if (lcdfd < 0)
	{
		eDebug("[eFbLCD] %s: %m", fb);
		goto nolfb;
	}

	if (ioctl(lcdfd, FBIOGET_VSCREENINFO, &m_screeninfo) < 0)
	{
		eDebug("[eFbLCD] FBIOGET_VSCREENINFO: %m");
		goto nolfb;
	}

	fb_fix_screeninfo fix;
	if (ioctl(lcdfd, FBIOGET_FSCREENINFO, &fix) < 0)
	{
		eDebug("[eFbLCD] FBIOGET_FSCREENINFO: %m");
		goto nolfb;
	}

	m_available = fix.smem_len;
	m_phys_mem = fix.smem_start;
	eDebug("[eFbLCD] %s %dk video mem", fb, m_available / 1024);
	_buffer=(unsigned char*)mmap(0, m_available, PROT_WRITE|PROT_READ, MAP_SHARED, lcdfd, 0);
	if (!_buffer)
	{
		eDebug("[eFbLCD] mmap: %m");
		goto nolfb;
	}

	lcd_type = 4;
	calcRamp();
	getMode();
	setMode(m_xRes, m_yRes, m_bpp);
	enableManualBlit();

	return;
nolfb:
	if (lcdfd >= 0)
	{
		::close(lcdfd);
		lcdfd = -1;
	}
	eDebug("[eFbLCD] framebuffer %s not available", fb);
	return;
}
Example #8
0
void CObjectView::OnUpdateRotate(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(getMode() == CObjectView::ROTATE);
}
Example #9
0
void CObjectView::OnUpdateZoom(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(getMode() == CObjectView::ZOOM);
}
Example #10
0
// LOOKAT
const Camera::LookAtValueType Camera::getLookAt( const EyeUsagePolicyValueType eyeUsagePolicy ) const
{
	vgm::MatrixR matrix;

	// MONOSCOPIC
	if ( getMode() == MONOSCOPIC )
	{
		switch ( eyeUsagePolicy.value() )
		{
			case EYE_LEFT:
				matrix = getLookAtLeft();
				break;

			case EYE_RIGHT:
				matrix = getLookAtRight();
				break;

			case EYE_BOTH:
			{
				const Camera::LookAtValueType left	= getLookAtLeft();
				const Camera::LookAtValueType right	= getLookAtRight();

				vgAssertN( left.equals(right), "lookAtLeft != lookAtRight" );
				matrix = left;
				break;
			}

			//case DEFAULT_EYEUSAGEPOLICY: = EYE_BOTH
			default:
				vgAssertN( false, "Unexpected value for eye usage policy %i", eyeUsagePolicy.value() );
				matrix.setIdentity();
		}
	}
	else
	// STEREOSCOPIC
	{
		const vgm::Vec3f halfEyeSeparation( getEyeSeparation() / 2.f, 0.f, 0.f );

		switch ( eyeUsagePolicy.value() )
		{
			case EYE_LEFT:
			{
				vgm::MatrixR eyeSeparation;
				eyeSeparation.setTranslate( halfEyeSeparation );
				matrix = getLookAtLeft();
				matrix = matrix * eyeSeparation;
				break;
			}

			case EYE_RIGHT:
			{
				vgm::MatrixR eyeSeparation;
				eyeSeparation.setTranslate( -halfEyeSeparation );
				matrix = getLookAtRight();
				matrix = matrix * eyeSeparation;
				break;
			}

			case EYE_BOTH:
			{
				vgAssertN( false, "EYE_BOTH not allowed in non MONOSCOPIC mode" );
				break;
			}

			//case DEFAULT_EYEUSAGEPOLICY: = EYE_BOTH
			default:
				vgAssertN( false, "Unexpected value for eye usage policy %i", eyeUsagePolicy.value() );
				matrix.setIdentity();
		}
	}

	return matrix;
}
Example #11
0
void CObjectView::OnUpdatePan(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(getMode() == CObjectView::PAN);
}
/* ----------------------------------------------------------------------------*
 *
 *  Function Name : readGesture(void)
 *
 *  Description  :Processes a gesture event and returns best guessed gesture
 *
 *  Input : None
 *
 *  Output : None
 *
 *  Return : Number corresponding to gesture. -1 on error.
 * ----------------------------------------------------------------------------*
 * Authors: Sarath S
 * Date: May 17, 2017
 * ---------------------------------------------------------------------------*/
int readGesture(void)
{
    uint8_t fifo_level = 0;
    int bytes_read = 0;
    uint8_t fifo_data[128];
    uint8_t gstatus;
    int motion;
    int i;
    
    /* Make sure that power and gesture is on and data is valid */
    if( !isGestureAvailable() || !(getMode() & 0x41) ) {
        return DIR_NONE;
    }
    
    /* Keep looping as long as gesture data is valid */
    while(1) {
    
        /* Wait some time to collect next batch of FIFO data */
        delayms(FIFO_PAUSE_TIME);
        
        /* Get the contents of the STATUS register. Is data still valid? */
        if( !i2c1_read(APDS9960_GSTATUS, &gstatus,1) ) {
            return ERROR;
        }
        
        /* If we have valid data, read in FIFO */
        if( (gstatus & APDS9960_GVALID) == APDS9960_GVALID ) {
        
            /* Read the current FIFO level */
            if( !i2c1_read(APDS9960_GFLVL, &fifo_level,1) ) {
                return ERROR;
            }

#if DEBUGPRINT
            debugPutString("FIFO Level: ");
            debugPutChar(fifo_level);
#endif

            /* If there's stuff in the FIFO, read it into our data block */
            if( fifo_level > 0) {
                bytes_read = i2c1_read(APDS9960_GFIFO_U, 
                                                fifo_data, 
                                                (fifo_level * 4) );
                if( bytes_read == -1 ) {
                    return ERROR;
                }
#if DEBUGPRINT
                debugPutString("FIFO Dump: ");
                for ( i = 0; i < bytes_read; i++ ) {
                    debugPutChar(fifo_data[i]);
                    debugPutString(" ");
                }
                debugPutString("\r\n");
#endif

                /* If at least 1 set of data, sort the data into U/D/L/R */
                if( bytes_read >= 4 ) {
                    for( i = 0; i < bytes_read; i += 4 ) {
                        gesture_data_.u_data[gesture_data_.index] = \
                                                            fifo_data[i + 0];
                        gesture_data_.d_data[gesture_data_.index] = \
                                                            fifo_data[i + 1];
                        gesture_data_.l_data[gesture_data_.index] = \
                                                            fifo_data[i + 2];
                        gesture_data_.r_data[gesture_data_.index] = \
                                                            fifo_data[i + 3];
                        gesture_data_.index++;
                        gesture_data_.total_gestures++;
                    }
                    
#if DEBUGPRINT
                debugPutString("Up Data: ");
                for ( i = 0; i < gesture_data_.total_gestures; i++ ) {
                    debugPutChar(gesture_data_.u_data[i]);
                    debugPutString(" ");
                }
                debugPutString("\r\n");
#endif

                    /* Filter and process gesture data. Decode near/far state */
                    if( processGestureData() ) {
                        if( decodeGesture() ) {
                            //***TODO: U-Turn Gestures
#if DEBUGPRINT
                           debugPutChar(gesture_motion_);
#endif
                        }
                    }
                    
                    /* Reset data */
                    gesture_data_.index = 0;
                    gesture_data_.total_gestures = 0;
                }
            }
        } else {
    
            /* Determine best guessed gesture and clean up */
            delayms(FIFO_PAUSE_TIME);
            decodeGesture();
            motion = gesture_motion_;
#if DEBUGPRINT
            debugPutString("END: ");
            debugPutChar(gesture_motion_);
#endif
            resetGestureParameters();
            return motion;
        }
    }
}
Example #13
0
HRESULT IDirect3DDevice9New::CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,HANDLE* pSharedHandle) 
{  
  dbgf("CreateTexture: %dx%d %d levels %s %s %s %d %s", Width, Height, Levels, getPool(Pool), getUsage(Usage), getMode(Format), pSharedHandle, pSharedHandle?"SHARED":"");
  int tb = GetTickCount();

#if USE_D3DEX || MANAGE_DEBUG_TEXTURE
  // Managed resources do not exist in D3D9Ex - need to emulate them :(
  if(Pool == D3DPOOL_MANAGED)
  {
    if(config.debug.compatibleTextures)
    {
      ONCE dbg("DEBUG: using compatible managed textures (manage-emulation disabled)");
      Pool = D3DPOOL_DEFAULT;
      Usage |= D3DUSAGE_DYNAMIC;
    }
    else
    {
      //dbg("CreateTexture: %dx%d %d levels %s %s %s %d %s (manage-emulation)", Width, Height, Levels, getPool(Pool), getUsage(Usage), getMode(Format), pSharedHandle, pSharedHandle?"SHARED":"");
      *ppTexture = new IDirect3DTexture9Managed((IDirect3DDevice9Ex*)this, (IDirect3DDevice9Ex*)dev, Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle);
      IDirect3DTexture9Managed* t = (IDirect3DTexture9Managed*)*ppTexture;
      timeWarn(tb, 1000, "CreateTexture Managed");
      if(t->failed()) {
        HRESULT ret = t->error();
        delete t;
        return ret;
      } else {
        return D3D_OK;
      }
    }
  }
#endif
  

  //dbg("CreateTexture: CreateTexture");
  HRESULT ret = dev->CreateTexture(Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle);

#if USE_D3DEX || MANAGE_DEBUG_TEXTURE
  timeWarn(tb, 1000, "CreateTexture");
  if(ret != D3D_OK) {
    dbg("CreateTexture failed! %d %d %d %s %s %s (%s)", Width, Height, Levels, getPool(Pool), getUsage(Usage), getMode(Format), getD3DError(ret));
  } else {    
    *ppTexture = new IDirect3DTexture9New((IDirect3DDevice9Ex*)this, *ppTexture);
  }
#endif

  //dbg("CreatedTexture: %dx%d %d levels %s %s %s %d %s 0x%08X 0x%08X", Width, Height, Levels, getPool(Pool), getUsage(Usage), getMode(Format), pSharedHandle, pSharedHandle?"SHARED":"", ppTexture, *ppTexture);

  return ret;
}
Example #14
0
HRESULT IDirect3DDevice9New::CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,HANDLE* pSharedHandle)
{
  dbgf("dev: CreateVolumeTexture: %dx%dx%d %d levels %s %s %s", Width, Height, Depth, Levels, getPool(Pool), getUsage(Usage), getMode(Format));
  
#if USE_D3DEX || MANAGE_DEBUG_VOLTEXTURE
  if(Pool == D3DPOOL_MANAGED && config.debug.compatibleTextures)
  {
    //dbg("WARNING: Emulating managed volume texture with D3DUSAGE_DYNAMIC");
    ONCE dbg("DEBUG: using compatible managed volume textures (manage-emulation disabled)");
    Pool = D3DPOOL_DEFAULT;
    Usage |= D3DUSAGE_DYNAMIC;
  }

  if(Pool == D3DPOOL_MANAGED)
  {
    // TODO: add error check
    *ppVolumeTexture = new IDirect3DVolumeTexture9Managed((IDirect3DDevice9Ex*)this, (IDirect3DDevice9Ex*)dev, Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle);
    return D3D_OK;
  } else {
    return dev->CreateVolumeTexture(Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle);
  }
#else
  return dev->CreateVolumeTexture(Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle);
#endif
}
Example #15
0
bool File::isPipe() const {
    return S_ISFIFO(getMode());
}
Example #16
0
void CObjectView::OnUpdateLighting(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(getMode() == CObjectView::LIGHT);
}
Example #17
0
void Screen::NewLine()
{
  if (getMode(MODE_NewLine)) Return();
  index();
}
Example #18
0
void CObjectView::OnUpdateModePoint(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(getMode() == CObjectView::POINT);
}
Example #19
0
void Screen::setCursorY(int y)
{
  if (y == 0) y = 1; // Default
  y -= 1; // Adjust
  cuY = qMax(0,qMin(lines  -1, y + (getMode(MODE_Origin) ? tmargin : 0) ));
}
Example #20
0
bool TinyBitmap::add(const uint32_t val){

    const uint16_t val_div = val >> 16;
    const uint16_t val_mod = val & 0xFFFF;

    if (tiny_bmp == nullptr){

        const int aligned_alloc = posix_memalign(reinterpret_cast<void**>(&tiny_bmp), 8, sizes[0] * sizeof(uint16_t));

        if (aligned_alloc != 0){

            cerr << "TinyBitmap::add(): Aligned memory could not be allocated with error " << aligned_alloc << endl;
            exit(1);
        }

        std::memset(tiny_bmp, 0, sizes[0] * sizeof(uint16_t));

        tiny_bmp[0] = (sizes[0] << 3) | bmp_mode | bits_16;
        tiny_bmp[2] = val_div;
    }

    if (getOffset() != val_div) return false;

    uint16_t sz = getSize();
    uint16_t mode = getMode();
    uint16_t cardinality = getCardinality();

    // Compute if inserting new value triggers an increase of the container size
    if (((mode == bmp_mode) && (val_mod >= ((sz - 3) << 4))) || ((mode != bmp_mode) && (cardinality >= (sz - 3 - (mode == rle_list_mode))))){

        // Means that in its current mode, container size must be increased to add a value
        // We need to compute if which mode has the smaller container size

        if ((mode != bmp_mode) && contains(val)) return true;

        runOptimize();

        sz = getSize();
        mode = getMode();
        cardinality = getCardinality();

        if ((mode != rle_list_mode) || (cardinality > (sz - 5))){

            const uint16_t nb_uint_bmp = getNextSize((std::max(val_mod, static_cast<const uint16_t>(maximum() & 0xFFFF)) >> 4) + 4);

            bool res;

            if (mode == rle_list_mode){

                const uint16_t nb_val = size();
                const uint16_t nb_val_rle_list = getNextSize(getNextSize(sz) + 1);
                const uint16_t nb_val_list = getNextSize(nb_val + 4);
                const uint16_t nb_val_min = (nb_val > (0xFFFF - 48)) ? 0xFFFF : std::min(nb_val_rle_list, std::min(nb_val_list, nb_uint_bmp));

                //cout << "TinyBitmap::add(): Size must be increased" << endl;
                //cout << "TinyBitmap::add(): nb_val_rle_list = " << nb_val_rle_list << endl;
                //cout << "TinyBitmap::add(): nb_val_list = " << nb_val_list << endl;
                //cout << "TinyBitmap::add(): nb_uint_bmp = " << nb_uint_bmp << endl;
                //cout << "TinyBitmap::add(): nb_val_min = " << nb_val_min << endl;

                if (nb_val_min > sizes[nb_sizes - 1]) return false;

                res = (nb_val_rle_list == nb_val_min);
                res = res ? change_sz(nb_val_min) : switch_mode(nb_val_min, (nb_val_list <= nb_uint_bmp) ? list_mode : bmp_mode);

                cardinality = getCardinality();
            }
            else {

                const uint16_t nb_val_list = getNextSize(cardinality + 4);

                //cout << "TinyBitmap::add(): Size must be increased" << endl;
                //cout << "TinyBitmap::add(): max_val_mode = " << max_val_mode << endl;
                //cout << "TinyBitmap::add(): nb_uint_bmp = " << nb_uint_bmp << endl;
                //cout << "TinyBitmap::add(): nb_val_list = " << nb_val_list << endl;

                if (mode == bmp_mode) res = (nb_uint_bmp <= nb_val_list) ? change_sz(nb_uint_bmp) : switch_mode(nb_val_list, list_mode);
                else res = (nb_val_list <= nb_uint_bmp) ? change_sz(nb_val_list) : switch_mode(nb_uint_bmp, bmp_mode);
            }

            if (!res) return false;

            mode = getMode();
        }
    }

    //cout << "TinyBitmap::add(): mode = " << mode << endl;

    if (mode == bmp_mode){ // Bitmap mode

        uint16_t& div = tiny_bmp[(val_mod >> 4) + 3];

        const uint16_t mod = 1U << (val_mod & 0xF);

        tiny_bmp[1] += ((div & mod) == 0); // += (1 << 8) if not already set (increase cardinality in header), 0 otherwise
        div |= mod; // Insert new value
    }
void TestStateMachine01::anyStateFunc(const LCreal)
{
   switch (getState()) {

      case INIT_STATE : {
         std::cout << "next()";
         next();
         break;
      }

      case 1 : {
         std::cout << "next()";
         next();
         break;
      }

      case 2 : {
         std::cout << "goTo(4)";
         goTo(4);
         break;
      }

      case 3 : {
         std::cout << "Should NOT be here!";
         break;
      }

      case 4 : {
         if (getMode() != RTN_STATE) {
            std::cout << "call(CALL_01)";
            call(CALL_01);
         }
         else {
            std::cout << "Returned from call(); next()";
            next();
         }
         break;
      }

      case 5 : {
         std::cout << "goTo(99)";
         goTo(99);
         break;
      }

      case 11 : {
         std::cout << "next()";
         next();
         break;
      }

      case 12 : {
         std::cout << "next()";
         next();
         break;
      }

      case 13 : {
         if (getMode() != RTN_STATE) {
            std::cout << "call(CALL_02,arg=13)";
            Basic::Number* arg = new Basic::Integer(13);
            call(CALL_02, arg);
            arg->unref();
         }
         else {
            std::cout << "Returned from call; ";
            const Basic::Boolean* arg = dynamic_cast<const Basic::Boolean*>( getArgument() );
            if (arg != 0) {
               std::cout << "arg(" << arg->getBoolean() << "); ";
            }
            std::cout << "next()";
            next();
         }
         break;
      }

      case 14 : {
         std::cout << "next()";
         next();
         break;
      }

      case 15 : {
         std::cout << "rtn()";
         rtn();
         break;
      }

      case 21 : {
         const Basic::Number* arg = dynamic_cast<const Basic::Number*>( getArgument() );
         if (arg != 0) {
            std::cout << "arg(" << arg->getReal() << "); ";
         }

         std::cout << "next()";
         next();
         break;
      }

      case 22 : {
         std::cout << "next()";
         next();
         break;
      }

      case 23 : {
         std::cout << "rtn(arg=true)";
         Basic::Boolean* arg = new Basic::Boolean(true);
         rtn(arg);
         arg->unref();
         break;
      }

      case 99 : {
         if (getMode() == NEW_STATE) {
            std::cout << "Finished;";
         }
         break;
      }

   };
}
Example #22
0
bool File::isDirectory() const {
    return S_ISDIR(getMode());
}
void draw_HUD(SDL_Renderer* ren)
{
    //Draw the top bar
    SDL_SetRenderDrawColor(ren, 255, 255, 255, 0);
    top_bar.w = window_size_x;
    SDL_RenderFillRect(ren, &top_bar);

    draw_int(ren, font, top_bar_text_color, 20, 0, reqired_power,  "Required: ", " MW");
    draw_int(ren, font, top_bar_text_color, 20, 20, power_avalible, "Avalible: ", " MW");
    draw_int(ren, font, top_bar_text_color, 200, 00, getBalance(), "£", "000");
    draw_int(ren, font, top_bar_text_color, 200, 20, lastBalanceChange, "£", "000");

    draw_int(ren, font, top_bar_text_color, 400, 0, getPopulation(), "Pop: ", "");

    fill_scale_values();
    public_happiness_scale.x = window_size_x-100-80;
    draw_scale(ren, &public_happiness_scale, scale_values.average);

    //Draw the side bar
    if(show_sidebar) {
        SDL_SetRenderDrawColor(ren, 255, 255, 255, 0);
        side_bar.x = window_size_x - side_bar.w;
        SDL_RenderFillRect(ren, &side_bar);
        SDL_Rect scaleBox = {window_size_x-100-5,0,100,fontSizeLarge+2};
        int item_y = side_bar.y+5;

        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POLICE_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.police);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_HEALTH_start);
        setColorGoodBad(ren, scale_values.health);
        scaleBox.y = item_y;
        SDL_RenderFillRect(ren, &scaleBox);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_EDUCATION_start);
        setColorGoodBad(ren, populationPerSchool() < target_population_per_school);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.education);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_SHOPPING_start);
        setColorGoodBad(ren, scale_values.shopping);
        scaleBox.y = item_y;
        SDL_RenderFillRect(ren, &scaleBox);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POWER_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.power);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_WASTE_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.waste);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POLUTION_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.polution);
    }

    SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);

    SDL_Rect open_menu_button = {window_size_x-30,0,30,30};
    SDL_RenderFillRect(ren, &open_menu_button);

    char* modeText = NULL;
    switch(getMode()) {
        case MODE_BUILD_RESIDENTIAL_1:
            modeText = &_binary_MODE_TEXT_RESIDENTIAL_1_start;
            break;
        case MODE_BUILD_RESIDENTIAL_2:
            modeText = &_binary_MODE_TEXT_RESIDENTIAL_2_start;
            break;
        case MODE_BUILD_ROAD:
            modeText = &_binary_MODE_TEXT_BUILD_ROAD_start;
            break;
        case MODE_BUILD_POWER_GAS:
            modeText = &_binary_MODE_TEXT_BUILD_POWER_GAS_start;
            break;
        case MODE_BUILD_DESTROY:
            modeText = &_binary_MODE_TEXT_DESTROY_start;
            break;
        case MODE_BUILD_RETAIL:
            modeText = &_binary_MODE_TEXT_BUILD_RETAIL_start;
            break;
        case MODE_BUILD_HOSPITAL:
            modeText = &_binary_MODE_TEXT_BUILD_HOSPITAL_start;
            break;
        case MODE_BUILD_POWER_SOLAR:
            modeText = &_binary_MODE_TEXT_BUILD_POWER_SOLAR_start;
            break;
        default:
            break;
    }
    if(modeText != NULL) {
        draw_string(ren, font, top_bar_text_color, 5, window_size_y-15, modeText);
    }
    if(ready_to_place) {
        SDL_SetRenderDrawColor(ren, 255, 255, 255, 0);
        SDL_RenderFillRect(ren, &planned_cost_box);
        draw_int(ren, font, top_bar_text_color, 200, 35, costOfPlannedBuild(),  "(-£", "000)");
    }

    SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
    draw_menu(ren);

    if(active_emergency()) {
        Point p = {window_size_x-16, 80};
        drawTile(ren, &p, getClip(SPRITE_BUILD_BACKGROUND));
        drawTile(ren, &p, getClip(SPRITE_BUILD_SERVICES_POLICE));
    }
}
Example #24
0
bool File::isRegularFile() const {
    return S_ISREG(getMode());
}
Example #25
0
void checkEndSound()
{
	if(getMode() != SOUNDPLAYER)
	{
		return;
	}
	
	if(!soundLoaded)
	{
		char ext[256];
		char tmp[256];
		
		strcpy(tmp,getFileName());
		separateExtension(tmp,ext);
		strlwr(ext);
		
		if(strcmp(ext,".pls") == 0 || strcmp(ext,".m3u") == 0)
		{	
			sndMode = TYPE_PLS;
			if(loadPlaylist(getFileName(), &curPlaylist))
			{
				DRAGON_chdir("/");
				loadSound(curPlaylist.urlEntry[0].data);
				plsPos = 0;
			}
			else
			{
				destroyRandomList();
				exitSound(0,0);
				return;
			}
		}
		else
		{
			sndMode = TYPE_NORMAL;
			
			bool success = loadSound(getFileName());
			
			if(soundMode == SOUND_ONESHOT || firstTime)
			{
				if(success == false)
				{
					destroyRandomList();
					exitSound(0,0);
					
					return;
				}
			}
			else
			{			
				while(!success)	
				{
					getNextSoundInternal(false);
					
					if(getMode() == BROWSER) // cover for no files found
					{	
						destroyRandomList();
						
						return;
					}
					
					success = loadSound(getFileName());
				}
			}
		}
		
		sampleWidth = (getSoundLength() / 236);
		soundLoaded = true;
	}
	
	firstTime = false;
	
	if(getState() == STATE_STOPPED || getState() == STATE_UNLOADED)
	{
		if(sndMode == TYPE_NORMAL)
		{
			if(soundMode == SOUND_ONESHOT)
			{
				exitSound(0,0);
			}
			else
			{
				getNextSoundInternal(true);
			}
		}
		if(sndMode == TYPE_PLS)
		{
			if(!queued)
			{
				if(plsPos == curPlaylist.numEntries - 1)
					plsPos = 0;
				else
					plsPos++;
			}
			
			DRAGON_chdir("/");
			loadSound(curPlaylist.urlEntry[plsPos].data);
			
			queued = false;
		}		
	}
}
Example #26
0
bool File::isSymlink() const {
    return S_ISLNK(getMode());
}
Example #27
0
boost::uint32_t Reader::processBuffer(PointBuffer& data, boost::uint64_t index) const
{
    const Schema& schema = data.getSchema();

    // make up some data and put it into the buffer

    // how many are they asking for?
    boost::uint64_t numPointsWanted = data.getCapacity();

    // we can only give them as many as we have left
    boost::uint64_t numPointsAvailable = getNumPoints() - index;
    if (numPointsAvailable < numPointsWanted)
        numPointsWanted = numPointsAvailable;

    const Bounds<double>& bounds = getBounds();
    const std::vector< Range<double> >& dims = bounds.dimensions();
    const double minX = dims[0].getMinimum();
    const double maxX = dims[0].getMaximum();
    const double minY = dims[1].getMinimum();
    const double maxY = dims[1].getMaximum();
    const double minZ = dims[2].getMinimum();
    const double maxZ = dims[2].getMaximum();

    const double numDeltas = (double)getNumPoints() - 1.0;
    const double delX = (maxX - minX) / numDeltas;
    const double delY = (maxY - minY) / numDeltas;
    const double delZ = (maxZ - minZ) / numDeltas;

    const Dimension& dimX = schema.getDimension("X", getName());
    const Dimension& dimY = schema.getDimension("Y", getName());
    const Dimension& dimZ = schema.getDimension("Z", getName());
    const Dimension& dimTime = schema.getDimension("Time", getName());

    boost::uint64_t time = index;

    const Reader::Mode mode = getMode();

    boost::uint32_t cnt = 0;
    data.setNumPoints(0);

    for (boost::uint32_t pointIndex=0; pointIndex<numPointsWanted; pointIndex++)
    {
        double x;
        double y;
        double z;
        switch (mode)
        {
            case Reader::Random:
                x = Utils::random(minX, maxX);
                y = Utils::random(minY, maxY);
                z = Utils::random(minZ, maxZ);
                break;
            case Reader::Constant:
                x = minX;
                y = minY;
                z = minZ;
                break;
            case Reader::Ramp:
                x = minX + delX * pointIndex;
                y = minY + delY * pointIndex;
                z = minZ + delZ * pointIndex;
                break;
            default:
                throw pdal_error("invalid mode in FauxReader");
                break;
        }

        data.setField<double>(dimX, pointIndex, x);
        data.setField<double>(dimY, pointIndex, y);
        data.setField<double>(dimZ, pointIndex, z);
        data.setField<boost::uint64_t>(dimTime, pointIndex, time);

        ++time;

        ++cnt;
        data.setNumPoints(cnt);
        assert(cnt <= data.getCapacity());
    }

    return cnt;
}
Example #28
0
bool File::isSocket() const {
    return S_ISSOCK(getMode());
}
Example #29
0
	void RtBroker::initializeBacktest(BrkLib::SimulationProfileData const& simulProfileData )
	{

		engine_m.initialize( simulProfileData, getMode() & BM_ONE_POSITION_PER_SYMBOL, !(getMode() & BM_USE_CLOSE_POS_COMMANDS) );
	}
Example #30
0
  bool TracAux_c::config_base ( const IdentItem_c* apc_ident, IsoAgLib::IdentMode_t at_identMode, uint16_t aui16_suppressMask )
  {
    //store old mode to decide to register or unregister to request for pgn
    IsoAgLib::IdentMode_t t_oldMode = getMode();

    //call config for handling which is base data independent
    //if something went wrong leave function before something is configured
    if ( ! BaseCommon_c::config_base ( apc_ident, at_identMode, aui16_suppressMask ) ) return false;

    if ( at_identMode == IsoAgLib::IdentModeImplement )
    {
      // set Time Period in ms for Scheduler_c
      mt_task.setPeriod( 100, false );
    }
    else
    { //IdentModeTractor
      // set Time Period in ms for Scheduler_c
      mt_task.setPeriod( 1000, false );
    }

    // un-/register to PGN
    if (t_oldMode == at_identMode)
      ; // no change, still the same mode
    else if (at_identMode == IsoAgLib::IdentModeTractor) {
      // a change from Implement mode to Tractor mode occured
      RegisterPgn_s s_register = getRegisterPgn();
      s_register(AUX_VALVE_0_ESTIMATED_FLOW, gcui32_pgnMask16consecutive);
      s_register(AUX_VALVE_0_MEASURED_FLOW, gcui32_pgnMask16consecutive);
      s_register(AUX_VALVE_0_COMMAND, gcui32_pgnMask16consecutive);
    } else {
      // a change from Tractor mode to Implement mode occured
      UnregisterPgn_s s_unregister = getUnregisterPgn();
      s_unregister(AUX_VALVE_0_ESTIMATED_FLOW, gcui32_pgnMask16consecutive);
      s_unregister(AUX_VALVE_0_MEASURED_FLOW, gcui32_pgnMask16consecutive);
      s_unregister(AUX_VALVE_0_COMMAND, gcui32_pgnMask16consecutive);
    }

    // set configure values
    mi32_lastMsgReceivedCmd = 0;

    for (int i = 0; i < nrOfValves; i++)
    {
      marr_auxFlag[i].ui8_estimatedActivated = false;
      marr_auxFlag[i].ui8_measuredActivated = false;
      marr_auxFlag[i].ui8_commandActivated = false;

      marr_valve[i].ui8_extendPortEstFlow = 125;
      marr_valve[i].ui8_retractPortEstFlow = 125;
      marr_valve[i].ui8_estFailSaveMode = IsoAgLib::IsoNotAvailableAux;
      marr_valve[i].ui8_estValveState = IsoAgLib::IsoNotAvailableAuxExt;
      marr_valve[i].ui8_extendPortMeasuredFlow = 125;
      marr_valve[i].ui8_retractPortMeasuredFlow = 125;
      marr_valve[i].ui16_extendPortPressure = 0;
      marr_valve[i].ui16_retractPortPressure = 0;
      marr_valve[i].ui8_returnPortPressure = 0;
      marr_valve[i].ui8_cmdPortFlow = 0;
      marr_valve[i].ui8_cmdFailSaveMode = IsoAgLib::IsoNotAvailableAux;
      marr_valve[i].ui8_cmdValveState = IsoAgLib::IsoNotAvailableAuxExt;
      marr_valve[i].ui8_estValveLimitStatus = IsoAgLib::IsoNotAvailableLimit;
      marr_valve[i].ui8_measuredValveLimitStatus = IsoAgLib::IsoNotAvailableLimit;
    }
    return true;
  }