Skip to content

Commit

Permalink
WIP of xrAI and xrSE_Factory. Headers cleanup. Use range-based for.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr committed Dec 31, 2017
1 parent ecb43e8 commit 7da3a99
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 434 deletions.
87 changes: 35 additions & 52 deletions src/utils/xrAI/game_spawn_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

#include "stdafx.h"
#include "game_spawn_constructor.h"
#include "Common/object_broker.h"
#include "level_spawn_constructor.h"
#include "xrServer_Objects_ALife_All.h"
#include "xrai.h"
#include "server_entity_wrapper.h"
#include "xrAICore/Navigation/graph_engine.h"
#include "xrAICore/Navigation/PatrolPath/patrol_path_storage.h"
#include "xrAI.h"

extern LPCSTR GAME_CONFIG;
extern LPCSTR generate_temp_file_name(LPCSTR header0, LPCSTR header1, string_path& buffer);
Expand Down Expand Up @@ -82,40 +80,32 @@ void CGameSpawnConstructor::load_spawns(LPCSTR name, bool no_separator_check)

// load levels
GameGraph::SLevel level;
auto I = m_levels.begin();
auto E = m_levels.end();
for (; I != E; ++I)
for (const auto &i : m_levels)
{
level.m_offset = (*I).m_offset;
level.m_name = (*I).m_name;
level.m_id = (*I).m_id;
Msg("%9s %2d %s", "level", level.id(), *(*I).m_name);
level.m_offset = i.m_offset;
level.m_name = i.m_name;
level.m_id = i.m_id;
Msg("%9s %2d %s", "level", level.id(), *i.m_name);
m_level_spawns.push_back(new CLevelSpawnConstructor(level, this, no_separator_check));
}

string256 temp;
xr_sprintf(temp,
"There are no valid levels (with AI-map and graph) in the section 'levels' in the '%s' to build spawn file "
"from!",
GAME_CONFIG);
xr_sprintf(temp, "There are no valid levels (with AI-map and graph) in the section 'levels' in the '%s' to build spawn file from!", GAME_CONFIG);
R_ASSERT2(!m_level_spawns.empty(), temp);
}

void CGameSpawnConstructor::process_spawns()
{
auto I = m_level_spawns.begin();
auto E = m_level_spawns.end();
for (; I != E; ++I)
for (auto &i: m_level_spawns)
#ifdef NO_MULTITHREADING
(*I)->Execute();
i->Execute();
#else
m_thread_manager.start(*I);
m_thread_manager.start(i);
m_thread_manager.wait();
#endif

I = m_level_spawns.begin();
for (; I != E; ++I)
(*I)->update();
for (auto &i : m_level_spawns)
i->update();

verify_level_changers();
verify_spawns();
Expand All @@ -129,20 +119,16 @@ void CGameSpawnConstructor::verify_spawns(ALife::_SPAWN_ID spawn_id)
m_temp0.push_back(spawn_id);

auto vertex = m_spawn_graph->vertex(spawn_id);
auto I = vertex->edges().begin();
auto E = vertex->edges().end();
for (; I != E; ++I)
verify_spawns((*I).vertex_id());
for (const auto &i : vertex->edges())
verify_spawns(i.vertex_id());
}

void CGameSpawnConstructor::verify_spawns()
{
SPAWN_GRAPH::const_vertex_iterator I = m_spawn_graph->vertices().begin();
SPAWN_GRAPH::const_vertex_iterator E = m_spawn_graph->vertices().end();
for (; I != E; ++I)
for (const auto &i : m_spawn_graph->vertices())
{
m_temp0.clear();
verify_spawns((*I).second->vertex_id());
verify_spawns(i.second->vertex_id());
}
}

Expand All @@ -152,10 +138,9 @@ void CGameSpawnConstructor::verify_level_changers()
return;

Msg("List of the level changers which are invalid for some reasons");
LEVEL_CHANGER_STORAGE::const_iterator I = m_level_changers.begin();
LEVEL_CHANGER_STORAGE::const_iterator E = m_level_changers.end();
for (; I != E; ++I)
Msg("%s", (*I)->name_replace());

for (const auto &i : m_level_changers)
Msg("%s", i->name_replace());

VERIFY2(m_level_changers.empty(), "Some of the level changers setup incorrectly");
}
Expand Down Expand Up @@ -222,8 +207,7 @@ void CGameSpawnConstructor::add_story_object(ALife::_STORY_ID id, CSE_ALifeDynam
{
Msg("Object %s, story id %d", object->name_replace(), object->m_story_id);
Msg("Object %s, story id %d", (*I).second->name_replace(), (*I).second->m_story_id);
VERIFY3(I == m_story_objects.end(), "There are several objects which has the same unique story ID, level ",
level_name);
VERIFY3(I == m_story_objects.end(), "There are several objects which has the same unique story ID, level ", level_name);
}

m_story_objects.insert(std::make_pair(id, object));
Expand All @@ -242,17 +226,14 @@ void CGameSpawnConstructor::process_actor(LPCSTR start_level_name)
{
m_actor = nullptr;

auto I = m_level_spawns.begin();
auto E = m_level_spawns.end();
for (; I != E; ++I)
for (const auto &i : m_level_spawns)
{
if (!(*I)->actor())
if (!i->actor())
continue;

Msg("Actor is on the level %s",
*game_graph().header().level(game_graph().vertex((*I)->actor()->m_tGraphID)->level_id()).name());
Msg("Actor is on the level %s", *game_graph().header().level(game_graph().vertex(i->actor()->m_tGraphID)->level_id()).name());
VERIFY2(!m_actor, "There must be the SINGLE level with ACTOR!");
m_actor = (*I)->actor();
m_actor = i->actor();
}

R_ASSERT2(m_actor, "There is no ACTOR spawn point!");
Expand Down Expand Up @@ -307,30 +288,32 @@ void clear_temp_folder()
{
string_path query;
FS.update_path(query, "$app_data_root$", "temp\\*.*");
string_path path_root;
FS.update_path(path_root, "$app_data_root$", "temp\\");
string_path path_final;

_finddata_t file;
auto handle = _findfirst(query, &file);
if (handle == intptr_t(-1))
return;

typedef xr_vector<shared_str> FILES;
FILES files;
xr_vector<shared_str> files;
do
{
if (file.attrib & _A_SUBDIR)
continue;

files.push_back(file.name);
strconcat(sizeof(path_final), path_final, path_root, file.name);
files.push_back(path_final);
} while (!_findnext(handle, &file));

_findclose(handle);

FILES::const_iterator I = files.begin();
FILES::const_iterator E = files.end();
for (; I != E; ++I)
for (const auto &i : files)
{
if (DeleteFile(**I))
Msg("file %s is successfully deleted", **I);
if (DeleteFile(*i))
Msg("file %s is successfully deleted", *i);
else
Msg("cannot delete file %s", **I);
Msg("cannot delete file %s", *i);
}
}
Loading

0 comments on commit 7da3a99

Please sign in to comment.