Pre initialize removal
This commit is contained in:
@@ -1,10 +1,22 @@
|
||||
namespace Gravity.Kernel;
|
||||
namespace Awperative;
|
||||
|
||||
/// <summary>
|
||||
/// Awperative hooks are the source of entry for scripts using Awperative. Create a hook and send into Start() to be recognized by the engine.
|
||||
/// </summary>
|
||||
public interface AwperativeHook
|
||||
{
|
||||
//DONT LOAD ASSETS HERE
|
||||
/// <summary>
|
||||
/// Called when the program starts; It is not recommended you load assets here.
|
||||
/// </summary>
|
||||
public void Initialize() {}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the program closes.
|
||||
/// </summary>
|
||||
public void Terminate() {}
|
||||
|
||||
/// <summary>
|
||||
/// Called when Awperative loads content.
|
||||
/// </summary>
|
||||
public void Load() {}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
|
||||
namespace Gravity.Kernel;
|
||||
namespace Awperative;
|
||||
|
||||
|
||||
public static class Core
|
||||
/// <summary>
|
||||
/// Initiating class of Awperative. Call Start() to start the kernel.
|
||||
/// </summary>
|
||||
public static class Awperative
|
||||
{
|
||||
//Inherits MonoGame and carries events.
|
||||
public static Base Base;
|
||||
public static List<Scene> LoadedScenes => Base.LoadedScenes;
|
||||
public static List<Scene> LoadedScenes = [];
|
||||
|
||||
public static List<AwperativeHook> ScriptingHooks;
|
||||
//Handles, graphic Settings, drawing, and loading content respectively.
|
||||
public static GraphicsDeviceManager GraphicsDeviceManager { get; internal set; }
|
||||
public static SpriteBatch SpriteBatch { get; internal set; }
|
||||
public static ContentManager ContentManager { get; internal set; }
|
||||
|
||||
//Entry points for code
|
||||
internal static List<AwperativeHook> EventHooks { get; private set; }
|
||||
|
||||
//hooks are called in order
|
||||
/// <summary>
|
||||
/// Start() begins the game; and begins communication with all event hooks.
|
||||
/// </summary>
|
||||
/// <param name="__hooks"> List of all event hooks you wish to use. </param>
|
||||
/// <remarks> You cannot add new hooks later; so make sure to register all of them in the Start() method.</remarks>
|
||||
public static void Start(List<AwperativeHook> __hooks) {
|
||||
ScriptingHooks = __hooks;
|
||||
EventHooks = __hooks;
|
||||
|
||||
Base = new Base();
|
||||
Base.Run();
|
||||
|
||||
Reference in New Issue
Block a user