-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.cpp
93 lines (73 loc) · 3 KB
/
Main.cpp
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
#include "Precompiled.hpp"
#include "Audio.hpp"
#include "FrameTimer.hpp"
#include "GameObject.hpp"
#include "Graphics.hpp"
#include "Input.hpp"
#include "LogicTimer.hpp"
#include "Physics.hpp"
#include "Reflection.hpp"
#include "Scripting.hpp"
#include "Window.hpp"
#include "CollisionComponents.hpp"
#include "Model.hpp"
#include "RigidBody.hpp"
#include "Transform.hpp"
#include "LuaCppInterfaceInclude.hpp"
#include "PrefabManager.hpp"
int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
using namespace lite;
// Initialize our systems.
auto audio = Audio();
auto physics = Physics(true, {0, -6, 0});
auto window = Window("Lite Game Engine", 960, 540);
auto graphics = Graphics(window);
RegisterComponent<Model>();
RegisterComponent<PlaneCollision>();
RegisterComponent<RigidBody>();
RegisterComponent<SphereCollision>();
RegisterComponent<Transform>();
Note(Reflection::Instance());
auto scene = GameObject("Scene.txt");
auto& spongebobPrefab = *GetPrefab("Bee");
auto frameTimer = FrameTimer();
// Game loop:
while (window.IsOpen())
{
frameTimer.BeginFrame();
window.Title(string("Lite - ") + to_string((int) frameTimer.FPS()) + " fps");
Scripting::Instance().DoString(1 + R"_LuaScript_(
--local Camera = lite.Graphics.CurrentInstance.Camera
local Input = lite.Input
local walkAmount = 0.5
--for key,value in pairs(lite.Graphics.CurrentInstance.Camera) do print(key,value) end
if ( Input.IsKeyHeld(string.byte("W")) ) then lite.Graphics.CurrentInstance:GetCamera():Walk(walkAmount) end
if ( Input.IsKeyHeld(string.byte("S")) ) then lite.Graphics.CurrentInstance:GetCamera():Walk(-walkAmount) end
if ( Input.IsKeyHeld(string.byte("A")) ) then lite.Graphics.CurrentInstance:GetCamera():Strafe(-walkAmount) end
if ( Input.IsKeyHeld(string.byte("D")) ) then lite.Graphics.CurrentInstance:GetCamera():Strafe(walkAmount) end
if ( Input.IsKeyHeld(string.byte("Q")) ) then lite.Graphics.CurrentInstance:GetCamera():Climb(walkAmount) end
if ( Input.IsKeyHeld(string.byte("E")) ) then lite.Graphics.CurrentInstance:GetCamera():Climb(-walkAmount) end
)_LuaScript_");
if (Input::IsTriggered(VK_ESCAPE)) window.Destroy();
if (Input::IsTriggered(VK_F1)) DebugDrawCollisions() = !DebugDrawCollisions();
if (Input::IsTriggered(VK_SPACE))
{
GameObject& child = scene.AddChild(spongebobPrefab);
child[Transform_].LocalPosition = graphics.Camera.Position();
child[RigidBody_].AddForce(Vector(graphics.Camera.Look()) * 300);
}
graphics.Camera.RotateY((float) Input::GetMouseDeltaX() / 100);
graphics.Camera.Pitch((float) Input::GetMouseDeltaY() / 100);
scene.Update();
scene.PushToSystems();
// Update all systems.
audio.Update();
physics.Update(frameTimer.IdealDeltaTime());
window.Update();
graphics.Update(frameTimer.DeltaTime());
scene.PullFromSystems();
frameTimer.EndFrame();
}
return 0;
}