unit Frost.Engine;

interface

uses
  _Geometry,
  Frost.GL,
  Frost.Forms,
  Frost.Scenes,
  Frost.RenderEngine,  
  Frost.Renderers,
  Frost.GameObjects;

type

TTime = class
  private
    FDelta: Single;
  public
    property Delta: Single read FDelta;
  end;

TResources = class

  end;
  
TControl      = Frost.Forms.TControl;
TScreen       = Frost.Forms.TScreen;
TScene        = Frost.Scenes.TScene;
TGameObject   = Frost.GameObjects.TGameObject;
TComponent    = Frost.GameObjects.TComponent;
TCamera       = Frost.RenderEngine.TCamera;
TMeshRenderer = Frost.Renderers.TMeshRenderer;
TMesh         = Frost.Renderers.TMesh;

TApplication = class
  private
    class var FInstance: TApplication;
  private
    FCurrentScene: TScene;
    FWindow: TWindow;                 
    constructor Create();
  public
    property CurrentScene: TScene read FCurrentScene;
    class procedure Init(CurrentScene: TScene; ApplicationTitle: PAnsiChar);   
    class procedure Start;
    procedure Close;
  end;

var              
  Application: TApplication;
  Resources: TResources;
  Control: TControl;
  Screen:  TScreen;    
  Window:  TWindow;  

implementation

{$REGION '  Application  '}
procedure CreateApplication;
begin
  GL := TOpenGL.Create(Application.FWindow.Handle, Application.FWindow.Width, Application.FWindow.Height);        
  Control := Application.FWindow.Control;
  Screen  := Application.FWindow.Screen;
  Application.CurrentScene.Awake;
end;

procedure CloseApplication;
begin
  if (Application.CurrentScene <> nil) then
    Application.CurrentScene.OnDestroy;
end;

procedure ChangeState;
begin

end;

procedure OnTimer(Delta: double);
begin
  Application.FCurrentScene.OnSceneUpdate(Delta / 10);
end;
 
constructor TApplication.Create();
begin

end;

class procedure TApplication.Init(CurrentScene: TScene; ApplicationTitle: PAnsiChar);
begin
  if (TApplication.FInstance = nil) then
    begin
      Application := TApplication.Create();
      TApplication.FInstance := Application;
      Window:= TWindow.Create(PAnsiChar(ApplicationTitle),
        @CreateApplication, @CloseApplication, @ChangeState, @OnTimer, True);
      Application.FWindow := Window;
      Application.FCurrentScene:= CurrentScene;
    end;
end;

class procedure TApplication.Start;
begin
  Application.FWindow.Initialize;
end;

procedure TApplication.Close;
begin     
  FWindow.Close;
end;
{$ENDREGION}

end.
