-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleSceneIntro.cpp
More file actions
139 lines (111 loc) · 3.38 KB
/
ModuleSceneIntro.cpp
File metadata and controls
139 lines (111 loc) · 3.38 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "Globals.h"
#include "Application.h"
#include "ModuleSceneIntro.h"
#include "Primitive.h"
#include "GameObject.h"
#include <stdlib.h>
#include <time.h>
#define RADIUS 44
ModuleSceneIntro::ModuleSceneIntro(Application* app, bool start_enabled) : Module(app, start_enabled)
{
selected_game_obj_uid.append("none");
}
ModuleSceneIntro::~ModuleSceneIntro()
{}
// Load assets
bool ModuleSceneIntro::Start()
{
App->gui->app_log.AddLog("Loading Intro assets\n");
srand(time(NULL));
GameObject* floor = new GameObject("floor plane");
floor->components.push_back((Component*)new PrimPlane(0, 1, 0, 10));
App->scene_intro->AddRootObject(floor);
return true;
}
// Load assets
bool ModuleSceneIntro::CleanUp()
{
App->gui->app_log.AddLog("Unloading Intro scene\n");
materials.clear();
all_game_objects.clear();
root_game_objects.clear();
return true;
}
void ModuleSceneIntro::Save(JSON_file& config)
{
JSON_file* save_file = App->json->OpenFile(name.c_str(), ASSETS_BASE_PATH);
save_file->WriteBool("empty", false);
save_file->WriteNumber("obj_num", all_game_objects.size());
uint obj_index = 0;
for (std::vector<GameObject*>::iterator it = all_game_objects.begin(); it != all_game_objects.end(); it++, obj_index++)
(*it)->Save(*save_file, obj_index);
save_file->Save();
config.WriteString("scene_manager.current_scene", name.c_str());
}
void ModuleSceneIntro::Load(JSON_file& config)
{
name = config.ReadString("scene_manager.current_scene");
JSON_file* save_file = App->json->OpenFile(name.c_str(), ASSETS_BASE_PATH);
if (!save_file->ReadBool("empty"))
{
uint obj_num = save_file->ReadNumber("obj_num");
for (uint obj_index = 0; obj_index < obj_num; obj_index++)
{
GameObject* new_obj = new GameObject();
new_obj->Load(*save_file, obj_index);
bool exists = false;
for (std::vector<GameObject*>::iterator it = all_game_objects.begin(); it != all_game_objects.end(); it++)
{
if ((*it)->uid == new_obj->uid) exists = true;
}
if (exists) delete new_obj;
else
{
if (new_obj->parent_uid == "none") AddRootObject(new_obj);
else all_game_objects.push_back(new_obj);
}
}
for (std::vector<GameObject*>::iterator it = all_game_objects.begin(); it != all_game_objects.end(); it++)
(*it)->FindParent(all_game_objects);
}
}
// Update
update_status ModuleSceneIntro::Update(float dt)
{
for (std::vector<GameObject*>::iterator it = all_game_objects.begin(); it != all_game_objects.end(); it++)
{
ComponentMesh* mesh = (ComponentMesh*)(*it)->FindComponent(COMPONENT_MESH);
if (mesh)
{
if (mesh->num_vertices == 0 && mesh->imported_file.length() > 0)
{
char* buffer = App->fs->Load(mesh->imported_file.c_str(), mesh->imported_f_length);
mesh->LoadFromBuffer(buffer);
}
}
}
return UPDATE_CONTINUE;
}
void ModuleSceneIntro::DrawScene()
{
for (std::vector<GameObject*>::iterator it = all_game_objects.begin(); it != all_game_objects.end(); it++) {
if(!(*it)->Cull(App->camera->cam))
(*it)->Draw();
}
}
void ModuleSceneIntro::AddRootObject(GameObject* game_obj)
{
root_game_objects.push_back(game_obj);
all_game_objects.push_back(game_obj);
}
GameObject* ModuleSceneIntro::GetSelectedObj()
{
if (selected_game_obj_uid != "none")
{
for (std::vector<GameObject*>::iterator it = all_game_objects.begin(); it != all_game_objects.end(); it++)
{
if (selected_game_obj_uid == (*it)->uid) return (*it);
}
}
return nullptr;
}