コード例 #1
0
int DestClick(points places[20])
{
	
	
	while(true)
	{
		Text td(250,400,"Please click on the destination position (click on the green nodes only.)");
		
		int pos = getClick();//position of the first click is recorded
		td.hide();
		int X = pos/65536;
		int Y = pos%65536;int t=100;
		
		for(int i=0; i<20; i++)
		{
			if((X<=places[i].x+4&&X>=places[i].x-4)&&(Y<=places[i].y+4&&Y>=places[i].y-4))
			t =i;
			
		}
		if(t!=100)
		{
			return t;
			break;
		}
		else
		{
			Text td1(300,400,"Invalid Position. Reloading ...");
			td1.show();
			wait(2);
			td1.hide();
		}
	}
	
	
}
コード例 #2
0
ファイル: ab.c プロジェクト: dbremner/retrocomputing
ex_drop()
{
	int i, k, o;

	o = 0;
	td1(1);
	for(i=0; i<idx.rank; i++) {
		k = idx.idx[i];
		if(k > 0) o += idx.del[i] * k;
		else k = -k;
		idx.dim[i] -= k;
	}
	map(o);
}
コード例 #3
0
ファイル: mytritri.cpp プロジェクト: qroph/motion-solver
__CD__BEGIN

Vector3D my_tri_tri_intersect(const Triangle& t1, const Triangle& t2)
{
    Plane p1(t1.v1,t1.v2,t1.v3);
    int other_side=0;
    {
        float f1=p1.Classify(t2.v1);
        float f2=p1.Classify(t2.v2);
        float f3=p1.Classify(t2.v3);
        float f12=f1*f2;
        float f23=f2*f3;
        if (f12>0.0f && f23>0.0f) return Vector3D::Zero;
        other_side=(f12<0.0f?(f23<0.0f?1:0):2);
    }
    Plane p2(t2.v1,t2.v2,t2.v3);
    Vector3D n12(p1.normal+p2.normal);
    TriangleDesc td2(t2,p2);
    const Vector3D& a2=td2[other_side+1];
    const Vector3D& b2=td2[other_side];
    const Vector3D& c2=td2[other_side+2];
    float t21=-(p1.d+p2.d+a2*n12)/((b2-a2)*n12);
    TriangleDesc td1(t1,p1);
    Vector3D P21(a2+t21*(b2-a2));
    if (td1.pointInTri(P21)) return P21;
    float t22=-(p1.d+p2.d+c2*n12)/((b2-c2)*n12);
    Vector3D P22(c2+t22*(b2-c2));
    if (td1.pointInTri(P22)) return P22;

    {
        float f1=p2.Classify(t1.v1);
        float f2=p2.Classify(t1.v2);
        float f3=p2.Classify(t1.v3);
        float f12=f1*f2;
        float f23=f2*f3;
        if (f12>0.0f && f23>0.0f) return Vector3D::Zero;
        other_side=(f12<0.0f?(f23<0.0f?1:0):2);
    }
    const Vector3D& a1=td1[other_side+1];
    const Vector3D& b1=td1[other_side];
    const Vector3D& c1=td1[other_side+2];
    float t11=-(p1.d+p2.d+a1*n12)/((b1-a1)*n12);
    Vector3D P11(a1+t11*(b1-a1));
    if (td2.pointInTri(P11)) return P11;
    float t12=-(p1.d+p2.d+c1*n12)/((b1-c1)*n12);
    Vector3D P12(c1+t12*(b1-c1));
    if (td2.pointInTri(P12)) return P12;
    return Vector3D::Zero;
}
コード例 #4
0
ファイル: ab.c プロジェクト: dbremner/retrocomputing
ex_take()
{
	int takezr();
	int i, k, o, fill[MRANK], fflg;

	/* While TANSTAAFL, in APL there is a close approximation.  It
	 * is possible to perform a "take" of more elements than an
	 * array actually contains (to be padded with zeros or blanks).
	 * If "td1()" detects that a dimension exceeds what the array
	 * actually contains it will return 1.  Special code is then
	 * required to force the extra elements in the new array to
	 * zero or blank.  This code is supposed to work for null items
	 * also, but it doesn't.
	 */

	o = 0;
	fflg = td1(0);
	for(i=0; i<idx.rank; i++) {
		fill[i] = 0;
		k = idx.idx[i];
		if(k < 0) {
			k = -k;
			if (k > idx.dim[i]) fill[i] = idx.dim[i] - k;
			o += idx.del[i] * (idx.dim[i] - k);
		}
		else {
			if (k > idx.dim[i]) fill[i] = idx.dim[i];
		}
		idx.dim[i] = k;
	}
	map(o);

	if (fflg){
		bidx(sp[-1]);
		forloop(takezr, fill);
	}
}
コード例 #5
0
ファイル: Master.cpp プロジェクト: Trizzor/uecore
/// Main function
int Master::Run()
{
    /// worldd PID file creation
    std::string pidfile = sConfig.GetStringDefault("PidFile", "");
    if(!pidfile.empty())
    {
        uint32 pid = CreatePIDFile(pidfile);
        if( !pid )
        {
            sLog.outError( "Cannot create PID file %s.\n", pidfile.c_str() );
            return 1;
        }

        sLog.outString( "Daemon PID: %u\n", pid );
    }

    ///- Start the databases
    if (!_StartDB())
        return 1;

    ///- Initialize the World
    sWorld.SetInitialWorldSettings();

    ///- Catch termination signals
    _HookSignals();

    ///- Launch WorldRunnable thread
    ACE_Based::Thread t(*new WorldRunnable);
    t.setPriority(ACE_Based::Highest);

    // set server online
    loginDatabase.PExecute("UPDATE realmlist SET color = 0, population = 0 WHERE id = '%d'",realmID);

#ifdef WIN32
    if (sConfig.GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/)
#else
    if (sConfig.GetBoolDefault("Console.Enable", true))
#endif
    {
        ///- Launch CliRunnable thread
        ACE_Based::Thread td1(*new CliRunnable);
    }

    ACE_Based::Thread td2(*new RARunnable);

    ///- Handle affinity for multiple processors and process priority on Windows
    #ifdef WIN32
    {
        HANDLE hProcess = GetCurrentProcess();

        uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
        if(Aff > 0)
        {
            ULONG_PTR appAff;
            ULONG_PTR sysAff;

            if(GetProcessAffinityMask(hProcess,&appAff,&sysAff))
            {
                ULONG_PTR curAff = Aff & appAff;            // remove non accessible processors

                if(!curAff )
                {
                    sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for mangosd. Accessible processors bitmask (hex): %x",Aff,appAff);
                }
                else
                {
                    if(SetProcessAffinityMask(hProcess,curAff))
                        sLog.outString("Using processors (bitmask, hex): %x", curAff);
                    else
                        sLog.outError("Can't set used processors (hex): %x",curAff);
                }
            }
            sLog.outString();
        }

        bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);

//        if(Prio && (m_ServiceStatus == -1)/* need set to default process priority class in service mode*/)
        if(Prio)
        {
            if(SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS))
                sLog.outString("mangosd process priority class set to HIGH");
            else
                sLog.outError("ERROR: Can't set mangosd process priority class.");
            sLog.outString();
        }
    }
    #endif

    uint32 realCurrTime, realPrevTime;
    realCurrTime = realPrevTime = getMSTime();

    uint32 socketSelecttime = sWorld.getConfig(CONFIG_SOCKET_SELECTTIME);

    // maximum counter for next ping
    uint32 numLoops = (sConfig.GetIntDefault( "MaxPingTime", 30 ) * (MINUTE * 1000000 / socketSelecttime));
    uint32 loopCounter = 0;

    ///- Start up freeze catcher thread
    uint32 freeze_delay = sConfig.GetIntDefault("MaxCoreStuckTime", 0);
    if(freeze_delay)
    {
        FreezeDetectorRunnable *fdr = new FreezeDetectorRunnable();
        fdr->SetDelayTime(freeze_delay*1000);
        ACE_Based::Thread t(*fdr);
        t.setPriority(ACE_Based::Highest);
    }

    ///- Launch the world listener socket
    port_t wsport = sWorld.getConfig (CONFIG_PORT_WORLD);
    std::string bind_ip = sConfig.GetStringDefault ("BindIP", "0.0.0.0");

    if (sWorldSocketMgr->StartNetwork (wsport, bind_ip.c_str ()) == -1)
    {
        sLog.outError ("Failed to start network");
        World::StopNow(ERROR_EXIT_CODE);
        // go down and shutdown the server
    }

    sWorldSocketMgr->Wait ();

    // set server offline
    loginDatabase.PExecute("UPDATE realmlist SET color = 2 WHERE id = '%d'",realmID);

    ///- Remove signal handling before leaving
    _UnhookSignals();

    // when the main thread closes the singletons get unloaded
    // since worldrunnable uses them, it will crash if unloaded after master
    t.wait();
    td2.wait ();

    ///- Clean database before leaving
    clearOnlineAccounts();

    ///- Wait for delay threads to end
    CharacterDatabase.HaltDelayThread();
    WorldDatabase.HaltDelayThread();
    loginDatabase.HaltDelayThread();

    sLog.outString( "Halting process..." );

    #ifdef WIN32
    if (sConfig.GetBoolDefault("Console.Enable", true))
    {
        // this only way to terminate CLI thread exist at Win32 (alt. way exist only in Windows Vista API)
        //_exit(1);
        // send keyboard input to safely unblock the CLI thread
        INPUT_RECORD b[5];
        HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
        b[0].EventType = KEY_EVENT;
        b[0].Event.KeyEvent.bKeyDown = TRUE;
        b[0].Event.KeyEvent.uChar.AsciiChar = 'X';
        b[0].Event.KeyEvent.wVirtualKeyCode = 'X';
        b[0].Event.KeyEvent.wRepeatCount = 1;

        b[1].EventType = KEY_EVENT;
        b[1].Event.KeyEvent.bKeyDown = FALSE;
        b[1].Event.KeyEvent.uChar.AsciiChar = 'X';
        b[1].Event.KeyEvent.wVirtualKeyCode = 'X';
        b[1].Event.KeyEvent.wRepeatCount = 1;

        b[2].EventType = KEY_EVENT;
        b[2].Event.KeyEvent.bKeyDown = TRUE;
        b[2].Event.KeyEvent.dwControlKeyState = 0;
        b[2].Event.KeyEvent.uChar.AsciiChar = '\r';
        b[2].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
        b[2].Event.KeyEvent.wRepeatCount = 1;
        b[2].Event.KeyEvent.wVirtualScanCode = 0x1c;

        b[3].EventType = KEY_EVENT;
        b[3].Event.KeyEvent.bKeyDown = FALSE;
        b[3].Event.KeyEvent.dwControlKeyState = 0;
        b[3].Event.KeyEvent.uChar.AsciiChar = '\r';
        b[3].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
        b[3].Event.KeyEvent.wVirtualScanCode = 0x1c;
        b[3].Event.KeyEvent.wRepeatCount = 1;
        DWORD numb;
        BOOL ret = WriteConsoleInput(hStdIn, b, 4, &numb);
    }
    #endif

    // for some unknown reason, unloading scripts here and not in worldrunnable
    // fixes a memory leak related to detaching threads from the module
    UnloadScriptingModule();

    // Exit the process with specified return value
    return World::GetExitCode();
}
コード例 #6
0
ファイル: Master.cpp プロジェクト: Artea/mangos-svn
bool Master::Run()
{
    sLog.outString( "MaNGOS daemon %s", _FULLVERSION );
    sLog.outString( "<Ctrl-C> to stop.\n\n" );

    sLog.outTitle( "MM   MM         MM   MM  MMMMM   MMMM   MMMMM");
    sLog.outTitle( "MM   MM         MM   MM MMM MMM MM  MM MMM MMM");
    sLog.outTitle( "MMM MMM         MMM  MM MMM MMM MM  MM MMM");
    sLog.outTitle( "MM M MM         MMMM MM MMM     MM  MM  MMM");
    sLog.outTitle( "MM M MM  MMMMM  MM MMMM MMM     MM  MM   MMM");
    sLog.outTitle( "MM M MM M   MMM MM  MMM MMMMMMM MM  MM    MMM");
    sLog.outTitle( "MM   MM     MMM MM   MM MM  MMM MM  MM     MMM");
    sLog.outTitle( "MM   MM MMMMMMM MM   MM MMM MMM MM  MM MMM MMM");
    sLog.outTitle( "MM   MM MM  MMM MM   MM  MMMMMM  MMMM   MMMMM");
    sLog.outTitle( "        MM  MMM http://www.mangosproject.org");
    sLog.outTitle( "        MMMMMM\n\n");

    _StartDB();

    //loglevel = (uint8)sConfig.GetIntDefault("LogLevel", DEFAULT_LOG_LEVEL);

    sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
    sWorld.SetMotd( sConfig.GetStringDefault("Motd", "Welcome to the Massive Network Game Object Server." ).c_str() );
    sWorld.SetInitialWorldSettings();

    port_t wsport, rmport;
    rmport = sWorld.getConfig(CONFIG_PORT_REALM);           //sConfig.GetIntDefault( "RealmServerPort", DEFAULT_REALMSERVER_PORT );
    wsport = sWorld.getConfig(CONFIG_PORT_WORLD);           //sConfig.GetIntDefault( "WorldServerPort", DEFAULT_WORLDSERVER_PORT );

    uint32 socketSelecttime;
                                                            //sConfig.GetIntDefault( "SocketSelectTime", DEFAULT_SOCKET_SELECT_TIME );
    socketSelecttime = sWorld.getConfig(CONFIG_SOCKET_SELECTTIME);

    //uint32 grid_clean_up_delay = sConfig.GetIntDefault("GridCleanUpDelay", 300);
    //sLog.outDebug("Setting Grid clean up delay to %d seconds.", grid_clean_up_delay);
    //grid_clean_up_delay *= 1000;
    //MapManager::Instance().SetGridCleanUpDelay(grid_clean_up_delay);

    //uint32 map_update_interval = sConfig.GetIntDefault("MapUpdateInterval", 100);
    //sLog.outDebug("Setting map update interval to %d milli-seconds.", map_update_interval);
    //MapManager::Instance().SetMapUpdateInterval(map_update_interval);

    //    sRealmList.setServerPort(wsport);
    //    sRealmList.GetAndAddRealms ();
    SocketHandler h;
    ListenSocket<WorldSocket> worldListenSocket(h);
    //    ListenSocket<AuthSocket> authListenSocket(h);

    if (worldListenSocket.Bind(wsport))
    {
        _StopDB();
        sLog.outString( "MaNGOS can not bind to that port" );
        exit(1);
    }

    h.Add(&worldListenSocket);
    //    h.Add(&authListenSocket);

    _HookSignals();

    ZThread::Thread t(new WorldRunnable);

    //#ifndef WIN32
    t.setPriority ((ZThread::Priority )2);
    //#endif

    #ifdef ENABLE_CLI
    ZThread::Thread td1(new CliRunnable);
    #endif

    #ifdef ENABLE_RA

    ListenSocket<RASocket> RAListenSocket(h);

    if (RAListenSocket.Bind(sConfig.GetIntDefault( "RA.Port", 3443 )))
    {

        sLog.outString( "MaNGOS can not bind to that port" );
        // exit(1); go on with no RA

    }

    h.Add(&RAListenSocket);
    #endif

    #ifdef WIN32
    {
        HANDLE hProcess = GetCurrentProcess();

        uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
        if(Aff > 0)
        {
            uint32 appAff;
            uint32 sysAff;

            if(GetProcessAffinityMask(hProcess,&appAff,&sysAff))
            {
                uint32 curAff = Aff & appAff;               // remove non accassable processors

                if(!curAff )
                {
                    sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessable for mangosd. Accessable processors bitmask (hex): %x",Aff,appAff);
                }
                else
                {
                    if(SetProcessAffinityMask(hProcess,curAff))
                        sLog.outString("Using processors (bitmask, hex): %x", curAff);
                    else
                        sLog.outError("Can't set used processors (hex): %x",curAff);
                }
            }
            sLog.outString("");
        }

        uint32 Prio = sConfig.GetIntDefault("ProcessPriority", 0);

        if(Prio)
        {
            if(SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS))
                sLog.outString("mangosd process priority class set to HIGH");
            else
                sLog.outError("ERROR: Can't set mangosd process priority class.");
            sLog.outString("");
        }
    }
    #endif

    uint32 realCurrTime, realPrevTime;
    realCurrTime = realPrevTime = getMSTime();
    while (!World::m_stopEvent)
    {

        if (realPrevTime > realCurrTime)
            realPrevTime = 0;

        realCurrTime = getMSTime();
        sWorldSocketMgr.Update( realCurrTime - realPrevTime );
        realPrevTime = realCurrTime;

        //h.Select(0, 100000);
        h.Select(0, socketSelecttime);
    }

    sLog.outString( "WORLD: Saving Addons" );
    sAddOnHandler._SaveToDB();

    _UnhookSignals();

    t.wait();

    _StopDB();

    sLog.outString( "Halting process..." );

    return 0;
}