| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using AtomicPlayer;
- namespace AtomicEngine
- {
- public static class Atomic
- {
- [DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
- private static extern int atomicsharp_initialize ();
- [DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
- private static extern bool atomicsharp_runframe ();
- [DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
- private static extern IntPtr csb_AtomicEngine_GetSubsystem(string name);
-
- static Atomic()
- {
- try {
- Initialize ();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- throw;
- }
- }
- public static void Run()
- {
-
- while (Atomic.RunFrame ()) {
- }
- }
- public static bool RunFrame()
- {
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
- NativeCore.ReleaseExpiredNativeReferences ();
- return atomicsharp_runframe ();
- }
- public static void RegisterAssemblyComponents(Assembly assembly)
- {
- ComponentCore.RegisterAssemblyComponents (assembly);
- }
- public static void Initialize()
- {
- ContainerModule.Initialize ();
- CoreModule.Initialize ();
- IOModule.Initialize ();
- ResourceModule.Initialize ();
- GraphicsModule.Initialize ();
- SceneModule.Initialize ();
- AtomicPlayer.PlayerModule.Initialize ();
- AtomicInterop.Initialize ();
- atomicsharp_initialize ();
- initSubsystems ();
- }
- static Dictionary<Type, RefCounted> subSystems = new Dictionary<Type, RefCounted>();
- static private void registerSubsystem (RefCounted subsystem)
- {
- subSystems[subsystem.GetType()] = subsystem;
- }
- static public T GetSubsystem<T>() where T : RefCounted
- {
- return (T) subSystems [typeof(T)];
- }
- static private void initSubsystems()
- {
- registerSubsystem (NativeCore.WrapNative<Player> (csb_AtomicEngine_GetSubsystem("Player")));
- }
- }
- public static partial class Constants
- {
- public const string LIBNAME = "/Users/josh/Dev/atomic/AtomicGameEngineSharp-build/Source/AtomicSharp/AtomicSharp";
- }
- public partial class Node
- {
- public T AddComponent<T> () where T:Component, new()
- {
- T component = new T ();
- AddComponent( component, 0, CreateMode.REPLICATED);
- return component;
- }
- // /new MyComponent (), 0, CreateMode.REPLICATED
- }
- public partial class RefCounted
- {
- protected RefCounted (IntPtr native)
- {
- nativeInstance = native;
- }
-
- public IntPtr nativeInstance;
- static public void _AddRef(IntPtr native)
- {
- csb_Atomic_RefCounted_AddRef(native);
- }
-
- static public void _ReleaseRef(IntPtr native)
- {
- csb_Atomic_RefCounted_ReleaseRef(native);
- }
- [DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
- public static extern IntPtr csb_RefCounted_GetClassID (IntPtr self);
- }
- public partial class Node : Animatable
- {
- public T GetComponent<T> (bool recursive = false) where T:Component
- {
- return (T) GetComponent (typeof(T).Name, recursive);
- }
-
- }
- }
|