Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
render_model_performance_test.hpp
Go to the documentation of this file.
1 #include "../console.h"
2 
3 #include <Strings/components/resources/strings/strings.h>
4 #include <Strings/components/utils/converters/converters.h>
5 
10 
12 {
17  {
18  public:
20  {
21  name = "render_model_performance_test";
22  description = "";
23  syntax = "render_model_performance_test <tag> <count> <distance> [y] [disable gizmos]";
24 
26  }
27 
28  BlamResult Execute(std::vector<std::string> arguments)
29  {
30  if (arguments.size() < 3)
31  {
32  return BlamResult::Error_Command_WrongArgumentCount;
33  }
34 
35  std::string tag_path = arguments.at(0);
36  int count = BlamStrings::Converters::StringToInt(arguments.at(1), 0);
37  float distance = BlamStrings::Converters::StringToFloat(arguments.at(2), 1.0f);
38  float y = 0.0f;
39  bool disable_gizmos = false;
40 
41  if (arguments.size() >= 4)
42  {
43  y = BlamStrings::Converters::StringToFloat(arguments.at(3), y);
44  }
45 
46  if (arguments.size() >= 5)
47  {
48  disable_gizmos = BlamStrings::Converters::StringToBool(arguments.at(4), disable_gizmos);
49  }
50 
52 
53  if (!tag)
54  {
55  BlamResult load_result = Blam::Content::Tags::LoadTagFromFile(tag_path);
56 
57  if (load_result == BlamResult::Error_FileNotFound)
58  {
59  Blam::Logger::LogEventForce("couldn't load tag '" + tag_path + "' to place", WSV_ERROR);
60  Blam::Logger::LogEventForce("tag '" + tag_path + "' does not exist");
61  return BlamResult::Success_OK;
62  }
63  else if (BR_FAILED(load_result))
64  {
65  Blam::Logger::LogEventForce("couldn't load tag '" + tag_path + "' to place", WSV_ERROR);
66  Blam::Logger::LogEventForce("tag '" + tag_path + "' load result was " + std::to_string(load_result)
67  + ": " + ERROR_TEXT(load_result));
68  return BlamResult::Success_OK;
69  }
70 
71  tag = Blam::Content::Tags::GetTagData(tag_path);
72  }
73 
74  if (!tag)
75  {
76  Blam::Logger::LogEventForce("couldn't load tag '" + tag_path + "' to place", WSV_ERROR);
77  Blam::Logger::LogEventForce("tag '" + tag_path + "' does not exist");
78  return BlamResult::Success_OK;
79  }
80 
82 
83  if (!world_state)
84  {
85  Blam::Logger::LogEventForce("cannot place: world state not ready", WSV_ERROR);
86  return BlamResult::Success_OK;
87  }
88 
89  std::vector<BlamWorldObject_Tag*> new_objects = std::vector<BlamWorldObject_Tag*>();
90 
91  int length = sqrt(count) / 2;
92 
93  for (int x = -length; x < length; x++)
94  {
95  for (int z = -length; z < length; z++)
96  {
97  BlamWorldObject_Tag* object = world_state->CreateTagObject(tag, false);
98 
99  if (object && object->ValidateTagData())
100  {
101  new_objects.push_back(object);
102  object->SetPosition(BlamVector3(x * distance, y, z * distance));
103  }
104  else
105  {
106  if (object) delete object;
107  }
108  }
109  }
110 
111  for (BlamWorldObject_Tag* object : new_objects)
112  {
113  world_state->AddObject(object);
114 
115  if (disable_gizmos && !UsingBgfx())
116  {
117  object->SetTransformEnabled(false);
118  }
119  }
120 
121  Blam::Logger::LogEventForce("placed " + std::to_string(new_objects.size()) + " of '" + tag_path + "'");
122 
123  return BlamResult::Success_OK;
124  }
125  };
126 }
Blam::World::GetWorldState
BLAM BlamWorldState * GetWorldState()
Retrieves the current world state.
Definition: world.cpp:56
object
Definition: object.h:27
tag_io.h
BlamWorldState::AddObject
void AddObject(BlamWorldObject *object)
Definition: BlamWorldState.cpp:107
Blam::Resources::Console::RenderModelPerformanceTestCommand
Class for the render_model_performance_test command.
Definition: render_model_performance_test.hpp:16
Blam::Resources::Console::RenderModelPerformanceTestCommand::Execute
BlamResult Execute(std::vector< std::string > arguments)
Called upon command execution.
Definition: render_model_performance_test.hpp:28
BlamConsoleCommand::description
std::string description
An optional description of the command. Shown when using the classify command.
Definition: console.h:36
logger.h
Blam::Resources::Console::RenderModelPerformanceTestCommand::RenderModelPerformanceTestCommand
RenderModelPerformanceTestCommand()
Definition: render_model_performance_test.hpp:19
world.h
BlamConsoleCommand
Class used to represent a console command.
Definition: console.h:33
UsingBgfx
bool UsingBgfx()
Definition: bgfx.cpp:63
Blam::Content::Tags::LoadTagFromFile
BLAM BlamResult LoadTagFromFile(std::string tag_path, bool reload_if_already_loaded=true)
Loads a tag from the engine's tag directory (default is '.
Definition: tag_io.cpp:319
BlamWorldState::CreateTagObject
BlamWorldObject_Tag * CreateTagObject(BlamTagData *tag_data, bool add_to_world=true)
Definition: BlamWorldState.cpp:258
BlamWorldObject_Tag
Class representing a tag-based world object.
Definition: world_objects.h:278
y
font DisplayOffset y
Definition: README.txt:68
BlamConsoleCommand::name
std::string name
The name of the console command.
Definition: console.h:35
Blam::Content::Tags::GetTagData
BLAM BlamTagData * GetTagData(std::string tag_path)
Retrieves information for a given tag.
Definition: tags.cpp:81
BlamConsoleCommand::syntax
std::string syntax
The syntax information for the command. Shown to the user when using the help command with an argumen...
Definition: console.h:37
BlamConsoleCommand::type
BlamCommandType type
The type of command this is. See #Blam::Resources::Console::BlamCommandType for more information.
Definition: console.h:40
BlamWorldObject::SetPosition
void SetPosition(BlamVector3 position)
Definition: BlamWorldObject.cpp:233
Blam::Logger::LogEventForce
BLAM void LogEventForce(std::string message)
Forcibly logs a message to the log and/or console.
Definition: aliases.cpp:262
tags.h
x
config GlyphExtraSpacing x
Definition: README.txt:30
BlamTagData
Class used to contain and access tag data.
Definition: tags.h:125
Blam::Resources::Console
Namespace for things relating to the debug console.
Definition: abort.hpp:5
BlamWorldState
Class representing a world state.
Definition: world_objects.h:715
BlamCommandType::Builtin
@ Builtin
A command that is hard-coded into the engine.