Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "DevShotGenerator.h"
  7. #include "cmd.h"
  8. #include "fmtstr.h"
  9. #include "host.h"
  10. #include "tier0/icommandline.h"
  11. #include <tier0/dbg.h>
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. #define PAUSE_FRAMES_BETWEEN_MAPS 300
  15. #define PAUSE_TIME_BETWEEN_MAPS 2.0f
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. //-----------------------------------------------------------------------------
  19. void DevShotGenerator_Usage()
  20. {
  21. //
  22. Msg( "-makedevshots usage:\n" );
  23. Msg( " [ -usedevshotsfile filename ] -- get map list from specified file, default is to build for maps/*.bsp\n" );
  24. Msg( " [ -startmap mapname ] -- restart generation at specified map (after crash, implies resume)\n" );
  25. Msg( " [ -condebug ] -- prepend console.log entries with mapname or engine if not in a map\n" );
  26. Msg( " [ +map mapname ] -- generate devshots for specified map and exit after that map\n" );
  27. }
  28. void DevShotGenerator_Init()
  29. {
  30. // check for devshot generation
  31. if ( CommandLine()->FindParm("-makedevshots") )
  32. {
  33. bool usemaplistfile = false;
  34. if ( CommandLine()->FindParm("-usedevshotsfile") )
  35. {
  36. usemaplistfile = true;
  37. }
  38. DevShotGenerator().EnableDevShotGeneration( usemaplistfile );
  39. }
  40. }
  41. void DevShotGenerator_Shutdown()
  42. {
  43. DevShotGenerator().Shutdown();
  44. }
  45. void DevShotGenerator_BuildMapList()
  46. {
  47. DevShotGenerator().BuildMapList();
  48. }
  49. CDevShotGenerator g_DevShotGenerator;
  50. CDevShotGenerator &DevShotGenerator()
  51. {
  52. return g_DevShotGenerator;
  53. }
  54. void CL_DevShots_NextMap()
  55. {
  56. DevShotGenerator().NextMap();
  57. }
  58. static ConCommand devshots_nextmap( "devshots_nextmap", CL_DevShots_NextMap, "Used by the devshots system to go to the next map in the devshots maplist." );
  59. //-----------------------------------------------------------------------------
  60. // Purpose: Constructor
  61. //-----------------------------------------------------------------------------
  62. CDevShotGenerator::CDevShotGenerator()
  63. {
  64. m_bUsingMapList = false;
  65. m_bDevShotsEnabled = false;
  66. m_iCurrentMap = 0;
  67. }
  68. void CDevShotGenerator::BuildMapList()
  69. {
  70. if ( !m_bDevShotsEnabled )
  71. return;
  72. DevShotGenerator_Usage();
  73. // Get the maplist file, if any
  74. const char *pMapFile = NULL;
  75. CommandLine()->CheckParm( "-usedevshotsfile", &pMapFile );
  76. // Build the map list
  77. if ( !BuildGeneralMapList( &m_Maps, CommandLine()->FindParm("-usedevshotsfile") != 0, pMapFile, "devshots", &m_iCurrentMap ) )
  78. {
  79. m_bDevShotsEnabled = false;
  80. }
  81. }
  82. void CDevShotGenerator::NextMap()
  83. {
  84. if ( !m_bDevShotsEnabled )
  85. return;
  86. //Msg("DEVSHOTS: Nextmap command received.\n");
  87. if (m_Maps.IsValidIndex(m_iCurrentMap))
  88. {
  89. //Msg("DEVSHOTS: Switching to %s (%d).\n", m_Maps[m_iCurrentMap].name, m_iCurrentMap );
  90. CFmtStr str("map %s\n", m_Maps[m_iCurrentMap].name);
  91. Cbuf_AddText( str.Access() );
  92. ++m_iCurrentMap;
  93. }
  94. else
  95. {
  96. //Msg("DEVSHOTS: Finished on map %d.\n", m_iCurrentMap);
  97. // no more levels, just quit
  98. Cbuf_AddText( "quit\n" );
  99. }
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose: initializes the object to enable dev shot generation
  103. //-----------------------------------------------------------------------------
  104. void CDevShotGenerator::EnableDevShotGeneration( bool usemaplistfile )
  105. {
  106. m_bUsingMapList = usemaplistfile;
  107. m_bDevShotsEnabled = true;
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose: starts the first map
  111. //-----------------------------------------------------------------------------
  112. void CDevShotGenerator::StartDevShotGeneration()
  113. {
  114. BuildMapList();
  115. CFmtStr str("map %s\n", m_Maps[m_iCurrentMap].name);
  116. Cbuf_AddText( str.Access() );
  117. ++m_iCurrentMap;
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Purpose:
  121. //-----------------------------------------------------------------------------
  122. void CDevShotGenerator::Shutdown()
  123. {
  124. }