Skip to content

Commit

Permalink
Merge pull request #4 from CppAndre/Develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
CppAndre committed Aug 30, 2016
2 parents 916d787 + 4f7b990 commit d9ede29
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/Prey/ai_sphereboss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ idProjectile *hhSphereBoss::LaunchProjectile( const char *jointname, idEntity *t
}

void hhSphereBoss::Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location ) {
//PreyRun BEGIN
// PreyRun BEGIN
if (pr_timer_running && pr_autostop.GetBool())
{
pr_Timer.Stop();
Expand All @@ -214,7 +214,7 @@ void hhSphereBoss::Killed( idEntity *inflictor, idEntity *attacker, int damage,
gameLocal.Printf("PreyRun: Timer: End game, time: %02d:%02d:%02d.%03d\n",times.hours,times.minutes,times.seconds,times.milliseconds);

}
//PreyRun END
// PreyRun END

HandleNoGore();
if ( !AI_DEAD ) {
Expand Down
52 changes: 29 additions & 23 deletions src/Prey/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,11 +1070,24 @@ void hhPlayer::DrawHUD(idUserInterface *_hud) {

#ifdef PR_DEBUG
auto time = PR_ms2time(pr_Timer.Milliseconds());
gameLocal.Printf("PreyRunDGB: Time: %02d:%02d:%02d.%03d\n", time.hours, time.minutes, time.seconds, time.milliseconds);
gameLocal.Printf("PreyRunDBG: Time: %02d:%02d:%02d.%03d\n", time.hours, time.minutes, time.seconds, time.milliseconds);

gameLocal.Printf("PreyRun Debug: Changed map to: %s\n", gameLocal.GetMapName());
#endif // PR_DEBUG
}

if (pr_preysplit.GetBool())
{
pr::WriteTime(pr::GetTime());
}

if (pr_demo_timer_running && !pr_demo_timer.IsRunning())
{
pr_demo_timer.Start();
#ifdef PR_DEBUG
gameLocal.Printf("PreyRunDBG: Starting demo timing\n");
#endif // PR_DEBUG
}
// PreyRun END

if (guiOverlay) {
Expand Down Expand Up @@ -1183,11 +1196,12 @@ void hhPlayer::DrawHUD(idUserInterface *_hud) {
auto vel = physicsObj.GetLinearVelocity();

idStr strText;

// Uses InVehicle now
if (physicsObj.HasGroundContacts() || InVehicle())
{
// are we standing on the ground or in a Vehicle? then add Z speed as well (when wallwalking, being on stairs/slopes or flying in Vehicle)
sprintf(strText, "%.2f", vel.Length());
sprintf(strText, "%.2f", vel.Length()); // vel.Lenght() == idMath::Sqrt(vel.x * vel.x + vel.y * vel.y + vel.z * vel.z)
}
else
{
Expand Down Expand Up @@ -1247,7 +1261,7 @@ void hhPlayer::DrawHUD(idUserInterface *_hud) {
renderSystem->DrawSmallStringExt(500, 80, velXYZ, idVec4(1, 1, 1, 1), false, declManager->FindMaterial("textures/bigchars"));
}

// Position
// Location
if (_hud->GetStateBool("pr_hud_location", "0"))
{
auto eyePos = GetEyePosition();
Expand Down Expand Up @@ -1275,9 +1289,9 @@ void hhPlayer::DrawHUD(idUserInterface *_hud) {

start = GetEyePosition();

// end the traceline 768 units ahead in the direction we're viewing
// end the traceline 2048 units ahead in the direction we're viewing

end = start + viewAngles.ToForward() * 768.0f;
end = start + viewAngles.ToForward() * 2048.0f;

// perform the traceline and store the results in trace
// stop the trace for monsters and players
Expand All @@ -1296,15 +1310,20 @@ void hhPlayer::DrawHUD(idUserInterface *_hud) {
// gameLocal.GetTraceEntity returns the entity's master entity if it exists
// search the SDK for more examples

int health = ent->health;
int health = ent->GetHealth();
int maxHealth = ent->GetMaxHealth();

if (health > 0 && maxHealth > 0)
{
idStr strHealth;
sprintf(strHealth, "Health: %d/%d", ent->health, ent->GetMaxHealth());
//sprintf(strName, "Name: %s", ent->name); // crashes
sprintf(strHealth, "Health: %03d/%03d", ent->health, ent->GetMaxHealth());

renderSystem->DrawSmallStringExt(360, 235, strHealth, idVec4(1, 1, 1, 1), false, declManager->FindMaterial("textures/bigchars"));

idStr strName;
sprintf(strName, "Name: %s", ent->GetName());

renderSystem->DrawSmallStringExt(360, 220, strName, idVec4(1, 1, 1, 1), false, declManager->FindMaterial("textures/bigchars"));
}
}
}
Expand Down Expand Up @@ -1484,12 +1503,13 @@ void hhPlayer::DrawHUD(idUserInterface *_hud) {
}

// Health
// PR_FIXME: Get health of shuttle
if (_hud->GetStateBool("pr_hud_health", "0"))
{
idStr strHealth;
idVec4 color;

// Player is dead
// Player is alive, Dead != Deathwalking
if (!IsDead())
{
auto health = GetHealth();
Expand Down Expand Up @@ -1527,20 +1547,6 @@ void hhPlayer::DrawHUD(idUserInterface *_hud) {
}

// PreyRun BEGIN
// converts the 0-255 format to the 0-1 format used by the DrawSmallStringExt function
//PR_time_t PR_ms2time(unsigned x)
//{
// PR_time_t ts;
// ts.hours = x / (60 * 60 * 1000);
// x = x - ts.hours*(60 * 60 * 1000);
// ts.minutes = x / (60 * 1000);
// x = x - ts.minutes*(60 * 1000);
// ts.seconds = x / 1000;
// ts.milliseconds = x - ts.seconds * 1000;
//
// return ts;
//}

inline float PR_calcStuff(float f)
{
return f / 255;
Expand Down
17 changes: 15 additions & 2 deletions src/Prey/prey_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,27 @@ void hhGameLocal::MapShutdown( void ) {
{
gameLocal.Printf("PreyRun: Timer: Paused, Map Shutdown\n");
pr_Timer.Stop();

#ifdef PR_DEBUG
auto time = PR_ms2time(pr_Timer.Milliseconds());
gameLocal.Printf("PreyRunDGB: Time: %02d:%02d:%02d.%03d\n", time.hours, time.minutes, time.seconds, time.milliseconds);
gameLocal.Printf("PreyRunDBG: Time: %02d:%02d:%02d.%03d\n", time.hours, time.minutes, time.seconds, time.milliseconds);
#endif // PR_DEBUG

// now done in idGameLocal::InitFromNewMap
/*pr::WriteMapChange(pr::GetTime(),(idStr) GetMapName());*/
}

if (pr_demo_timer_running&&pr_demo_timer.IsRunning())
{
pr_demo_timer.Stop();
#ifdef PR_DEBUG
gameLocal.Printf("PreyRunDBG: Stopping demo Timer\n");
#endif // PR_DEBUG
}

#ifdef PR_DEBUG
gameLocal.Printf("PreyRunDBG: Leaving map:%s\n", gameLocal.GetMapName());
#endif
// PreyRun END

//HUMANHEAD: mdc - added support for automatically dumping stats on map switch/game exit
Expand Down Expand Up @@ -909,7 +922,7 @@ gameReturn_t hhGameLocal::RunFrame( const usercmd_t *clientCmds ) {
timer_think.Milliseconds(), timer_events.Milliseconds(), num );
}

// build the return value
// build the return value
ret.consistencyHash = 0;
ret.sessionCommand[0] = 0;

Expand Down
27 changes: 26 additions & 1 deletion src/PreyRun/interprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,38 @@ namespace pr
WritePreySplit(buf);
}

void WriteTime(const Time& time)
{
std::vector<char> buf(10);
buf[0] = static_cast<char>(buf.size());
buf[1] = static_cast<char>(MessageType::TIME);
AddTimeToBuffer(buf.data() + 2, time);

if (pr_preysplit_update.GetFloat() > 0.0f)
{
static auto last_time = std::chrono::steady_clock::now() - std::chrono::milliseconds(static_cast<long long>(1000 / pr_preysplit_update.GetFloat()) + 1);

auto now = std::chrono::steady_clock::now();

if (now >= last_time + std::chrono::milliseconds(static_cast<long long>(1000 / pr_preysplit_update.GetFloat())))
{
WritePreySplit(buf);
last_time = now;
}
}
else
{
WritePreySplit(buf);
}
}

void WriteMapChange(const Time& time, idStr& map)
{
// normal map path : maps/game/roadhouse.map
// gets turneded into: roadhouse.map
map.Replace("maps/game/", "");
#ifdef PR_DEBUG
gameLocal.Printf("PreyRunDBG: WriteMapChange: Map exited: %s\nPreyRunDGB: WriteMapChange: Time %02d:%02d:%02d.%03d\n", map.c_str(), time.hours, time.minutes, time.seconds, time.milliseconds);
gameLocal.Printf("PreyRunDBG: WriteMapChange: Map exited: %s\nPreyRunDBG: WriteMapChange: Time %02d:%02d:%02d.%03d\n", map.c_str(), time.hours, time.minutes, time.seconds, time.milliseconds);
#endif // PR_DEBUG

int32_t size = static_cast<int32_t>(map.Size());
Expand Down
5 changes: 4 additions & 1 deletion src/PreyRun/interprocess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <vector>
#include <cstring>
#include <chrono>

#define PREYSPLIT_PIPE_NAME "PreyRun-PreySplit"

Expand All @@ -38,7 +39,7 @@ namespace pr
GAMEEND = 0x00,
MAPCHANGE = 0x01,
TIMER_RESET = 0x02,
TIMER_START = 0x03,
TIMER_START = 0x03
};

struct Time
Expand All @@ -52,6 +53,8 @@ namespace pr
void InitPreySplitPipe();
void ShutdownPreySplitPipe();

void WriteTime(const Time& time);

void WriteGameEnd(const Time& time);
void WriteMapChange(const Time& time, idStr& map);
void WriteTimerReset(const Time& time);
Expand Down
4 changes: 4 additions & 0 deletions src/game/Game_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,10 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo
idEntity *ent;
idDict si;

#ifdef PR_DEBUG
gameLocal.Printf("PreyRun DBG: Loading savegame %s from map %s\n",saveGameFile->GetName(),mapName);
#endif // PR_DEBUG

if ( mapFileName.Length() ) {
MapShutdown();
}
Expand Down
14 changes: 5 additions & 9 deletions src/game/gamesys/SysCmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ void Cmd_PR_TimeDemo_f(const idCmdArgs &args)
const char *demoName;
demoName = args.Argv(1);

auto startTime = gameLocal.GetTime();
gameLocal.Printf("Start time: %u\n", startTime);
pr_demo_timer.Clear();
pr_demo_timer_running = true;

cmdSystem->BufferCommandText(CMD_EXEC_NOW, va("playDemo %s", demoName));

auto endTime = gameLocal.GetTime();
gameLocal.Printf("End time: %u\n", endTime);
auto times = PR_ms2time(pr_demo_timer.Milliseconds());

gameLocal.Printf("Demo took: %u milliseconds\n", (endTime - startTime));
gameLocal.Printf("Demoplayback: %02d:%02d:%02d.%03d\n", times.hours, times.minutes, times.seconds, times.milliseconds);
}

/*
Expand Down Expand Up @@ -73,8 +72,6 @@ void Cmd_PR_timer_Start_f(const idCmdArgs &args)
pr_Timer.Start();
pr_timer_running = true;

pr::WriteTimerStart(pr::GetTime());

gameLocal.Printf("Starting timer\n");
}

Expand Down Expand Up @@ -122,7 +119,6 @@ void Cmd_PR_test_f(const idCmdArgs &args)
{
auto player = gameLocal.GetLocalPlayer();
gameLocal.Printf("clip:%d\navail:%d\naltclip:%d\naltavail:%d\nzoomfov:%d\n", player->weapon->AmmoInClip(), player->weapon->AmmoAvailable(), player->weapon->AltAmmoInClip(), player->weapon->AltAmmoAvailable(), player->weapon->GetZoomFov());

}

void Cmd_PR_dgb_timer_f(const idCmdArgs &args)
Expand Down Expand Up @@ -2880,7 +2876,7 @@ void idGameLocal::InitConsoleCommands(void) {
// DEBUG COMMANDS
#ifdef PR_DEBUG
cmdSystem->AddCommand("PR_Test", Cmd_PR_test_f, CMD_FL_GAME, "For testing purpose");
cmdSystem->AddCommand("PR_dgb_timer", Cmd_PR_dgb_timer_f, CMD_FL_GAME, "Prints timer stats");
cmdSystem->AddCommand("PR_dgb_timer", Cmd_PR_dgb_timer_f, CMD_FL_GAME, "PreyRun Debug cmd: Prints timer stats");
#endif // PR_DEBUG

// PreyRun END
Expand Down
5 changes: 4 additions & 1 deletion src/game/gamesys/SysCvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All game cvars should be defined here.
idCVar pr_autojump("PR_AutoJump", "0", CVAR_GAME | CVAR_BOOL | CVAR_ARCHIVE, "automaticly jumps when holding spacebar");
idCVar pr_autopause("PR_AutoPause", "0", CVAR_GAME | CVAR_BOOL, "Automaticly pauses after map load");
idCVar pr_preysplit("PR_PreySplit", "1", CVAR_GAME | CVAR_BOOL | CVAR_ARCHIVE, "Enables support for interaction with PreySplit a LiveSplit component");
idCVar pr_preysplit_update("PR_PreySplit_update", "41", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "The time in milliseconds PreyRun shoud update the game timer of PreySplit",0,1000);

// HUD BEGIN

Expand All @@ -31,7 +32,7 @@ idCVar pr_hud_speedometer("PR_hud_Speedometer", "0", CVAR_GAME | CVAR_BOOL | CVA
idCVar pr_hud_speedometer_r("PR_hud_Speedometer_R", "255", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "Defines the red value of the speedometer 0-255",0,255);
idCVar pr_hud_speedometer_g("PR_hud_Speedometer_G", "255", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "Defines the green value of the speedometer 0-255",0,255);
idCVar pr_hud_speedometer_b("PR_hud_Speedometer_B", "63.75", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "Defines the blue value of the speedometer 0-255",0,255);
idCVar pr_hud_speedometer_precision("PR_hud_Speedometer_Precision", "6", CVAR_GAME | CVAR_INTEGER /*| CVAR_ARCHIVE*/, "the amount of number shown after the comma 0-6",0,6);
idCVar pr_hud_speedometer_precision("PR_hud_Speedometer_Precision", "6", CVAR_GAME | CVAR_INTEGER /*| CVAR_ARCHIVE*/, "the amount of numbers shown after the comma 0-6",0,6);
idCVar pr_hud_speedometer_x("PR_hud_Speedometer_x", "310", CVAR_GAME | CVAR_INTEGER | CVAR_ARCHIVE, "position of the speedometer x coordinate 0-639",0,639);
idCVar pr_hud_speedometer_y("PR_hud_Speedometer_y", "460", CVAR_GAME | CVAR_INTEGER | CVAR_ARCHIVE, "posiont of the speedometer y coordinate 0-479",0,479);

Expand All @@ -43,6 +44,8 @@ idCVar pr_hud_velocity("PR_hud_Velocity", "0", CVAR_GAME | CVAR_BOOL, "Shows inf

// Timer
idTimer pr_Timer; // The actual timer
idTimer pr_demo_timer;
bool pr_demo_timer_running;
bool pr_timer_running = false;

idCVar pr_autostart("PR_Timer_AutoStart", "1", CVAR_GAME | CVAR_BOOL | CVAR_ARCHIVE, "Automaticly start the hud timer at run begin");
Expand Down
3 changes: 3 additions & 0 deletions src/game/gamesys/SysCvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
extern idCVar pr_autojump;
extern idCVar pr_autopause;
extern idCVar pr_preysplit;
extern idCVar pr_preysplit_update;
// Speedometer
extern idCVar pr_hud_speedometer;
extern idCVar pr_hud_speedometer_r;
Expand All @@ -22,7 +23,9 @@ extern idCVar pr_hud_viewangles;
extern idCVar pr_hud_velocity;
// Timer
extern idTimer pr_Timer;
extern idTimer pr_demo_timer;
extern bool pr_timer_running;
extern bool pr_demo_timer_running;

extern idCVar pr_autostart;
extern idCVar pr_autostop;
Expand Down

0 comments on commit d9ede29

Please sign in to comment.