Pre initialize removal

This commit is contained in:
2026-01-30 20:22:49 -05:00
parent cc4fee7a34
commit 9f744fcd5f
43 changed files with 156 additions and 186 deletions

View File

@@ -1,107 +1,72 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Gravity.Kernel;
namespace Awperative;
//todo: make static
public class Base : Game
/// <summary>
/// Base class of Awperative. Carries events from MonoGame into scenes and hooks.
/// </summary>
public sealed class Base : Game
{
public static GraphicsDeviceManager GraphicsDeviceManager;
public static ContentManager ContentManager { get; private set; }
public static SpriteBatch SpritesBatch;
public static List<Scene> LoadedScenes { get; private set; } = [];
public static Scene MainScene { get; private set; }
public Base()
{
//todo: move this asshole to camera
GraphicsDeviceManager = new GraphicsDeviceManager(this);
GraphicsDeviceManager.PreferredBackBufferWidth = 1920;
GraphicsDeviceManager.PreferredBackBufferHeight = 1080;
GraphicsDeviceManager.IsFullScreen = true;
/// <summary>
/// Start of Awperative. Please do not try to call this.
/// </summary>
internal Base() {
Awperative.GraphicsDeviceManager = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
/// <summary>
/// Initialize() is called when the program starts. Override Initialize() in scripting tools or use hooks to call from this event.
/// </summary>
/// <remarks> It is recommended not to load content in Initialize()</remarks>
protected override void Initialize() {
Awperative.ContentManager = Content;
Awperative.SpriteBatch = new SpriteBatch(GraphicsDevice);
ContentManager = Content;
SpritesBatch = new SpriteBatch(GraphicsDevice);
MainScene = new Scene();
LoadedScenes.Add(MainScene);
//todo: generalize initialization, load a json file containing scripts to run and try running them
//intptr.size
//Marshal.Sizeof<Class>
foreach (AwperativeHook hook in Core.ScriptingHooks)
hook.Initialize();
// TODO: Add your initialization logic here
foreach(Scene scene in LoadedScenes)
scene.Initialize();
foreach (AwperativeHook hook in Awperative.EventHooks) hook.Initialize();
foreach(Scene scene in Awperative.LoadedScenes) scene.Initialize();
base.Initialize();
}
protected override void LoadContent()
{
foreach (AwperativeHook hook in Core.ScriptingHooks)
/// <summary>
/// LoadContent() is called when the program starts; right after Initialize(). Override Load() in scripting tools or use hooks to call from this event.
/// </summary>
/// <remarks> It is recommended to load content during LoadContent()</remarks>
protected override void LoadContent() {
foreach (AwperativeHook hook in Awperative.EventHooks)
hook.Load();
foreach(Scene scene in LoadedScenes)
foreach(Scene scene in Awperative.LoadedScenes)
scene.Load();
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
//TODO: add specific error codes so i know when json went wrong
foreach(Scene scene in LoadedScenes)
scene.Update(gameTime);
base.Update(gameTime);
/// <summary>
/// Update() is called every frame; before Draw(). Override Update() in scripting tools to call from this event.
/// </summary>
/// <remarks> Hooks are unable to receive both Update() and Draw()</remarks>
protected override void Update(GameTime __gameTime) {
foreach(Scene scene in Awperative.LoadedScenes) scene.Update(__gameTime);
base.Update(__gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
// TODO: Add your drawing code here
//collider.Center += Vector2.One;
//ADD MOVING COLLIDERS
foreach(Scene scene in LoadedScenes)
scene.Draw(gameTime);
base.Draw(gameTime);
/// <summary>
/// Draw() is called every frame; after Update(). Override Draw() in scripting tools to call from this event.
/// </summary>
/// <remarks> Hooks are unable to receive both Update() and Draw()</remarks>
protected override void Draw(GameTime __gameTime) {
foreach(Scene scene in Awperative.LoadedScenes) scene.Draw(__gameTime);
base.Draw(__gameTime);
}
protected override void EndRun()
{
foreach (AwperativeHook hook in Core.ScriptingHooks)
hook.Terminate();
foreach (Scene scene in LoadedScenes)
scene.Terminate();
/// <summary>
/// EndRun() is called if the program closes. Override Terminate() in scripting tools or use hooks to call from this event.
/// </summary>
/// <remarks> This event may not trigger if the program is force closed.</remarks>
protected override void EndRun() {
foreach (AwperativeHook hook in Awperative.EventHooks) hook.Terminate();
foreach (Scene scene in Awperative.LoadedScenes) scene.Terminate();
}
}