bool VRSDClientLuaImplementation::IsGlobalUserDataOfType(const char* Name, const char* Type)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  VMemoryTempBuffer<512> copyBuffer(Name); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');

  lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, Tokenizer.Next());
  if(LookupPath(Tokenizer) != HKV_SUCCESS)
    return false;

  // now the variable should be at the top of the stack
  return LUA_TestUserData(m_pLuaState, -1, Type) != NULL;
}
示例#2
0
文件: Engine.cpp 项目: zgub4/op3d
void op3d::Engine::createIndexBuffer()
{
    VkDeviceSize bufferSize = sizeof(indices[0]) * indices.size();

    VDeleter<VkBuffer> stagingBuffer{device, vkDestroyBuffer};
    VDeleter<VkDeviceMemory> stagingBufferMemory{device, vkFreeMemory};
    createBuffer(bufferSize,
                 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
                 stagingBuffer,
                 stagingBufferMemory);

    void* data;
    vkMapMemory(device, stagingBufferMemory, 0, bufferSize, 0, &data);
    memcpy(data, indices.data(), (std::size_t)bufferSize);
    vkUnmapMemory(device, stagingBufferMemory);

    createBuffer(bufferSize,
                 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
                 indexBuffer,
                 indexBufferMemory);

    copyBuffer(stagingBuffer, indexBuffer, bufferSize);
}
bool VRSDClientLuaImplementation::GetGlobalType(const char*pVariableName, char * pUserDataTypeName)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  VMemoryTempBuffer<512> copyBuffer(pVariableName); // operate on a copy string in the tokenizer

  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, Tokenizer.Next());

  if(LookupPath(Tokenizer) != HKV_SUCCESS)
    return false;

  const char * szName = VSWIG_Lua_typename(m_pLuaState, -1);
  sprintf(pUserDataTypeName, "%s", szName);
  
  return pUserDataTypeName[0] != 0;
}
示例#4
0
文件: main.c 项目: Cruel/ctrulib
int main()
{
	initSrv();
	
	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	aptSetupEventHandler();

	APP_STATUS status;
	while((status=aptGetStatus())!=APP_EXITING)
	{
		if(status==APP_RUNNING)
		{
			u32 PAD=hidSharedMem[7];
			
			u32 regData=PAD|0x01000000;
			GSPGPU_WriteHWRegs(NULL, 0x202A04, (u32*)&regData, 4);

			renderEffect();
			swapBuffers();
			copyBuffer();
		}
		svc_sleepThread(16666666);
	}

	hidExit();
	gspGpuExit();
	aptExit();
	svc_exitProcess();
	return 0;
}
示例#5
0
文件: main.c 项目: Aliakr18/ctrulib
int main()
{
	getSrvHandle(&srvHandle);
	
	aptInit();

	gspGpuInit();

	Handle hidHandle;
	Handle hidMemHandle;
	srv_getServiceHandle(srvHandle, &hidHandle, "hid:USER");
	HIDUSER_GetInfo(hidHandle, &hidMemHandle);
	svc_mapMemoryBlock(hidMemHandle, 0x10000000, 0x1, 0x10000000);

	HIDUSER_Init(hidHandle);

	while(1)
	{
		u32 PAD=((u32*)0x10000000)[7];
		renderEffect();
		swapBuffers();
		copyBuffer();
		u32 regData=PAD|0x01000000;
		GSPGPU_WriteHWRegs(gspGpuHandle, 0x202A04, (u8*)&regData, 4);
		svc_sleepThread(1000000000);
	}

	svc_exitProcess();
	return 0;
}
bool VRSDClientLuaImplementation::UpdateGlobalVariable(const char* szVarName, const char* szNewValue)
{
  if(!szVarName || !szNewValue || szVarName[0]==0)
    return false;

  // we can only get global symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VMemoryTempBuffer<512> copyBuffer(szVarName); // operate on a copy string in the tokenizer

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  const char* pCurrent = Tokenizer.Next();
  unsigned int i = 0;

  const char* pLastField = NULL;

  lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, pCurrent);
  if(lua_isnil(m_pLuaState, -1))
    return false;
  if(LookupPath(Tokenizer, &pLastField) != HKV_SUCCESS)
    return false;

  // now the variable is at the top of the stack, update its value
  int iLuaType = lua_type(m_pLuaState, -1);
  lua_pop(m_pLuaState, 1);

  bool bIsIntegerKey = false;
  if(pLastField && VStringUtil::IsIntegerString(pLastField))
  {
    bIsIntegerKey = true;
    lua_pushnumber(m_pLuaState, (LUA_NUMBER)atoi(pLastField));
  }

  if (!PushValue(iLuaType, szNewValue))
    return false;

  if( Tokenizer.GetTokenCount() > 1 )
  {
    VASSERT(pLastField != NULL);
    if(bIsIntegerKey)
    {
      lua_settable(m_pLuaState, -3);
    }
    else
    {
      lua_setfield(m_pLuaState, -2, pLastField);
    }
  }
  else
  {
    lua_setglobal(m_pLuaState, szVarName);
  }

  return true;
}
示例#7
0
void PixelBufferClass::RotoZoom(LayerInfo* layer)
{
    int ZoomRotation = layer->ZoomRotation;
    xlColor c;
    float PI_2 = 6.283185307179586476925286766559;

    float W,sin_W,cos_W,x_cos_W,x_sin_W;


    int u,v,indx;
    //  How I can I get these values?
    int StartFrame = layer->buffer.curEffStartPer;
    int CurrentFrame = layer->buffer.curPeriod;
    int EndFrame = layer->buffer.curEffEndPer;
    int MaxSizeArray = layer->BufferHt*layer->BufferWi;

    float EP; // EP is how far we are into the current effect
    if((EndFrame-StartFrame)>0)
        EP = (CurrentFrame-StartFrame)/(EndFrame-StartFrame);
    else
        EP=0.0;

    W = PI_2 * (ZoomRotation/10.0);
    W*=EP; //    Move radian as we are farther into the effect

//  This is temp work around for a buffer allocation to copy data before roto zooming.
//  This would be better to be a dynamic buffer allocation and deletion of buffer at end of routine
    std::vector<xlColor> copyBuffer(MaxSizeArray);

    for (int x = 0; x < layer->BufferWi; x++)
    {
        for (int y = 0; y < layer->BufferHt; y++)
        {
            layer->buffer.GetPixel(x, y, c);
            indx = x*layer->BufferHt+y;
            copyBuffer[indx]=c;  // Make a copy of existing frame buffer
        }
    }
    cos_W = cos(W);
    sin_W = sin(W);
    for (int x = 0; x < layer->BufferWi; x++)
    {
        x_cos_W=x*cos_W; // save some compute cycles
        x_sin_W=x*sin_W;
        for (int y = 0; y < layer->BufferHt; y++)
        {
            u = x_cos_W+y*(-sin_W); // Calculate new location to move old color to
            v = x_sin_W+y*cos_W;
            indx = u*layer->BufferHt+v;
            c=copyBuffer[indx]; // get color from copyBuffer
            layer->buffer.SetPixel(x, y, c); // and overwrite current x,y location
        }
    }


}
Buffering & Buffering::operator= ( const Buffering &rhs ) {
    if ( this != &rhs ) { //If the addresses are not the same

    _iBufferLen    = rhs._iBufferLen;
    _iDelayLen     = rhs._iDelayLen;

    init();
    copyBuffer( _pfBuffer, rhs._pfBuffer );

    }
    return *this;
}
示例#9
0
// Test copying from one buffer to another.
TEST_F(ClBufferTest, writeCopyAndRead) {
    ClBuffer in(error, *c, bufferSize, input.data(), clReadOnly);
    ASSERT_OK(error);
    ClBuffer out(error, *c, bufferSize, clWriteOnly);
    ASSERT_OK(error);
    ClCopyBuffer copyBuffer(in, out);
    q->enqueue(error, copyBuffer); ASSERT_OK(error);
    ClReadBuffer readBuffer(out, output.data());
    q->enqueue(error, readBuffer); ASSERT_OK(error);
    q->finish(error); ASSERT_OK(error);
    ASSERT_EQ(input, output) << "Data read from buffer was not the same as "
    "data copied into it.";
}
示例#10
0
void PppConfPacket::appendOption(PppConfOption* opt) {
	unsigned newLen = getUnitLength() + opt->bufLen + 2;
	setUnitLength(newLen);
	setLengthVal(newLen); // Change the length within the packet.
	
	// Point to the new empty space at the end of the buffer.
	// Can't get this before changing the size in case the buffer is moved.
	ACE_UINT8* ptr = ptrUnit() + getUnitLength() - (opt->bufLen + 2); 
	
	*ptr = opt->optType;
	++ptr;
	*ptr = opt->bufLen + 2;
	++ptr;
	copyBuffer(ptr, opt->optBuf, opt->bufLen);
}
bool VRSDClientLuaImplementation::GetLocalType(const char* pVariableName, char * pUserDataTypeName)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  const char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(pVariableName); // operate on a copy string in the tokenizer

  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();

  pUserDataTypeName[0] = 0;

  while((pSymbolName = lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {                                                             //stack: ..., localX, TOP
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      // there is already the local on the stack
      if(LookupPath(Tokenizer) != HKV_SUCCESS)
        return false;

      const char * szName = VSWIG_Lua_typename(m_pLuaState, -1);
      sprintf(pUserDataTypeName, "%s", szName);

      return pUserDataTypeName[0] != 0;
    }

    // clean up the stack and increment the index to get the next local variable
    lua_pop(m_pLuaState, 1);                                    //stack: ..., TOP
    iLocalIndex++;
  }

  return false;
}
bool VRSDClientLuaImplementation::GetUserDataPointerFromLocal(const char* szVariable, void** ppUserData, void ** ppEnvironment)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);
  VLuaStackCleaner stackCleaner(m_pLuaState);


  char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(szVariable); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();

  while((pSymbolName = (char*)lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {                                                       //Stack: ..., localX, TOP
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      VLuaStackCleaner innerStackCleaner(m_pLuaState);
      //there is already the local on the stack...
      if(LookupPath(Tokenizer) != HKV_SUCCESS)
        return false;

      // now the variable is at the top of the stack
      *ppUserData = lua_touserdata(m_pLuaState, -1);    //Stack: ..., localX, {field}, TOP
      *ppEnvironment = m_pLuaState;
      return true;
    }

    // remove the value and update the index to get the next local variable
    lua_pop(m_pLuaState, 1);
    iLocalIndex++;
  }

  return false;
}
bool VRSDClientLuaImplementation::IsLocalUserDataOfType(const char* Name, const char* Type)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  const char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(Name); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();

  while((pSymbolName = lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {                                                             //stack: ..., localX, TOP
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      VLuaStackCleaner innerStackCleaner(m_pLuaState);
      // there is already the local on the stack

      if(LookupPath(Tokenizer) != HKV_SUCCESS)
        return false;

      // now the variable is at the top of the stack
      return LUA_TestUserData(m_pLuaState, -1, Type) != NULL;
    }

    // increment the index to get the next local variable
    iLocalIndex++;
    lua_pop(m_pLuaState, 1);
  }
 
  return false;
}
示例#14
0
文件: main.c 项目: bunnei/ctrulib
int main()
{
	initSrv();
		
	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	Handle fsuHandle;
	srv_getServiceHandle(NULL, &fsuHandle, "fs:USER");
	FSUSER_Initialize(fsuHandle);

	Handle fileHandle;
	u32 bytesRead;
	FS_archive sdmcArchive=(FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FS_path filePath=(FS_path){PATH_CHAR, 10, (u8*)"/test.bin"};
	FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	FSFILE_Read(fileHandle, &bytesRead, 0x0, (u32*)gspHeap, 0x46500);
	FSFILE_Close(fileHandle);

	aptSetupEventHandler();
	
	while(!aptGetStatus())
	{
		u32 PAD=hidSharedMem[7];
		renderEffect();
		swapBuffers();
		copyBuffer();
		u32 regData=PAD|0x01000000;
		GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
		svc_sleepThread(1000000000);
	}

	svc_closeHandle(fsuHandle);
	hidExit();
	gspGpuInit();
	aptExit();
	svc_exitProcess();
	return 0;
}
示例#15
0
文件: Engine.cpp 项目: zgub4/op3d
void op3d::Engine::updateUniformBuffer()
{
    static auto startTime = std::chrono::high_resolution_clock::now();

    auto currentTime = std::chrono::high_resolution_clock::now();
    float time = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startTime).count() / 1000.0f;

    UniformBufferObject ubo = {};
    ubo.model = glm::rotate(glm::mat4(), time * glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
    ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
    ubo.proj = glm::perspective(glm::radians(45.0f), swapChain.getExtent().width / (float)swapChain.getExtent().height, 0.1f, 10.0f);
    ubo.proj[1][1] *= -1;

    void* data;
    vkMapMemory(device, uniformStagingBufferMemory, 0, sizeof(ubo), 0, &data);
    memcpy(data, &ubo, sizeof(ubo));
    vkUnmapMemory(device, uniformStagingBufferMemory);

    copyBuffer(uniformStagingBuffer, uniformBuffer, sizeof(ubo));
}
示例#16
0
 void FileReadSP::step(stk::StkFrames& buffer, Tick tick, bool is_new_event) {
   if (!file_read_.isOpen()) {
     file_read_.open(file_name_);
   }
   Tick s = std::max((long)0, (long)tick);
   Tick e = std::min((long)(file_read_.fileSize()), (long)(tick+buffer.frames()));
   Tick n_frames = e - s;
   if (n_frames <= 0) {
     // no overlap at all
     zeroBuffer(buffer);
   } else if (n_frames == buffer.frames()) {
     // file spans whole buffer
     file_read_.read(buffer, s, do_normalize_);
   } else {
     // partial overlap.  Read into a temp buffer and copy
     // the active part into buffer.
     temp_buffer_.resize(n_frames, buffer.channels());
     file_read_.read(temp_buffer_, s, do_normalize_);
     copyBuffer(temp_buffer_, 0, buffer, s - tick, n_frames);
   }
 }
示例#17
0
文件: tests.cpp 项目: Bimbochobot/FIT
// run all tests and store them to the tiled bitmap
void runAllMakeTiled()
{
  int fw = 5 * frame_w;
  int fh = 2 * frame_h;
  
  // alokace pameti 
  S_RGBA * tiled = new S_RGBA[fw * fh];
  memset( tiled, 0, fw*fh*sizeof(S_RGBA) );

  // vsechny testy
  for( int y = 0; y < 2; ++y)
    for( int x = 0; x < 5; ++x)
    {
      // Resolve test number
      int test = 1 + y*5+x;

      // Clear frame buffer
      clearFB();
      
      // Run test
      runTest(test);
      
      // Copy bitmap
      copyBuffer( frame_buffer, tiled, x * frame_w, y * frame_h, frame_w, frame_h, fw );
    
    }

   // Clear frame buffer
   clearFB();

   // save bitmap
   SaveBitmap( "tiled.bmp", tiled, fw, fh );

   // Dealokace pameti
   delete [] tiled;
}
示例#18
0
文件: wave.cpp 项目: Jongsix/espeak
size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSize)
{
	ENTER("wave_write");
	size_t bytes_written = 0;
	// space in ringbuffer for the sample needed: 1x mono channel but 2x for 1 stereo channel
	size_t bytes_to_write = (out_channels==1) ? theSize : theSize*2;
	my_stream_could_start = 0;
 
	if(pa_stream == NULL)
	{
		SHOW_TIME("wave_write > wave_open_sound\n");
		if (0 != wave_open_sound())
		{
			SHOW_TIME("wave_write > wave_open_sound fails!");
			return 0;
		}
		my_stream_could_start=1;
	}
	else if (!wave_is_busy(NULL))
	{
		my_stream_could_start = 1;
	}
	assert(BUFFER_LENGTH >= bytes_to_write);
 
	if (myWrite >= myBuffer + BUFFER_LENGTH)
	{
		myWrite = myBuffer;
	} // end if (myWrite >= myBuffer + BUFFER_LENGTH)
 
	size_t aTotalFreeMem=0;
	char* aRead = myRead;
	SHOW("wave_write > aRead=%x, myWrite=%x\n", (int)aRead, (int)myWrite);
 
	while (1)
	{
		if (my_callback_is_output_enabled && (0==my_callback_is_output_enabled()))
		{
			SHOW_TIME("wave_write > my_callback_is_output_enabled: no!");
			return 0;
		}
 
		aRead = myRead;
 
		// write pointer is before read pointer?
		if (myWrite >= aRead)
		{
			aTotalFreeMem = aRead + BUFFER_LENGTH - myWrite;
		}
		else // read pointer is before write pointer!
		{
			aTotalFreeMem = aRead - myWrite;
		} // end if (myWrite >= aRead)
 
		if (aTotalFreeMem>1)
		{
			// -1 because myWrite must be different of aRead
			// otherwise buffer would be considered as empty
			aTotalFreeMem -= 1;
		} // end if (aTotalFreeMem>1)
 
		if (aTotalFreeMem >= bytes_to_write)
		{
			break;
		} // end if (aTotalFreeMem >= bytes_to_write)
		
		//SHOW_TIME("wave_write > wait");
		SHOW("wave_write > wait: aTotalFreeMem=%d\n", aTotalFreeMem);
		SHOW("wave_write > aRead=%x, myWrite=%x\n", (int)aRead, (int)myWrite);
		usleep(10000);
	} // end while (1)
 
	aRead = myRead;
 
	// write pointer is ahead the read pointer?
	if (myWrite >= aRead)
	{
		SHOW_TIME("wave_write > myWrite >= aRead");
		// determine remaining free memory to the end of the ringbuffer
		size_t aFreeMem = myBuffer + BUFFER_LENGTH - myWrite;
		// is enough linear space available (regardless 1 or 2 channels)?
		if (aFreeMem >= bytes_to_write)
		{
			// copy direct - no wrap around at end of ringbuffer needed
			myWrite += copyBuffer(myWrite, theMono16BitsWaveBuffer, theSize);
		}
		else // not enough linear space available
		{
			// 2 channels (stereo)?
			if (out_channels == 2)
			{
				// copy with wrap around at the end of ringbuffer
				copyBuffer(myWrite, theMono16BitsWaveBuffer, aFreeMem/2);
				myWrite = myBuffer;
				myWrite += copyBuffer(myWrite, theMono16BitsWaveBuffer+aFreeMem/2, theSize - aFreeMem/2);
			}
			else // 1 channel (mono)
			{
				// copy with wrap around at the end of ringbuffer
				copyBuffer(myWrite, theMono16BitsWaveBuffer, aFreeMem);
				myWrite = myBuffer;
				myWrite += copyBuffer(myWrite, theMono16BitsWaveBuffer+aFreeMem, theSize - aFreeMem);
			} // end if (out_channels == 2)
		} // end if (aFreeMem >= bytes_to_write)
	} // if (myWrite >= aRead)
	else // read pointer is ahead the write pointer
	{
		SHOW_TIME("wave_write > myWrite <= aRead");
		myWrite += copyBuffer(myWrite, theMono16BitsWaveBuffer, theSize);
	} // end if (myWrite >= aRead)
 
	bytes_written = bytes_to_write;
	myWritePosition += theSize/sizeof(uint16_t); // add number of samples
 
	if (my_stream_could_start && (get_used_mem() >= out_channels * sizeof(uint16_t) * FRAMES_PER_BUFFER))
	{
		start_stream();
	} // end if (my_stream_could_start && (get_used_mem() >= out_channels * sizeof(uint16_t) * FRAMES_PER_BUFFER))
 
	SHOW_TIME("wave_write > LEAVE");
 
	return bytes_written;
}
bool VRSDClientLuaImplementation::GetSubSymbolsForGlobal(char* GlobalName, DynArray_cl<VRSDScriptSymbol>& SubSymbols, unsigned int& SubSymbolCount)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  SubSymbolCount = 0;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  ScopedBooleanToTrue disableDebugCallback(m_bDebuggerRetrievingValues);
  VLuaStackCleaner stackCleaner(m_pLuaState);

  VMemoryTempBuffer<512> copyBuffer(GlobalName); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  lua_getfield(m_pLuaState, LUA_GLOBALSINDEX, Tokenizer.Next());
  if(LookupPath(Tokenizer) != HKV_SUCCESS)
    return false;

  // now the variable should be at the top of the stack and we can get the subvariables of it
  
  // first key for the iteration
  lua_pushnil(m_pLuaState);
  
  while (lua_next(m_pLuaState, -2) != 0)
  {
    // after this the key is at -2 and the value at -1
    
    // we only want string fields and numeric fields
    // (lua_isstring returns also true for numbers, using
    // tostring later on will cast the number to a string)
    int iKeyType = lua_type(m_pLuaState, -2);
    if (iKeyType==LUA_TNUMBER || iKeyType==LUA_TSTRING)
    {  
      VString sKeyBuffer;

      //this if prevents a conversion of number on the Lua stack
      if(iKeyType==LUA_TNUMBER) sKeyBuffer.Format("%1.0f", lua_tonumber(m_pLuaState, -2));
      else                      sKeyBuffer = lua_tostring(m_pLuaState, -2);

      const char* pSymbolName = sKeyBuffer.AsChar();

      if(pSymbolName)
      {
        // table member variable
        if(lua_istable(m_pLuaState, -1))
        {
          // add a symbol for the table
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "table", VRSDScriptSymbol::SYMBOL_TABLE);
        }
        // numeric member variable
        else if(lua_type(m_pLuaState, -1) == LUA_TNUMBER)
        {
          char buffer[32];
          sprintf(buffer, "%f", lua_tonumber(m_pLuaState, -1));
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, buffer, VRSDScriptSymbol::SYMBOL_NUMBER);
        }
        // string member variable
        else if(lua_type(m_pLuaState, -1) == LUA_TSTRING)
        {
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, lua_tostring(m_pLuaState, -1), VRSDScriptSymbol::SYMBOL_STRING);
        }
        // function member variable
        else if(lua_isfunction(m_pLuaState, -1))
        {
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "function", VRSDScriptSymbol::SYMBOL_FUNCTION);
        }
        // userdata member variable
        else if(lua_isuserdata(m_pLuaState, -1))
        {
          char buffer[128];
          swig_type_info* type = (swig_type_info *)LUA_GetSwigType(m_pLuaState, -1);
          void * pUserData = lua_touserdata(m_pLuaState, -1);

          if(type)
          {
            vis_snprintf(buffer, 128, "userdata:0x%p [%s: 0x%p]", pUserData, type->str, ((swig_lua_userdata*)pUserData)->ptr);
          }
          else
          {
            vis_snprintf(buffer, 128, "userdata:0x%p", lua_touserdata(m_pLuaState, -1));
          }
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, buffer, VRSDScriptSymbol::SYMBOL_USERDATA);
        }
        else if(lua_isboolean(m_pLuaState, -1))
        {
          int iBoolVal = lua_toboolean(m_pLuaState, -1);
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, iBoolVal ? "true" : "false", VRSDScriptSymbol::SYMBOL_BOOLEAN);
        }
        else if(lua_isnil(m_pLuaState, -1))
        {
          AddSymbol(SubSymbols, SubSymbolCount, pSymbolName, "nil", VRSDScriptSymbol::SYMBOL_CLASS);
        }

      }
    }
    lua_pop(m_pLuaState, 1);  // remove the value, keep the key for the next iteration
  }

  return true;
}
示例#20
0
文件: main.c 项目: Tybus/3Dfrogr
int main()
{
	initSrv();

	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	Handle fsuHandle;
	srv_getServiceHandle(NULL, &fsuHandle, "fs:USER");
	FSUSER_Initialize(fsuHandle);

	aptSetupEventHandler();
    init_map();
    int i;
    int j;
    int p=4;
    int d=0;
    int q;
    int frogx = 0;
    int frogy = 0;
    int carx[6][9];
    int logx[5][6];

    // Cant use rand.
    //for(d=1;d<6;d++){
    //    while(p>4){
    //        p = rand();
    //    }
    //    carx[d]=26+p;

     for(d=0;d<8;d++){
        carx[0][d]=26;
        if(d<5){
            logx[0][d]=26;
        }
        d++;
    }
    for(d=1;d<8;d++){
        if(d<5){
            logx[0][d]=0;
        }
        carx[0][d]=0;
        d++;
    }
    for(q=0;q<8;q++){

        for(d=1; d<6; d++){
            if(q<5){
                if(d<5){
                    logx[d][q]=26+p+6;
                }
            }
            carx[d][q]=26+p +6;
            p=p+6;
        }
        p=0;
        q++;
    }
    p= 0;
    for(q=1;q<8;q++){

        for(d=1;d<5;d++){
            if(q<5){
                if(d<5){
                    logx[d][q] = p-6;
                }
            }
            carx[d][q]=p-6;
            p=p-6;
        }
        p=0;
        q++;
     }

	while(!aptGetStatus()){
		u32 PAD=hidSharedMem[7];
		if (PAD == BUTTON_UP){
            frogy+= 1;
            }
        else if (PAD == BUTTON_DOWN){
            frogy+= -1;
            }
        else if (PAD == BUTTON_LEFT){
            frogx+= -1;
            }
        else if (PAD == BUTTON_RIGHT){
            frogx+=1;
            }

		u32 regData=PAD|0x01000000;
		init_map();
        for(i=0;i<6;i++){
            for(j=0;j<8;j++){
                draw_car(carx[i][j],15+j*15);
                if(i<5){
                    if(j<5){
                        draw_logs(logx[i][j],150+j*15);
                        }
                }
            }
        }
        draw_frog(frogx,frogy);
		//Checks Colition
        for(i=0;i<6;i++){
            for(j=0;j<8;j++){
                if(frogy==j+1){
                    if(frogx==carx[i][j]){
                        frogy =0;
                        frogx =0;
                    }
                }
            }
        }
        //Checks if frog in poodle
         if(frogy >9){
            for(i=0;i<5;i++){
                for(j=0;j<5;j++){
                    if(frogy==j+10){
                        if(frogx==logx[i][j] || frogx==logx[i][j]+1 || frogx==logx[i][j]+2){
                                frogx= frogx -1;
                        }
                        else{
                            frogx =0;
                            frogy =0;
                            }
                    }
                }
            }
        }
        //reinitialize the cars :D
        // Cant use f*****g rand
        //for(p=0;p<6;p++){
        //    if(carx[p]==0){
        //        d=5;
        //        while(d>4){
        //            d = rand();
        //        }
        //        carx[p]= 26+d;
        //     }
        //    else {
        //    carx[p]=carx[p]-1;
        //    }
        //}
        for(i=0;i<6;i++){
            for(j=0;j<9;j=j+2){
                if(i<5){
                    if(j<5){
                        if(logx[i][j]==0){
                            logx[i][j]=26;
                        }
                        else{
                        logx[i][j]=logx[i][j]-1;
                        }
                    }
                }
                if(carx[i][j]==0){
                    carx[i][j] =26;
                }
                else{
                    carx[i][j]=carx[i][j]-1;
                }
            }
        }
        for(i=0;i<6;i++){
            for(j=1;j<9;j=j+2){
                if(i<5){
                    if(j<5){
                        if(logx[i][j]==26){
                            logx[i][j]=0;
                        }
                        else{
                        logx[i][j]=logx[i][j]+1;
                        }
                    }
                }
                if(carx[i][j]==26){
                    carx[i][j]=0;
                    }
                else{
                    carx[i][j]= carx[i][j]+1;
                }
            }
        }
		copyBuffer();
		swapBuffers();
		GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
        svc_sleepThread(220000000);


    }

	svc_closeHandle(fsuHandle);
	hidExit();
	gspGpuInit();
	aptExit();
	svc_exitProcess();
	return 0;
}
bool VRSDClientLuaImplementation::GetSubSymbolsForLocal(char* LocalName, DynArray_cl<VRSDScriptSymbol>& SubSymbols, unsigned int& SubSymbolCount)
{
  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;
  
  SubSymbolCount = 0;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugCallback(m_bDebuggerRetrievingValues);

  char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(LocalName); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();

  while((pSymbolName = (char*)lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {                                                       //stack: .., localX, TOP
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      //the local is already on the stack
      if(LookupPath(Tokenizer) != HKV_SUCCESS)
        return false;

      // now we can iterate over the contents of the table
      // first key for the iteration
      lua_pushnil(m_pLuaState);                           //stack: .., localX, {field}, nil, TOP

      //access the last field
      while (lua_next(m_pLuaState, -2) != 0)              //stack: .., localX, {field}, key, value TOP
      {
        // we only want string fields and numeric fields
        // (lua_isstring returns also true for numbers, using
        // tostring later on will cast the number to a string)
        int iKeyType = lua_type(m_pLuaState, -2);
        if (iKeyType==LUA_TNUMBER || iKeyType==LUA_TSTRING)
        {  
          VString sKeyBuffer;

          //this if prevents a conversion of number on the Lua stack
          if(iKeyType==LUA_TNUMBER) sKeyBuffer.Format("%1.0f", lua_tonumber(m_pLuaState, -2));
          else                      sKeyBuffer = lua_tostring(m_pLuaState, -2);

          if(!sKeyBuffer.IsEmpty())
          {
            int iValueType = lua_type(m_pLuaState, -1);
            VString sValueBuffer;

            // table member variable
            switch (iValueType) 
            {
              case LUA_TTABLE:
                // add a symbol for the table
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "table", VRSDScriptSymbol::SYMBOL_TABLE);
                break;
            
              case LUA_TNUMBER:
                // numeric member variable
                sValueBuffer.Format("%f", lua_tonumber(m_pLuaState, -1));
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_NUMBER);
                break;

              case LUA_TSTRING:
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), lua_tostring(m_pLuaState, -1), VRSDScriptSymbol::SYMBOL_STRING);
                break;

              case LUA_TFUNCTION:
                sValueBuffer.Format("function:0x%p", lua_tocfunction(m_pLuaState, -1));
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_FUNCTION);
                break;
              
              case LUA_TBOOLEAN:
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), lua_toboolean(m_pLuaState, -1) ? "true" : "false", VRSDScriptSymbol::SYMBOL_BOOLEAN);
                break;

              case LUA_TNIL:
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "nil", VRSDScriptSymbol::SYMBOL_CLASS);
                break;

              case LUA_TTHREAD:
                sValueBuffer.Format("thread:0x%p", lua_tothread(m_pLuaState, -1));
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_CLASS);
                break;

              case LUA_TUSERDATA:
                sValueBuffer.Format("userdata:0x%p", lua_touserdata(m_pLuaState, -1));
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), sValueBuffer.AsChar(), VRSDScriptSymbol::SYMBOL_USERDATA);
                break;
            
              default:
                AddSymbol(SubSymbols, SubSymbolCount, sKeyBuffer.AsChar(), "unknown", VRSDScriptSymbol::SYMBOL_STRING);
                break;
            }
          }
        }

        // remove the value, keep the key for the next iteration
        lua_pop(m_pLuaState, 1);                        //stack: .., localX, {field}, key, TOP
      }
      return true;
    }

    // clean up the stack and increment the index to get the next local variable
    lua_pop(m_pLuaState, 1);                            //stack: .., TOP
    iLocalIndex++;
  }

  return true;
}
示例#22
0
Buffering::Buffering( const Buffering &rhs ) : _iDelayLen( rhs._iDelayLen ), _iBufferLen( rhs._iBufferLen )  {
    init();
    copyBuffer( _pfBuffer, rhs._pfBuffer );
}
示例#23
0
文件: voterd.c 项目: Chryel/PINT
void checkSDC(int pipe_num) {
  int r_index;
  int bytes_avail = bytesReady(replicas, rep_count, pipe_num);
  if (bytes_avail == 0) {
    return;
  }

  switch (rep_type) {
    case SMR: 
      // Only one rep, so pretty much have to trust it
      sendPipe(pipe_num, 0);
      return;
    case DMR:
      // Can detect, and check what to do
      if (compareBuffs(&(replicas[0].vot_pipes[pipe_num]), &(replicas[1].vot_pipes[pipe_num]), bytes_avail) != 0) {
        printf("Voting disagreement: caught SDC in DMR but can't do anything about it.\n");
      }

      sendPipe(pipe_num, 0);
      return;
    case TMR:
      // Send the solution that at least two agree on
      // TODO: What if buff_count is off?
      for (r_index = 0; r_index < rep_count; r_index++) {
        if (compareBuffs(&(replicas[r_index].vot_pipes[pipe_num]), &(replicas[(r_index + 1) % rep_count].vot_pipes[pipe_num]), bytes_avail) == 0) {
          // If the third doesn't agree, it should be restarted.
          if (compareBuffs(&(replicas[r_index].vot_pipes[pipe_num]), &(replicas[(r_index + 2) % rep_count].vot_pipes[pipe_num]), bytes_avail) != 0) {  
            int restartee = (r_index + 2) % rep_count;
            
            debug_print("Caught SDC: %s : %d\n", controller_name, replicas[restartee].pid);
            if (DEBUG_PRINT) {
              // print all three or just two?

              // Create typed pipes for meta data
              struct typed_pipe print_pipesA[pipe_count];
              struct typed_pipe print_pipesB[pipe_count];
              convertVoteToTyped(replicas[r_index].vot_pipes, pipe_count, print_pipesA);
              convertVoteToTyped(replicas[(r_index + 2) % rep_count].vot_pipes, pipe_count, print_pipesB);
              
              // Copy the buffer over
              char *buffer_A = (char *)malloc(sizeof(char) * MAX_VOTE_PIPE_BUFF);
              char *buffer_B = (char *)malloc(sizeof(char) * MAX_VOTE_PIPE_BUFF);
              copyBuffer(&(replicas[r_index].vot_pipes[pipe_num]), buffer_A, bytes_avail);
              copyBuffer(&(replicas[(r_index + 2) % rep_count].vot_pipes[pipe_num]), buffer_B, bytes_avail);

              // print them out.
              printBuffer(&(print_pipesA[pipe_num]), buffer_A, bytes_avail);
              printBuffer(&(print_pipesB[pipe_num]), buffer_B, bytes_avail);

              free(buffer_A);
              free(buffer_B);
            }
            restart_prep(restartee, r_index);
          } else {
            // If all agree, send and be happy. Otherwise the send is done as part of the restart process
            sendPipe(pipe_num, r_index);
          }
          return;
        } 
      }

      printf("VoterD: TMR no two replicas agreed.\n");
  }
}
示例#24
0
文件: lexer.c 项目: csoren/asmotor
void
lex_Goto(SLexerBookmark* bookmark) {
    copyBuffer(g_currentBuffer, &bookmark->Buffer);
    lex_Current = bookmark->Token;
}
示例#25
0
void main(void) {
	/* your definitions here */
  int leftADValue = 0;
  int rightADValue = 0;
  char leftButton = 1;
  char leftButtonLast = 1;
  char rightButton = 1;
  char rightButtonLast = 1;
	
	// init buttons and seven-segment displays
	initIO();
	// init LCD
	initLCD();
	// init A/D converter
	initADC();

	
	/* your code here */
  drawBuffer();
  wait(100001);
  //setPixel(10, 10, 1);

  //writeString(5, 0, "Hallo Welt");
  writeText(LOREM);

  for(;;) {
    switch (curMode) {
      case 0:
        leftADValue = getADCValue(1);
        curLine = inverseScaleDown(leftADValue, lines);
        writeInt(7, 0, curLine+1);
        writeInt(7, 104, lines);
        copyBuffer(curLine, 7);
        drawBuffer();
    //eventloop(4);
      break;
      case 1:
        copyBuffer(curLine, 7);
        writeInt(7, 0, curLine+1);
        writeInt(7, (128 - 4*CHARACTER_WIDTH), lines);
        drawBuffer();
        curLine++;
        if(curLine > lines)
          curMode = 6;
        else
          curMode = 2;
      break;
      case 2:
        wait(DELAY/2);
        curMode = 3;
      break;
      case 3:
        wait(DELAY/2);
        curMode = 4;
      break;
      case 4:
        wait(DELAY/2);
        curMode = 5;
      break;
      case 5:
        wait(DELAY/2);
        curMode = 1;
      break;
      case 6:
        __wait_nop();
      break;
    }
  printNumber(curMode);
  leftButton = PDR07_P0;
  rightButton = PDR07_P2;
  if(leftButton == 1 && leftButtonLast == 0) {
    if (curMode == 0) {
      curLine = 0;
      curMode = 1;
    }
    else {
      curMode = 0;

    }
  }
  leftButtonLast = leftButton;
  rightButtonLast = rightButton;
		__wait_nop();
  }
}
bool VRSDClientLuaImplementation::UpdateLocalVariable(const char* Variable, const char* NewValue)
{
  if(!Variable || !NewValue)
    return false;

  VASSERT(m_pLuaState);

  if(!m_pLuaState || !m_pActivationRecord)
    return false;

  // we can only get local symbols without a crash if we are really in a Lua code execution path
  if(strcmp(m_pActivationRecord->what, "Lua"))
    return true;

  VLuaStackCleaner stackCleaner(m_pLuaState);
  ScopedBooleanToTrue disableDebugHook(m_bDebuggerRetrievingValues);

  const char* pSymbolName = NULL;
  int iLocalIndex = 1;

  VMemoryTempBuffer<512> copyBuffer(Variable); // operate on a copy string in the tokenizer
  
  VStringTokenizerInPlace Tokenizer(copyBuffer.AsChar(), '.');
  char* pCurrent = Tokenizer.Next();
  int i = 0;
  const char* pLastField = NULL;

  // go through all local variables
  while((pSymbolName = lua_getlocal(m_pLuaState, m_pActivationRecord, iLocalIndex)) != NULL)
  {
    // check if this local variable is the one we want
    if(!strcmp(pSymbolName, pCurrent))
    {
      VLuaStackCleaner innerStackCleaner(m_pLuaState);
      if(LookupPath(Tokenizer, &pLastField) != HKV_SUCCESS)
        return false;

      // now the variable is at the top of the stack, update its value
      int iLuaType = lua_type(m_pLuaState, -1);

      // pop off the field again
      lua_pop(m_pLuaState, 1);

      bool bIsIntegerKey = false;
      if(pLastField && VStringUtil::IsIntegerString(pLastField))
      {
        bIsIntegerKey = true;
        lua_pushnumber(m_pLuaState, (LUA_NUMBER)atoi(pLastField));
      }

      if (!PushValue(iLuaType, NewValue))
      {
        return false;
      }

      if(Tokenizer.GetTokenCount() > 1)
      {
        VASSERT(pLastField != NULL);
        if(bIsIntegerKey)
        {
          lua_settable(m_pLuaState, -3);
        }
        else
        {
          lua_setfield(m_pLuaState, -2, pLastField);
        }
      }
      else
      {
        lua_setlocal(m_pLuaState, m_pActivationRecord, iLocalIndex);
      }

      break;
    }

    // clean up the stack and increment the index to get the next local variable
    lua_pop(m_pLuaState, 1);
    iLocalIndex++;
  }

  return true;
}
示例#27
0
文件: lexer.c 项目: csoren/asmotor
void
lex_Bookmark(SLexerBookmark* bookmark) {
    copyBuffer(&bookmark->Buffer, g_currentBuffer);
    bookmark->Token = lex_Current;
}