コード例 #1
0
ファイル: luamap.cpp プロジェクト: Parhamic/teeworlds
CLuaMapFile::CLuaMapFile(CTile *pTiles, const char *pCode, int Width, int Height)
{
    m_pTiles = pTiles;
    m_pLua = luaL_newstate();
    luaL_openlibs(m_pLua);

    m_Width = Width;
    m_Height = Height;

    //lua_atpanic(m_pLua, &Panic); //Todo

    lua_pushlightuserdata(m_pLua, this);
    lua_setglobal(m_pLua, "pLUA");

    lua_register(m_pLua, ToLower("errorfunc"), this->ErrorFunc);
    lua_register(m_pLua, ToLower("GetTile"), this->GetTile);
    lua_register(m_pLua, ToLower("SetTile"), this->SetTile);
    lua_register(m_pLua, ToLower("GetFlag"), this->GetFlag);
    lua_register(m_pLua, ToLower("SetFlag"), this->SetFlag);
    lua_register(m_pLua, ToLower("GetWidth"), this->GetWidth);
    lua_register(m_pLua, ToLower("GetHeight"), this->GetHeight);


    luaL_dostring(m_pLua, pCode);
    ErrorFunc(m_pLua);
}
コード例 #2
0
ファイル: luafile.cpp プロジェクト: MJavad/teeworlds
void CLuaFile::TickDefered()
{
    if (!g_Config.m_SvLua)
        return;

    ErrorFunc(m_pLua);

    if (!FunctionExist("TickDefered"))
        return;

    FunctionPrepare("TickDefered");
    PushInteger((int)(time_get() * 1000 / time_freq()));
    PushInteger(m_pServer->Server()->Tick());
    FunctionExec();

    ErrorFunc(m_pLua);
}
コード例 #3
0
ファイル: List.c プロジェクト: chinabin/DSAA
int InitListHead(pListHeader *plh)
{
    (*plh) = malloc(sizeof(ListHeader));
    if((*plh) == NULL)
        ErrorFunc(NULL, MALLOC_FAILED);
    (*plh)->ListSize = 0;
    (*plh)->next = NULL;
    return 0;
}
コード例 #4
0
ファイル: List.c プロジェクト: chinabin/DSAA
// replace element of position index, so original element will toward back
bool ListInsert(pListHeader plh, unsigned int index, pListNode pNode)
{
    if(index > plh->ListSize)
        ErrorFunc("Too much bigger index!\n", OUT_OF_SCOPE);

    pListNode pRplcedNode = GetElem(plh, index);
    pListNode pPriorNode = PriorElem(plh, pRplcedNode);

    pNode->next = pPriorNode->next;
    pPriorNode->next = pNode;

    (plh->ListSize)++;
    return true;
}
コード例 #5
0
ファイル: luafile.cpp プロジェクト: MJavad/teeworlds
void CLuaFile::Tick()
{
    if (!g_Config.m_SvLua)
        return;

    ErrorFunc(m_pLua);
    MySQLTick(); //garbage collector -> clear old results that aren't fetched by lua
    m_pLuaShared->Tick();

    if (!FunctionExist("Tick"))
        return;

    FunctionPrepare("Tick");
    PushInteger((int)(time_get() * 1000 / time_freq()));
    PushInteger(m_pServer->Server()->Tick());
    FunctionExec();

	if (m_pServer->Server()->Tick() % (m_pServer->Server()->TickSpeed() * 60) == 0)
		dbg_msg("lua", "%i kiB", lua_gc(m_pLua, LUA_GCCOUNT, 0));

    lua_gc(m_pLua, LUA_GCCOLLECT, 1000);

    ErrorFunc(m_pLua);
}
コード例 #6
0
ファイル: luafile.cpp プロジェクト: MJavad/teeworlds
void CLuaFile::FunctionExec(const char *pFunctionName)
{
    if (m_pLua == 0)
        return;
    if (m_aFilename[0] == 0)
        return;

    if (pFunctionName)
    {
        if (FunctionExist(pFunctionName) == false)
            return;
        FunctionPrepare(pFunctionName);
    }
    if (lua_pcall(m_pLua, m_FunctionVarNum, LUA_MULTRET, 0))
        ErrorFunc(m_pLua);
    m_FunctionVarNum = 0;
}
コード例 #7
0
ファイル: luamap.cpp プロジェクト: Parhamic/teeworlds
int CLuaMapFile::FunctionExec(const char *pFunctionName)
{
    if (m_pLua == 0)
        return 0;

    if (pFunctionName)
    {
        if (FunctionExist(pFunctionName) == false)
            return 0;
        FunctionPrepare(pFunctionName);
    }
    int Ret = lua_pcall(m_pLua, m_FunctionVarNum, LUA_MULTRET, 0);
    if (Ret)
        ErrorFunc(m_pLua);
    m_FunctionVarNum = 0;
    return Ret;
}
コード例 #8
0
ファイル: luafile.cpp プロジェクト: MJavad/teeworlds
void CLuaFile::Init(const char *pFile)
{
    //close first
    Close();

    str_copy(m_aFilename, pFile, sizeof(m_aFilename));

    m_pLua = luaL_newstate();
	dbg_msg("lua", "%i kiB (loaded state)", lua_gc(m_pLua, LUA_GCCOUNT, 0));
    luaL_openlibs(m_pLua);
	dbg_msg("lua", "%i kiB (loaded libs)", lua_gc(m_pLua, LUA_GCCOUNT, 0));

    lua_atpanic(m_pLua, &Panic);

    //include
    lua_register(m_pLua, ToLower("Include"), this->Include);
    luaL_dostring(m_pLua, "package.path = \"./lua/?.lua;./lua/lib/?.lua\"\n");

    //config
    lua_register(m_pLua, ToLower("SetScriptUseSettingPage"), this->SetScriptUseSettingPage);
    lua_register(m_pLua, ToLower("SetScriptTitle"), this->SetScriptTitle);
    lua_register(m_pLua, ToLower("SetScriptInfo"), this->SetScriptInfo);

    //events
    lua_register(m_pLua, ToLower("AddEventListener"), this->AddEventListener);
    lua_register(m_pLua, ToLower("RemoveEventListener"), this->RemoveEventListener);

    //player
    lua_register(m_pLua, ToLower("GetPlayerIP"), this->GetPlayerIP);
    lua_register(m_pLua, ToLower("GetPlayerSpectateID"), this->GetPlayerSpectateID);
    lua_register(m_pLua, ToLower("GetPlayerName"), this->GetPlayerName);
    lua_register(m_pLua, ToLower("GetPlayerClan"), this->GetPlayerClan);
    lua_register(m_pLua, ToLower("GetPlayerCountry"), this->GetPlayerCountry);
    lua_register(m_pLua, ToLower("GetPlayerScore"), this->GetPlayerScore);
    lua_register(m_pLua, ToLower("GetPlayerPing"), this->GetPlayerPing);
    lua_register(m_pLua, ToLower("GetPlayerTeam"), this->GetPlayerTeam);
    lua_register(m_pLua, ToLower("GetPlayerSkin"), this->GetPlayerSkin);
    lua_register(m_pLua, ToLower("GetPlayerColorFeet"), this->GetPlayerColorFeet);
    lua_register(m_pLua, ToLower("GetPlayerColorBody"), this->GetPlayerColorBody);
    lua_register(m_pLua, ToLower("SetPlayerScore"), this->SetPlayerScore);
    lua_register(m_pLua, ToLower("SetPlayerName"), this->SetPlayerName);
    lua_register(m_pLua, ToLower("SetPlayerTeam"), this->SetPlayerTeam);
    lua_register(m_pLua, ToLower("SetPlayerClan"), this->SetPlayerClan);
    lua_register(m_pLua, ToLower("SetPlayerCountry"), this->SetPlayerCountry);
    lua_register(m_pLua, ToLower("SetPlayerSpectateID"), this->SetPlayerSpectateID);

    lua_register(m_pLua, ToLower("SetPlayerColorBody"), this->SetPlayerColorBody);
    lua_register(m_pLua, ToLower("SetPlayerColorFeet"), this->SetPlayerColorFeet);

    //character
    lua_register(m_pLua, ToLower("Emote"), this->Emote);
    lua_register(m_pLua, ToLower("GetCharacterPos"), this->GetCharacterPos);
    lua_register(m_pLua, ToLower("GetCharacterVel"), this->GetCharacterVel);
    lua_register(m_pLua, ToLower("SetCharacterPos"), this->SetCharacterPos);
    lua_register(m_pLua, ToLower("SetCharacterVel"), this->SetCharacterVel);

    //config
    lua_register(m_pLua, ToLower("GetConfigValue"), this->GetConfigValue);
    lua_register(m_pLua, ToLower("SetConfigValue"), this->SetConfigValue);

    //console
    lua_register(m_pLua, ToLower("Print"), this->Print);
    lua_register(m_pLua, ToLower("Console"), this->Console);

    //game
    lua_register(m_pLua, ToLower("GetGameType"), this->GetGameType);
    lua_register(m_pLua, ToLower("IsTeamplay"), this->IsTeamplay);

    //message
    //  lua_register(m_pLua, ToLower("GetNetError"), this->GetNetError);
    lua_register(m_pLua, ToLower("SendPacket"), this->SendPacket);
    lua_register(m_pLua, ToLower("AddModFile"), this->AddModFile);
    lua_register(m_pLua, ToLower("DeleteModFile"), this->DeleteModFile);
    lua_register(m_pLua, ToLower("SendFile"), this->SendFile);


    //collision
    lua_register(m_pLua, ToLower("IntersectLine"), this->IntersectLine);
    lua_register(m_pLua, ToLower("GetTile"), this->GetTile);
    lua_register(m_pLua, ToLower("SetTile"), this->SetTile);
    lua_register(m_pLua, ToLower("GetMapWidth"), this->GetMapWidth);
    lua_register(m_pLua, ToLower("GetMapHeight"), this->GetMapHeight);

    //Chat
    lua_register(m_pLua, ToLower("SendBroadcast"), this->SendBroadcast);
    lua_register(m_pLua, ToLower("SendChat"), this->SendChat);
    lua_register(m_pLua, ToLower("SendChatTarget"), this->SendChatTarget);

    //Entities
    lua_register(m_pLua, ToLower("EntityFind"), this->EntityFind);
    lua_register(m_pLua, ToLower("EntityGetCharacterId"), this->EntityGetCharacterId);
    lua_register(m_pLua, ToLower("EntityGetPos"), this->EntityGetPos);
    lua_register(m_pLua, ToLower("EntitySetPos"), this->EntitySetPos);
    lua_register(m_pLua, ToLower("EntityDestroy"), this->EntityDestroy);
    lua_register(m_pLua, ToLower("ProjectileFind"), this->ProjectileFind);
    lua_register(m_pLua, ToLower("ProjectileGetWeapon"), this->ProjectileGetWeapon);
    lua_register(m_pLua, ToLower("ProjectileGetOwner"), this->ProjectileGetOwner);
    lua_register(m_pLua, ToLower("ProjectileGetPos"), this->ProjectileGetPos);
    lua_register(m_pLua, ToLower("ProjectileGetDir"), this->ProjectileGetDir);
    lua_register(m_pLua, ToLower("ProjectileGetLifespan"), this->ProjectileGetLifespan);
    lua_register(m_pLua, ToLower("ProjectileGetExplosive"), this->ProjectileGetExplosive);
    lua_register(m_pLua, ToLower("ProjectileGetSoundImpact"), this->ProjectileGetSoundImpact);
    lua_register(m_pLua, ToLower("ProjectileGetStartTick"), this->ProjectileGetStartTick);
    lua_register(m_pLua, ToLower("ProjectileSetWeapon"), this->ProjectileSetWeapon);
    lua_register(m_pLua, ToLower("ProjectileSetOwner"), this->ProjectileSetOwner);
    lua_register(m_pLua, ToLower("ProjectileSetStartPos"), this->ProjectileSetStartPos);
    lua_register(m_pLua, ToLower("ProjectileSetDir"), this->ProjectileSetDir);
    lua_register(m_pLua, ToLower("ProjectileSetLifespan"), this->ProjectileSetLifespan);
    lua_register(m_pLua, ToLower("ProjectileSetExplosive"), this->ProjectileSetExplosive);
    lua_register(m_pLua, ToLower("ProjectileSetSoundImpact"), this->ProjectileSetSoundImpact);
    lua_register(m_pLua, ToLower("ProjectileSetStartTick"), this->ProjectileSetStartTick);
    lua_register(m_pLua, ToLower("ProjectileCreate"), this->ProjectileCreate);
    lua_register(m_pLua, ToLower("LaserCreate"), this->LaserCreate);


    //game
    lua_register(m_pLua, ToLower("CreateExplosion"), this->CreateExplosion);
    lua_register(m_pLua, ToLower("CreateDeath"), this->CreateDeath);
    lua_register(m_pLua, ToLower("CreateDamageIndicator"), this->CreateDamageIndicator);
    lua_register(m_pLua, ToLower("CreateHammerHit"), this->CreateHammerHit);
    lua_register(m_pLua, ToLower("CreateSound"), this->CreateSound);

    //tunings
    lua_register(m_pLua, ToLower("GetTuning"), this->GetTuning);
    lua_register(m_pLua, ToLower("SetTuning"), this->SetTuning);

    lua_register(m_pLua, ToLower("CharacterSetInputDirection"), this->CharacterSetInputDirection);
    lua_register(m_pLua, ToLower("CharacterSetInputJump"), this->CharacterSetInputJump);
    lua_register(m_pLua, ToLower("CharacterSetInputWeapon"), this->CharacterSetInputWeapon);
    lua_register(m_pLua, ToLower("CharacterSetInputTarget"), this->CharacterSetInputTarget);
    lua_register(m_pLua, ToLower("CharacterSetInputHook"), this->CharacterSetInputHook);
    lua_register(m_pLua, ToLower("CharacterSetInputFire"), this->CharacterSetInputFire);
    lua_register(m_pLua, ToLower("CharacterGetCoreJumped"), this->CharacterGetCoreJumped);
    lua_register(m_pLua, ToLower("CharacterSpawn"), this->CharacterSpawn);
    lua_register(m_pLua, ToLower("CharacterIsAlive"), this->CharacterIsAlive);
    lua_register(m_pLua, ToLower("CharacterKill"), this->CharacterKill);
    lua_register(m_pLua, ToLower("CharacterIsGrounded"), this->CharacterIsGrounded);
    lua_register(m_pLua, ToLower("CharacterIncreaseHealth"), this->CharacterIncreaseHealth);
    lua_register(m_pLua, ToLower("CharacterIncreaseArmor"), this->CharacterIncreaseArmor);
    lua_register(m_pLua, ToLower("CharacterSetAmmo"), this->CharacterSetAmmo);
    lua_register(m_pLua, ToLower("CharacterGetAmmo"), this->CharacterGetAmmo);
    lua_register(m_pLua, ToLower("CharacterGetInputTarget"), this->CharacterGetInputTarget);
    lua_register(m_pLua, ToLower("CharacterGetActiveWeapon"), this->CharacterGetActiveWeapon);
    lua_register(m_pLua, ToLower("CharacterSetActiveWeapon"), this->CharacterSetActiveWeapon);
    lua_register(m_pLua, ToLower("CharacterDirectInput"), this->CharacterDirectInput);
    lua_register(m_pLua, ToLower("CharacterPredictedInput"), this->CharacterPredictedInput);
    lua_register(m_pLua, ToLower("CharacterGetHealth"), this->CharacterGetHealth);
    lua_register(m_pLua, ToLower("CharacterGetArmor"), this->CharacterGetArmor);
    lua_register(m_pLua, ToLower("CharacterSetHealth"), this->CharacterSetHealth);
    lua_register(m_pLua, ToLower("CharacterSetArmor"), this->CharacterSetArmor);
    lua_register(m_pLua, ToLower("CharacterTakeDamage"), this->CharacterTakeDamage);

    lua_register(m_pLua, ToLower("SendCharacterInfo"), this->SendCharacterInfo);

    lua_register(m_pLua, ToLower("SetAutoRespawn"), this->SetAutoRespawn);

    lua_register(m_pLua, ToLower("Win"), this->Win);
    lua_register(m_pLua, ToLower("SetGametype"), this->SetGametype);

    lua_register(m_pLua, ToLower("DummyCreate"), this->DummyCreate);
    lua_register(m_pLua, ToLower("IsDummy"), this->IsDummy);

    //version
    lua_register(m_pLua, ToLower("CheckVersion"), this->CheckVersion);
    lua_register(m_pLua, ToLower("GetVersion"), this->GetVersion);

    lua_register(m_pLua, ToLower("CreateDirectory"), this->CreateDirectory);
    lua_register(m_pLua, ToLower("GetDate"), this->GetDate);

    lua_register(m_pLua, ToLower("GetTick"), this->GetTick);
    lua_register(m_pLua, ToLower("GetTickSpeed"), this->GetTickSpeed);

    //MySQL - Yeah
    lua_register(m_pLua, ToLower("MySQLConnect"), this->MySQLConnect);
    lua_register(m_pLua, ToLower("MySQLEscapeString"), this->MySQLEscapeString);
    lua_register(m_pLua, ToLower("MySQLSelectDatabase"), this->MySQLSelectDatabase);
    lua_register(m_pLua, ToLower("MySQLIsConnected"), this->MySQLIsConnected);
    lua_register(m_pLua, ToLower("MySQLQuery"), this->MySQLQuery);
    lua_register(m_pLua, ToLower("MySQLClose"), this->MySQLClose);
    lua_register(m_pLua, ToLower("MySQLFetchResults"), this->MySQLFetchResults);

    m_pLuaShared = new CLuaShared<CLuaFile>(this);

    lua_pushlightuserdata(m_pLua, this);
    lua_setglobal(m_pLua, "pLUA");

    lua_register(m_pLua, ToLower("errorfunc"), this->ErrorFunc);

	dbg_msg("lua", "%i kiB (loaded fx)", lua_gc(m_pLua, LUA_GCCOUNT, 0));
    if (luaL_loadfile(m_pLua, m_aFilename) == 0)
    {
        lua_pcall(m_pLua, 0, LUA_MULTRET, 0);
        ErrorFunc(m_pLua);
		dbg_msg("lua", "%i kiB (loaded file)", lua_gc(m_pLua, LUA_GCCOUNT, 0));
    }
    else
    {
        ErrorFunc(m_pLua);
        dbg_msg("lua", "fail to load file: %s", pFile);
        Close();
        return;
    }
}
コード例 #9
0
// Private methods
void SerialHandler::ProcessCommand(){
	if(Buffer[0] < FunctionBufferLenght){
	void (*H_FuncPtr)(uint8_t[]) = intFunc[Buffer[0]];
	H_FuncPtr(Buffer);
	} else ErrorFunc(Buffer);
}
コード例 #10
0
ファイル: image_sphere.cpp プロジェクト: PeterZhouSZ/hyperion
bit ImageOfSphere::Run(time::Progress * prog)
{
 prog->Push();

 // Create an array of rays, calculated from the pixel positions...
  prog->Report(0,3);
  // Get the cameras centre...
   bs::Vert camCent;
   math::Vect<4,real64> camCentHomo;
   cf.camera.Centre(camCentHomo);
   camCentHomo /= camCentHomo[3];
   for (nat32 i=0;i<3;i++) camCent[i] = camCentHomo[i];
   
   
  // Get the coordinate to 'point on ray' conversion matrix...
   math::Mat<4,3,real64> p2r;
   cf.camera.GetInverse(p2r);
   p2r /= math::FrobNorm(p2r);
   
  // Get the cameras direction...
   math::Vect<3,real64> camDir;
   cf.camera.Dir(camDir);
   LogDebug("camDir" << LogDiv() << camDir);
   
  // Actual construction and filling in...
   ErrData ed;
   ed.radius = radius;
   ed.ray.Size(edge.Size());
   ds::List<bs::Pnt>::Cursor targ = edge.FrontPtr();
   for (nat32 i=0;i<ed.ray.Size();i++)
   {
    cf.GetRay((*targ)[0],(*targ)[1],ed.ray[i],&camCentHomo,&p2r,&camDir);
    
    LogDebug("ray {i,start,dir}" << LogDiv() << i << LogDiv() << ed.ray[i].s << LogDiv() << ed.ray[i].n);
   
    ++targ;
   }


 // Initialisation is, as always, the hard bit...
 // We use a scheme of selecting a bunch of random ray triplets, from each 
 // triplet calculating the exact fit and then finding its error - we ultimatly
 // select the lowest error result...
 // (This is a bit like ransac, but without a rigourous stopping criterion.)
  prog->Report(1,3);
  real32 lowestError = math::Infinity<real32>();
  data::Random rand;
  for (nat32 i=0;i<ed.ray.Size()-2;i++)
  {
   // Select 3 rays at random, without duplication...
    nat32 indA = rand.Int(0,ed.ray.Size()-1);
    nat32 indB = rand.Int(0,ed.ray.Size()-2);
    nat32 indC = rand.Int(0,ed.ray.Size()-3);
    if (indB>=indA) ++indB;
    if (indC>=math::Min(indA,indB)) ++indC;
    if (indC>=math::Max(indA,indB)) ++indC;
  
   // Find the associated centre...
    bs::Vert cent;
    SphereFromRays(radius,ed.ray[indA].s,ed.ray[indA].n,ed.ray[indB].n,ed.ray[indC].n,cent);
   
   // Find the error...
    math::Vect<1> err;
    ErrorFunc(cent,err,ed);
   
   // If the best keep it...
    if (math::IsFinite(err[0])&&(err[0]<lowestError))
    {
     centre = cent;
     lowestError = err[0];
    }
  }
  
  if (!math::IsFinite(lowestError))
  {
   prog->Pop();
   return false;
  }


 // Optimisation time - just invoke LM...
  prog->Report(2,3);
  
  math::LM(centre,ed,&ErrorFunc);
  
 
 prog->Pop();
 return true;
}