-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
120 lines (98 loc) · 3.33 KB
/
main.cpp
File metadata and controls
120 lines (98 loc) · 3.33 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
#include <iostream>
#include "raylib.h"
#include "rlgl.h"
#include <string>
#include <vector>
#include <unordered_map>
#ifdef _WIN32
#include <lua.hpp>
#else
#include <luajit-2.1/lua.hpp>
#endif
#include "jsonparser.h"
#include "entitydefinition.h"
#include "entitymanager.h"
#include "scenemanager.h"
#include "modelsdrawcalls.h"
#include "functionsluadraw.h"
#include "functionsluamain.h"
#include "functionsluainput.h"
///Initialize Shaders
#if defined(PLATFORM_DESKTOP)
#define GLSL_VERSION 330
#else
#define GLSL_VERSION 100
#endif
Shader modelsbatchshader;
///Entitys
std::vector<Entity> entities_scene;
int next_entity_id = -1;
///Assets Unordered Maps
std::unordered_map<std::string, Texture> textures_buffer;
std::unordered_map<std::string, Sound> sounds_buffer;
std::unordered_map<std::string, Model> models_buffer;
std::unordered_map<std::string, Shader> shader_buffer;
std::unordered_map<std::string, Font> font_buffer;
///Initialize Model Queue
std::unordered_map<Model*,RenderBatch> batches;
///Initialize Camera
Camera3D camera = {0};
///Initialize LUA state
lua_State* L;
int main(){
///Start LUA
L = luaL_newstate();
luaL_openlibs(L);
luaL_dofile(L,"gamefiles/engine/modules/angelhelper.lua");
luaL_dofile(L,"gamefiles/engine/modules/angelinput.lua");
///Define Exposed Functions
ExposeDrawFunctions();
ExposeMainFunctions();
ExposeInputFunctions();
///Load config file
JsonParser config;
config.load("gamefiles/game.json");
///Set some flags
unsigned int window_flags = 0;
if(config.get_bool("window_resize")) window_flags |= FLAG_WINDOW_RESIZABLE;
if(config.get_bool("window_fullscreen")) window_flags |= FLAG_FULLSCREEN_MODE;
if(window_flags != 0) SetConfigFlags(window_flags);
///Initialize Window
InitWindow(config.get_int("window_width"),config.get_int("window_height"),config.get_string("name").c_str());
///Start Engine Shaders
modelsbatchshader = LoadShader(TextFormat("gamefiles/engine/shaders/%i/modelbatch.vs",GLSL_VERSION),TextFormat("gamefiles/engine/shaders/%i/modelbatch.fs",GLSL_VERSION));
modelsbatchshader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(modelsbatchshader,"mvp");
modelsbatchshader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(modelsbatchshader,"instanceTransform");
///Block mouse
if(config.get_bool("block_mouse")) DisableCursor();
SetTargetFPS(config.get_int("target_fps"));
///Configure Camera
camera.position = (Vector3){0.0f,5.0f,10.0f};
camera.target = (Vector3){0.0f,0.0f,0.0f};
camera.up = (Vector3){0.0f,1.0f,0.0f};
camera.fovy = 60.f;
camera.projection = CAMERA_PERSPECTIVE;
///Load the MainScene
LoadScene(config.get_string("starting_scene",""));
///Start the game loop
while(!WindowShouldClose()){
UpdateCamera(&camera,CAMERA_FREE);
float delta_time = GetFrameTime();
UpdateEntities(delta_time);
BeginDrawing();
ClearBackground(BLACK);
BeginMode3D(camera);
DrawEntities();
FlushRendererModels();
EndMode3D();
DrawScreenEntities();
if(config.get_bool("show_fps")) DrawFPS(10,10);
EndDrawing();
}
///End the Engine
lua_close(L);
CloseWindow();
///Free Shaders
UnloadShader(modelsbatchshader);
return 0;
}