Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengtuggy committed May 1, 2024
1 parent a71c262 commit 46aedb5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 51 deletions.
2 changes: 1 addition & 1 deletion engine/src/cmd/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ std::vector<std::string> json::parsing::parse_array(const char *input)
} else if (input[0] == '\0') {
VS_LOG_AND_FLUSH(debug, "Invalid JSON Input - Empty String");
} else {
VS_LOG_AND_FLUSH(debug, boost::format("JSON Data: %s") % input);
//VS_LOG_AND_FLUSH(trace, boost::format("JSON Data: %s") % input);
}

const char *index = json::parsing::tlws(input);
Expand Down
28 changes: 21 additions & 7 deletions engine/src/lin_time.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2001-2022 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* lin_time.cpp
*
* Copyright (C) 2001-2024 Daniel Horn, pyramid3d, Stephen G. Tuggy,
* and other Vega Strike contributors.
*
* https://github.com/vegastrike/Vega-Strike-Engine-Source
Expand Down Expand Up @@ -29,7 +31,7 @@
static double firsttime;
VSRandom vsrandom(time(NULL));

#ifdef WIN32
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif //tells VCC not to generate min/max macros
Expand Down Expand Up @@ -168,8 +170,12 @@ void micro_sleep(unsigned int n) {
#endif

void InitTime() {
#ifdef WIN32
VS_LOG(trace, "InitTime() called");
#ifdef _WIN32
QueryPerformanceFrequency(&freq);
if (freq.QuadPart == 0) {
VS_LOG(serious_warning, "InitTime(): freq is zero!");
}
QueryPerformanceCounter(&ttime);

#elif defined (_POSIX_MONOTONIC_CLOCK)
Expand Down Expand Up @@ -200,12 +206,14 @@ double GetElapsedTime() {
}

double queryTime() {
#ifdef WIN32
#ifdef _WIN32
alignas(16) LARGE_INTEGER ticks;
QueryPerformanceCounter(&ticks);
double tmpnewtime = 0;
if (freq.QuadPart > 0) {
tmpnewtime = static_cast<double>(ticks.QuadPart / freq.QuadPart);
} else {
tmpnewtime = static_cast<double>(ticks.QuadPart);
}
return tmpnewtime - firsttime;
#elif defined (_POSIX_MONOTONIC_CLOCK)
Expand All @@ -228,12 +236,14 @@ double queryTime() {
}

double realTime() {
#ifdef WIN32
#ifdef _WIN32
alignas(16) LARGE_INTEGER ticks;
QueryPerformanceCounter(&ticks);
double tmpnewtime = 0;
if (freq.QuadPart > 0) {
tmpnewtime = static_cast<double>(ticks.QuadPart / freq.QuadPart);
} else {
tmpnewtime = static_cast<double>(ticks.QuadPart);
}
if (tmpnewtime == INFINITY) {
tmpnewtime = 0;
Expand All @@ -259,19 +269,23 @@ double realTime() {

void UpdateTime() {
static bool first = true;
#ifdef WIN32
#ifdef _WIN32
alignas(16) LARGE_INTEGER ticks;
QueryPerformanceCounter(&ticks);
double tmpnewtime = 0;
if (freq.QuadPart > 0) {
tmpnewtime = static_cast<double>(ticks.QuadPart / freq.QuadPart);
} else {
tmpnewtime = static_cast<double>(ticks.QuadPart);
}
if (tmpnewtime == INFINITY) {
tmpnewtime = 0;
}
double tmpttime = 0;
if (freq.QuadPart > 0) {
tmpttime = static_cast<double>(ttime.QuadPart / freq.QuadPart);
} else {
tmpttime = static_cast<double>(ttime.QuadPart);
}
elapsedtime = (tmpnewtime - tmpttime);
ttime = newtime;
Expand Down Expand Up @@ -307,7 +321,7 @@ void UpdateTime() {
# error "We have no way to determine the time on this system."
#endif
elapsedtime *= timecompression;
// VS_LOG(trace, (boost::format("lin_time.cpp: UpdateTime(): elapsedtime after time compression is %1%") % elapsedtime));
//VS_LOG(trace, (boost::format("lin_time.cpp: UpdateTime(): elapsedtime after time compression is %1%") % elapsedtime));
first = false;
}

Expand Down
4 changes: 3 additions & 1 deletion engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ int main(int argc, char *argv[]) {
}
#endif
#endif

InitTime();

AUDInit();
AUDListenerGain(vs_options::instance().sound_gain);
Expand Down Expand Up @@ -555,7 +557,7 @@ void SetStartupView(Cockpit *cp) {

void bootstrap_main_loop() {
static bool LoadMission = true;
InitTime();
//InitTime();
if (LoadMission) {
LoadMission = false;
active_missions.push_back(mission = new Mission(mission_name));
Expand Down
90 changes: 48 additions & 42 deletions engine/src/star_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ void StarSystem::Update(float priority) {

//client
void StarSystem::Update(float priority, bool executeDirector) {
static bool very_first_frame{ true };
bool firstframe = true;
///this makes it so systems without players may be simulated less accurately
for (unsigned int k = 0; k < _Universe->numPlayers(); ++k) {
Expand All @@ -1113,31 +1114,35 @@ void StarSystem::Update(float priority, bool executeDirector) {
simulation_atom_var /= (priority / getTimeCompression());
//VS_LOG(trace, (boost::format("void StarSystem::Update( float priority, bool executeDirector ): Msg B: simulation_atom_var as multiplied = %1%") % simulation_atom_var));
///just be sure to restore this at the end
time += GetElapsedTime();
if (very_first_frame) {
time = GetElapsedTime() - SIMULATION_ATOM;
very_first_frame = false;
}
double time_to_chew_up = GetElapsedTime() - time;
_Universe->pushActiveStarSystem(this);
// double bolttime = 0;
if (time > simulation_atom_var) {
if (time > simulation_atom_var * 2) {
double bolttime = 0;
if (time_to_chew_up > simulation_atom_var) {
if (time_to_chew_up > simulation_atom_var * 2) {
VS_LOG(trace,
(boost::format(
"%1% %2%: time, %3$.6f, is more than twice simulation_atom_var, %4$.6f")
% __FILE__ % __LINE__ % time % simulation_atom_var));
"%1% %2%: time_to_chew_up to chew up, %3$.6f, is more than twice simulation_atom_var, %4$.6f")
% __FILE__ % __LINE__ % time_to_chew_up % simulation_atom_var));
}

// double missionSimulationTimeSubtotal = 0.0;
// double processUnitTimeSubtotal = 0.0;
//
// double updateUnitsPhysicsTimeSubtotal = 0.0;
// double updateMissilesTimeSubtotal = 0.0;
// double collideTableUpdateTimeSubtotal = 0.0;
// double updateCameraSoundsTimeSubtotal = 0.0;
double missionSimulationTimeSubtotal = 0.0;
double processUnitTimeSubtotal = 0.0;

double updateUnitsPhysicsTimeSubtotal = 0.0;
double updateMissilesTimeSubtotal = 0.0;
double collideTableUpdateTimeSubtotal = 0.0;
double updateCameraSoundsTimeSubtotal = 0.0;

//Chew up all sim_atoms that have elapsed since last update
// ** stephengtuggy 2020-07-23: We definitely need this block of code! **
while (time > simulation_atom_var) {
while (time_to_chew_up > simulation_atom_var) {
//VS_LOG(trace, "void StarSystem::Update( float priority, bool executeDirector ): Chewing up a sim atom");
if (current_stage == MISSION_SIMULATION) {
// double missionSimulationStageStartTime = realTime();
double missionSimulationStageStartTime = realTime();
TerrainCollide();
UpdateAnimatedTexture();
Unit::ProcessDeleteQueue();
Expand All @@ -1157,45 +1162,46 @@ void StarSystem::Update(float priority, bool executeDirector) {
//waste of frakkin time
active_missions[i]->BriefingUpdate();
}
// double missionSimulationStageEndTime = realTime();
// missionSimulationTimeSubtotal += (missionSimulationStageEndTime - missionSimulationStageStartTime);
// VS_LOG(trace, (boost::format("void StarSystem::Update( float priority, bool executeDirector ): Time taken by MISSION_SIMULATION stage: %1%") % (missionSimulationStageEndTime - missionSimulationStageStartTime)));
double missionSimulationStageEndTime = realTime();
missionSimulationTimeSubtotal += (missionSimulationStageEndTime - missionSimulationStageStartTime);
//VS_LOG(trace, (boost::format("void StarSystem::Update( float priority, bool executeDirector ): Time taken by MISSION_SIMULATION stage: %1%") % (missionSimulationStageEndTime - missionSimulationStageStartTime)));
current_stage = PROCESS_UNIT;
} else if (current_stage == PROCESS_UNIT) {
// double processUnitStageStartTime = realTime();
double processUnitStageStartTime = realTime();
UpdateUnitsPhysics(firstframe);
// double updateUnitsPhysicsDoneTime = realTime();
// updateUnitsPhysicsTimeSubtotal += (updateUnitsPhysicsDoneTime - processUnitStageStartTime);
double updateUnitsPhysicsDoneTime = realTime();
updateUnitsPhysicsTimeSubtotal += (updateUnitsPhysicsDoneTime - processUnitStageStartTime);
UpdateMissiles(); //do explosions
// double updateMissilesDoneTime = realTime();
// updateMissilesTimeSubtotal += (updateMissilesDoneTime - updateUnitsPhysicsDoneTime);
double updateMissilesDoneTime = realTime();
updateMissilesTimeSubtotal += (updateMissilesDoneTime - updateUnitsPhysicsDoneTime);
collide_table->Update();
// double collideTableUpdateDoneTime = realTime();
// collideTableUpdateTimeSubtotal += (collideTableUpdateDoneTime - updateMissilesDoneTime);
double collideTableUpdateDoneTime = realTime();
collideTableUpdateTimeSubtotal += (collideTableUpdateDoneTime - updateMissilesDoneTime);
if (this == _Universe->getActiveStarSystem(0)) {
UpdateCameraSnds();
}
// bolttime = queryTime();
// bolttime = queryTime() - bolttime;
// double processUnitStageEndTime = realTime();
// processUnitTimeSubtotal += (processUnitStageEndTime - processUnitStageStartTime);
// updateCameraSoundsTimeSubtotal += (processUnitStageEndTime - collideTableUpdateDoneTime);
// VS_LOG(trace, (boost::format("void StarSystem::Update( float priority, bool executeDirector ): Time taken by PROCESS_UNIT stage: %1%") % (processUnitStageEndTime - processUnitStageStartTime)));
bolttime = queryTime();
bolttime = queryTime() - bolttime;
double processUnitStageEndTime = realTime();
processUnitTimeSubtotal += (processUnitStageEndTime - processUnitStageStartTime);
updateCameraSoundsTimeSubtotal += (processUnitStageEndTime - collideTableUpdateDoneTime);
//VS_LOG(trace, (boost::format("void StarSystem::Update( float priority, bool executeDirector ): Time taken by PROCESS_UNIT stage: %1%") % (processUnitStageEndTime - processUnitStageStartTime)));
current_stage = MISSION_SIMULATION;
firstframe = false;
}
time -= simulation_atom_var;
time_to_chew_up -= simulation_atom_var;
}
time = GetElapsedTime();

VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by MISSION_SIMULATION: %3%") % __FILE__ % __LINE__ % missionSimulationTimeSubtotal));
VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by PROCESS_UNIT: %3%") % __FILE__ % __LINE__ % processUnitTimeSubtotal));

// VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by MISSION_SIMULATION: %3%") % __FILE__ % __LINE__ % missionSimulationTimeSubtotal));
// VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by PROCESS_UNIT: %3%") % __FILE__ % __LINE__ % processUnitTimeSubtotal));
//
// VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by updating units' physics: %3%") % __FILE__ % __LINE__ % updateUnitsPhysicsTimeSubtotal));
// VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by updating missiles: %3%") % __FILE__ % __LINE__ % updateMissilesTimeSubtotal));
// VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by updating collide tables: %3%") % __FILE__ % __LINE__ % collideTableUpdateTimeSubtotal));
// VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by updating camera sounds: %3%") % __FILE__ % __LINE__ % updateCameraSoundsTimeSubtotal));
VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by updating units' physics: %3%") % __FILE__ % __LINE__ % updateUnitsPhysicsTimeSubtotal));
VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by updating missiles: %3%") % __FILE__ % __LINE__ % updateMissilesTimeSubtotal));
VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by updating collide tables: %3%") % __FILE__ % __LINE__ % collideTableUpdateTimeSubtotal));
VS_LOG(trace, (boost::format("%1% %2%: Subtotal of time taken by updating camera sounds: %3%") % __FILE__ % __LINE__ % updateCameraSoundsTimeSubtotal));

// double cycleThroughPlayersStartTime = realTime();
double cycleThroughPlayersStartTime = realTime();
unsigned int i = _Universe->CurrentCockpit();
for (unsigned int j = 0; j < _Universe->numPlayers(); ++j) {
if (_Universe->AccessCockpit(j)->activeStarSystem == this) {
Expand All @@ -1211,8 +1217,8 @@ void StarSystem::Update(float priority, bool executeDirector) {
}
}
_Universe->SetActiveCockpit(i);
// double cycleThroughPlayersEndTime = realTime();
// VS_LOG(trace, (boost::format("%1% %2%: Time taken by cycling through active players / cockpits: %3%") % __FILE__ % __LINE__ % (cycleThroughPlayersEndTime - cycleThroughPlayersStartTime)));
double cycleThroughPlayersEndTime = realTime();
VS_LOG(trace, (boost::format("%1% %2%: Time taken by cycling through active players / cockpits: %3%") % __FILE__ % __LINE__ % (cycleThroughPlayersEndTime - cycleThroughPlayersStartTime)));
}
if (sigIter.isDone()) {
sigIter = draw_list.createIterator();
Expand Down

0 comments on commit 46aedb5

Please sign in to comment.