forked from ThatDamnPineapple/EvolutionProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
135 lines (109 loc) · 4.08 KB
/
Main.cs
File metadata and controls
135 lines (109 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#region global usings
global using Microsoft.Xna.Framework;
global using Microsoft.Xna.Framework.Graphics;
global using EvoSim.ProjectContent.CellStuff;
global using EvoSim.ProjectContent.Camera;
global using EvoSim.ProjectContent.SceneStuff;
global using EvoSim.Interfaces;
global using System;
global using System.Collections.Generic;
global using System.Linq;
#endregion
using Microsoft.Xna.Framework.Input;
using EvoSim.Helpers;
using SharpDX.X3DAudio;
using System.Reflection;
using System.Runtime.CompilerServices;
using EvoSim.Helpers.HelperClasses;
namespace EvoSim
{
public class Main : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public static Random random;
public static float delta;
private static float oldTime;
public static Vector2 ScreenSize => new Vector2(1900, 950);
internal static List<ILoadable> loadCache;
internal static List<IDraw> drawables = new List<IDraw>();
internal static List<IUpdate> updatables = new List<IUpdate>();
public static ButtonToggle ForceSim;
public static bool forcingSim = false;
public Main()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
_graphics.IsFullScreen = false;
_graphics.PreferredBackBufferWidth = (int)ScreenSize.X;
_graphics.PreferredBackBufferHeight = (int)ScreenSize.Y;
_graphics.ApplyChanges();
base.Initialize();
}
protected override void LoadContent()
{
ForceSim = new ButtonToggle(new PressingButton(() => Keyboard.GetState().IsKeyDown(Keys.U)), new ButtonAction((object o) => forcingSim = true));
_spriteBatch = new SpriteBatch(GraphicsDevice);
random = new Random();
loadCache = new List<ILoadable>();
foreach (Type type in Assembly.GetAssembly(typeof(Main)).GetTypes())
{
if (!type.IsAbstract && type.GetInterfaces().Contains(typeof(ILoadable)))
{
object instance = Activator.CreateInstance(type);
loadCache.Add(instance as ILoadable);
}
loadCache.Sort((n, t) => n.LoadPriority.CompareTo(t.LoadPriority));
}
for (int k = 0; k < loadCache.Count; k++)
{
loadCache[k].Load();
}
DrawHelper.MagicPixel = Content.Load<Texture2D>("sprites/MagicPixel");
DrawHelper.Arial = Content.Load<SpriteFont>("fonts/Arial");
}
protected override void Update(GameTime gameTime)
{
ForceSim.Update(this);
delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
if (forcingSim)
{
delta = 0.004f;
for (int i = 0; i < 50000; i++)
{
foreach (IUpdate updatable in updatables.OrderBy(n => n.UpdatePriority))
{
updatable.Update(gameTime);
}
}
forcingSim = false;
base.Update(gameTime);
return;
}
foreach (IUpdate updatable in updatables.OrderBy(n => n.UpdatePriority))
{
updatable.Update(gameTime);
}
oldTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
_spriteBatch.Begin();
foreach (IDraw drawable in drawables.OrderBy(n => n.DrawPriority))
{
drawable.Draw(_spriteBatch);
}
_spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}