Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
98 lines (72 loc) · 2.89 KB
/
Copy pathmain.cpp
File metadata and controls
98 lines (72 loc) · 2.89 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
//
// Created by ymod1 on 12/05/2026.
//
#include <SDL3/SDL.h>
#include <iostream>
#include <string>
#include <filesystem>
#include <pxr/base/plug/registry.h>
#include <pxr/base/plug/plugin.h>
#include "Systems.hpp"
std::filesystem::path GetExecutableDir()
{
wchar_t buffer[MAX_PATH];
GetModuleFileNameW(nullptr, buffer, MAX_PATH);
return std::filesystem::path(buffer).parent_path();
}
//------------------------------------------------------------------------------------------------
void InitUsdSubsystem()
{
std::filesystem::path exeDir = GetExecutableDir();
std::cout << "[C++] Registering USD plugins..." << std::endl;
const std::vector<std::string> pluginPaths = {
(exeDir / "usd").string(),
(exeDir / "usd_lib").string()
};
auto& registry = PlugRegistry::GetInstance();
auto newPlugins = registry.RegisterPlugins(pluginPaths);
std::cout << "[C++] Registered USD plugins: " << newPlugins.size() << std::endl;
for (const auto& plug : newPlugins) {
std::cout << " - " << plug->GetName() << std::endl;
}
}
//------------------------------------------------------------------------------------------------
int main()
{
InitUsdSubsystem();
std::cout << "Starting...\n";
ecs::World game_world;
ecs::Scheduler scheduler;
scheduler.add<InputAccess> ("InputSystem", Handle_Input);
scheduler.add<PlayerMovementAccess> ("PlayerMovementSystem", Update_Player_Movement);
scheduler.add<EnemiesMovementAccess> ("EnemiesMovementSystem", Update_Enemies_Movement);
scheduler.add<BulletsMovementAccess> ("BulletsMovementSystem", Update_Bullets_Movement);
scheduler.add<CollisionDetectionAccess> ("CollisionDetectionSystem", Collision_detection);
scheduler.add<WorldMapAccess> ("WorldMapSystem", World_Map_Update);
scheduler.add<RenderAccess> ("RenderSystem", Render_Scene);
ecs::EntityID single_tread_entity = game_world.create();
game_world.add(single_tread_entity, NoMultithreading{});
if (!Init_Systems(game_world)) {
std::cout << " -> Systems initialization failed!";
return -1;
}
bool running = true;
using Clock = std::chrono::high_resolution_clock;
using Seconds = std::chrono::duration<float>;
auto last = Clock::now();
// 5. Game Loop
while (running)
{
auto now = Clock::now();
float dt = std::chrono::duration_cast<Seconds>(now - last).count();
last = now;
auto& input = game_world.get_resource<env::InputState>();
scheduler.tick(game_world, dt);
running = !input.quit;
}
std::cout << "Quitting...\n";
Quit_Systems(game_world);
std::cout << "Exiting...\n";
return 0;
}
// TIP See CLion help at <a href="https://www.jetbrains.com/help/clion/">jetbrains.com/help/clion/</a>. Also, you can try interactive lessons for CLion by selecting 'Help | Learn IDE Features' from the main menu.