Beispiel #1
0
        private void RenderObject(LatipiumObject obj, Com.Latipium.Core.Tuple <object, object> data, IObjectRenderer objectR, IColorRenderer colorR)
        {
            Com.Latipium.Core.Tuple <float, float, float> position = obj.InvokeFunction <Com.Latipium.Core.Tuple <float, float, float>, Com.Latipium.Core.Tuple <float, float, float> >("Position", null);
            float[] transform = obj.InvokeFunction <float[], float[]>("Transform", null);
            if (position != null)
            {
                GL.Translate(position.Object1, position.Object2, position.Object3);
            }
            if (transform != null)
            {
                GL.MultMatrix(transform);
            }
            int len = objectR.Start(data.Object1);

            if (colorR == null)
            {
                for (int i = 0; i < len; ++i)
                {
                    objectR.Vertex(i);
                }
            }
            else
            {
                colorR.Start(data.Object2);
                for (int i = 0; i < len; ++i)
                {
                    colorR.Color(i);
                    objectR.Vertex(i);
                }
            }
            objectR.End();
        }
Beispiel #2
0
 internal void AddObjects(IEnumerable <LatipiumObject> objects)
 {
     foreach (LatipiumObject obj in objects)
     {
         LatipiumObject type = obj.InvokeFunction <LatipiumObject>("Type");
         if (type != null)
         {
             if (!InitializedTypes.Contains(type))
             {
                 type.InvokeProcedure <Action <IEnumerable <LatipiumObject> > >("Initialize", UpdatedCallback);
             }
             Com.Latipium.Core.Tuple <float[], int[]> data = type.InvokeFunction <Com.Latipium.Core.Tuple <float[], int[]> >("GetPhysicsData");
             if (data != null && data.Object1 != null && data.Object2 != null)
             {
                 List <JVector> points             = new List <JVector>();
                 List <TriangleVertexIndices> tris = new List <TriangleVertexIndices>();
                 for (int i = 0; i < data.Object1.Length - 2; i += 3)
                 {
                     points.Add(new JVector(data.Object1[i], data.Object1[i + 1], data.Object1[i + 2]));
                 }
                 for (int i = 0; i < data.Object2.Length - 2; i += 3)
                 {
                     tris.Add(new TriangleVertexIndices(data.Object2[i], data.Object2[i + 1], data.Object2[i + 2]));
                 }
                 Octree      octree     = new Octree(points, tris);
                 Shape       shape      = new TriangleMeshShape(octree);
                 RigidBody   body       = new RigidBody(shape);
                 Func <bool> UseGravity = type.GetFunction <bool>("UseGravity");
                 body.AffectedByGravity = UseGravity == null || UseGravity();
                 Bodies.Add(obj, body);
                 World.AddBody(body);
             }
         }
     }
 }
Beispiel #3
0
        public void Added(LatipiumObject realm)
        {
            PhysicsSystem system = new PhysicsSystem();
            IEnumerable <LatipiumObject> objs = realm.InvokeFunction <IEnumerable <LatipiumObject> >("GetObjects");

            if (objs != null)
            {
                system.AddObjects(objs);
            }
            Systems.Add(realm, system);
            if (RealmAdded != null)
            {
                RealmAdded(realm);
            }
        }
        public void Start()
        {
            LatipiumModule auth     = ModuleFactory.FindModule("Com.Latipium.Modules.Authentication");
            LatipiumModule graphics = ModuleFactory.FindModule("Com.Latipium.Modules.Graphics");
            LatipiumModule physics  = ModuleFactory.FindModule("Com.Latipium.Modules.Physics");
            LatipiumModule player   = ModuleFactory.FindModule("Com.Latipium.Modules.Player");
            LatipiumModule worldGen = ModuleFactory.FindModule("Com.Latipium.Modules.World.Generator");
            LatipiumModule worldSer = ModuleFactory.FindModule("Com.Latipium.Modules.World.Serialization");

            if (graphics == null)
            {
                Log.Error("Unable to find graphics module");
            }
            else
            {
                string         name  = null;
                LatipiumObject world = null;
                if (worldGen != null || worldSer != null)
                {
                    if (auth == null)
                    {
                        name = "Player";
                    }
                    else
                    {
                        name = auth.InvokeFunction <string>("GetUsername");
                    }
                    if (worldSer != null)
                    {
                        world = worldSer.InvokeFunction <LatipiumObject>("Load");
                    }
                    if (world == null && worldGen != null)
                    {
                        world = worldGen.InvokeFunction <LatipiumObject>("Generate");
                    }
                }
                LatipiumObject p = null;
                if (world != null)
                {
                    p = world.InvokeFunction <string, LatipiumObject>("GetPlayer", name);
                    if (player != null && p != null)
                    {
                        player.InvokeProcedure <LatipiumObject>("HandleFor", p);
                    }
                }
                Thread physicsThread = null;
                Thread parent        = null;
                if (physics != null)
                {
                    physicsThread = new Thread(() => {
                        physics.InvokeProcedure("Initialize");
                        if (world != null)
                        {
                            physics.InvokeProcedure <LatipiumObject>("LoadWorld", world);
                        }
                        try {
                            physics.InvokeProcedure("Loop");
                        } catch (ThreadInterruptedException) {
                        } finally {
                            physics.InvokeProcedure("Destroy");
                            if (parent != null)
                            {
                                parent.Interrupt();
                            }
                        }
                    });
                    physicsThread.Start();
                }
                graphics.InvokeProcedure("Initialize");
                if (world != null)
                {
                    graphics.InvokeProcedure <LatipiumObject>("LoadWorld", world);
                    if (p != null)
                    {
                        graphics.InvokeProcedure <LatipiumObject>("SetPlayer", p);
                    }
                }
                try {
                    graphics.InvokeProcedure("Loop");
                } finally {
                    graphics.InvokeProcedure("Destroy");
                    if (physicsThread != null)
                    {
                        parent = Thread.CurrentThread;
                        physicsThread.Interrupt();
                        try {
                            Thread.Sleep(int.MaxValue);
                        } catch (ThreadInterruptedException) {
                        }
                    }
                    if (world != null && worldSer != null)
                    {
                        worldSer.InvokeProcedure <LatipiumObject>("Save", world);
                    }
                }
            }
        }
Beispiel #5
0
        public void Loop()
        {
            int update = Environment.TickCount;

            while (true)
            {
                float time = Environment.TickCount - update;
                update = Environment.TickCount;
                Dictionary <LatipiumObject, List <LatipiumObject> > objects = new Dictionary <LatipiumObject, List <LatipiumObject> >();
                foreach (LatipiumObject realm in GetRealms())
                {
                    objects.Clear();
                    List <LatipiumObject> additions;
                    if (Additions.ContainsKey(realm))
                    {
                        additions = Additions[realm];
                    }
                    else
                    {
                        additions        = new List <LatipiumObject>();
                        Additions[realm] = additions;
                    }
                    List <LatipiumObject> removals;
                    if (Removals.ContainsKey(realm))
                    {
                        removals = Removals[realm];
                    }
                    else
                    {
                        removals        = new List <LatipiumObject>();
                        Removals[realm] = removals;
                    }
                    foreach (LatipiumObject obj in realm.InvokeFunction <IEnumerable <LatipiumObject> >("GetObjects"))
                    {
                        LatipiumObject        type = obj.InvokeFunction <LatipiumObject>("Type");
                        List <LatipiumObject> list;
                        if (objects.ContainsKey(type))
                        {
                            list = objects[type];
                        }
                        else
                        {
                            list          = new List <LatipiumObject>();
                            objects[type] = list;
                        }
                        list.Add(obj);
                    }
                    foreach (LatipiumObject type in objects.Keys)
                    {
                        Com.Latipium.Core.Tuple <IEnumerable <LatipiumObject>, IEnumerable <LatipiumObject> > changes = type.InvokeFunction <IEnumerable <LatipiumObject>, Com.Latipium.Core.Tuple <IEnumerable <LatipiumObject>, IEnumerable <LatipiumObject> > >("PhysicsUpdate", objects[type]);
                        if (changes != null)
                        {
                            lock ( ListLock ) {
                                if (changes.Object1 != null)
                                {
                                    additions.AddRange(changes.Object1);
                                }
                                if (changes.Object2 != null)
                                {
                                    removals.AddRange(changes.Object2);
                                }
                            }
                        }
                    }
                    Systems[realm].Step(time);
                }
            }
        }
        public void Start()
        {
            LatipiumModule auth     = ModuleFactory.FindModule("Com.Latipium.Modules.Authentication");
            LatipiumModule graphics = ModuleFactory.FindModule("Com.Latipium.Modules.Graphics");
            LatipiumModule network  = ModuleFactory.FindModule("Com.Latipium.Modules.Network");
            LatipiumModule player   = ModuleFactory.FindModule("Com.Latipium.Modules.Player");
            LatipiumModule world    = ModuleFactory.FindModule("Com.Latipium.Modules.World");

            if (graphics == null)
            {
                Log.Error("Unable to find graphics module");
            }
            else
            {
                string         name = null;
                LatipiumObject w    = null;
                if (world != null)
                {
                    if (auth == null)
                    {
                        name = "Player";
                    }
                    else
                    {
                        name = auth.InvokeFunction <string>("GetUsername");
                    }
                    w = world.InvokeFunction <LatipiumObject>("CreateWorld");
                }
                Thread networkThread = null;
                if (network != null)
                {
                    Thread parent = Thread.CurrentThread;
                    networkThread = new Thread(() => {
                        network.InvokeProcedure("InitializeClient");
                        if (world != null)
                        {
                            network.InvokeProcedure <LatipiumObject>("LoadWorld", w);
                        }
                        parent.Interrupt();
                        try {
                            network.InvokeProcedure("Loop");
                        } catch (ThreadInterruptedException) {
                        } finally {
                            network.InvokeProcedure("Destroy");
                        }
                    });
                    networkThread.Start();
                    try {
                        // Will be interrupted when the network loads
                        Thread.Sleep(int.MaxValue);
                    } catch (ThreadInterruptedException) {
                    }
                }
                LatipiumObject p = null;
                if (w != null)
                {
                    p = w.InvokeFunction <string, LatipiumObject>("GetPlayer", name);
                    if (player != null && p != null)
                    {
                        player.InvokeProcedure <LatipiumObject>("HandleFor", p);
                    }
                }
                graphics.InvokeProcedure("Initialize");
                if (world != null)
                {
                    graphics.InvokeProcedure <LatipiumObject>("LoadWorld", w);
                    if (p != null)
                    {
                        graphics.InvokeProcedure <LatipiumObject>("SetPlayer", p);
                    }
                }
                try {
                    graphics.InvokeProcedure("Loop");
                } finally {
                    graphics.InvokeProcedure("Destroy");
                    if (networkThread != null)
                    {
                        networkThread.Interrupt();
                    }
                }
            }
        }