mtask.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. #ifndef MTASK_H
  19. #define MTAST_H
  20. //////////////////////////////////////////////////////////////////////
  21. //
  22. // MTask.h
  23. //
  24. // Multitasking module for game run routines
  25. //
  26. // Created On: 10/18/96 BRH
  27. // Implemented:10/18/96 BRH
  28. //
  29. //////////////////////////////////////////////////////////////////////
  30. #include "System.h"
  31. #ifdef PATHS_IN_INCLUDES
  32. #include "ORANGE/CDT/List.h"
  33. #else
  34. #include "LIST.H"
  35. #endif // PATHS_IN_INCLUDES
  36. //////////////////////////////////////////////////////////////////////
  37. // Task Info Structure
  38. //////////////////////////////////////////////////////////////////////
  39. typedef struct tag_TaskInfo
  40. {
  41. long* plStackAddress; // Address of allocated memory for stack
  42. long* plSP; // Current saved position of Stack Pointer
  43. char* pszFunctionName; // Name of task using this stack
  44. // (used for reporting errors)
  45. } TASKINFO, *PTASKINFO;
  46. //////////////////////////////////////////////////////////////////////
  47. // Function prototypes
  48. //////////////////////////////////////////////////////////////////////
  49. // This is the function to run all of the tasks once. It
  50. // should be called in the main loop of the game
  51. void MTaskManager(void);
  52. // This is used to add tasks to be processed by
  53. // MTaskManager. Note only tasks designed for
  54. // this module should be added. Tasks should
  55. // never return and need to call MTaskWait
  56. // periodically.
  57. short MTaskAddFunc(void* pFunction, char* pszFuncName, short sStackSize = 1024);
  58. #define MTaskAddwSize(fnTask, sStackSz) MTaskAddFunc(fnTask, #fnTask, sStackSz)
  59. #define MTaskAdd(fnTask) MTaskAddFunc(fnTask, #fnTask);
  60. // This is used to remove tasks from the task list.
  61. // Only call this function from within the task's process
  62. // since it kills the currently running task and removes
  63. // it from the list.
  64. // This is what should be called when you no longer wish
  65. // to run a task. For example if the task is character
  66. // logic, it would normally loop until the guy got killed.
  67. // When he is killed, call MTaskKill to remove it from
  68. // the task processing list.
  69. void MTaskKill(void);
  70. // This funciton is to be called from within the task's
  71. // process. It is used to allow other tasks to be run.
  72. // This funciton must be called periodically to allow the
  73. // other tasks to run. Your code will resume immediately
  74. // after this call.
  75. long* MTaskWait(void);
  76. #endif // MTASK_H
  77. //////////////////////////////////////////////////////////////////////
  78. // EOF
  79. //////////////////////////////////////////////////////////////////////