PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/renderer.h

http://infon.googlecode.com/
C Header | 192 lines | 82 code | 50 blank | 60 comment | 0 complexity | 32ae7c7c2939152c310fee29244041bf MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. Copyright (c) 2006 Florian Wesch <fw@dividuum.de>. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation, Inc.,
  13. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  14. */
  15. #ifndef RENDERER_H
  16. #define RENDERER_H
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include "client_creature.h"
  21. #include "client_player.h"
  22. #include "client_world.h"
  23. #define RENDERER_API_VERSION 4
  24. typedef struct {
  25. /* the renderer version number. set this to RENDERER_API_VERSION. */
  26. int version;
  27. /* called once before other rendering function. should initialize a new
  28. * output with size w x h and fullscreen if fs is set. should return 1
  29. * if successfull, 0 on failure. */
  30. int (*open )(int w, int h, int fs);
  31. /* called once before the client exits. do cleanups here */
  32. void (*close)(void);
  33. /* called for every frame. game_time and delta contain game time and delta
  34. * to previous frame in milliseconds */
  35. void (*tick)(int game_time, int delta);
  36. /* called if the world changes its size (at startup or on level change). */
  37. void (*world_info_changed)(const client_world_info_t *info);
  38. /* called for every world_tile that changed (from being solid) */
  39. void (*world_changed )(int x, int y);
  40. /* called after a player joins the game. you can return any pointer, which will
  41. * then be saved in player->userdata */
  42. void *(*player_joined )(const client_player_t *player);
  43. /* called if some player value changed */
  44. void (*player_changed )(const client_player_t *player, int changed);
  45. /* called before a player leaves the game */
  46. void (*player_left )(const client_player_t *player);
  47. /* called after a new creature spawned. you can return any pointer, which will
  48. * then be saved in creature->userdata */
  49. void *(*creature_spawned)(const client_creature_t *creature);
  50. /* called if some creature value changed */
  51. void (*creature_changed)(const client_creature_t *creature, int changed);
  52. /* called before a creature died */
  53. void (*creature_died )(const client_creature_t *creature);
  54. /* called for each (scroll?) message. */
  55. void (*scroll_message )(const char *message);
  56. } renderer_api_t;
  57. typedef struct {
  58. /* infon version string */
  59. const char *version;
  60. /* maximum number of players. */
  61. int max_players;
  62. /* maximum number of creatures. */
  63. int max_creatures;
  64. /* calls function 'callback' for each creature in the game. opaque is passed to the callback function. */
  65. void (*each_creature)(void (*callback)(const client_creature_t *creature, void *opaque), void *opaque);
  66. /* calls function 'callback' for each player in the game. opaque is passed to the callback function. */
  67. void (*each_player )(void (*callback)(const client_player_t *player, void *opaque), void *opaque);
  68. /* returns information on creature num or NULL if creature does not exist. */
  69. const client_creature_t* (*get_creature)(int num);
  70. /* returns information on player num or NULL or the player does not exist. */
  71. const client_player_t* (*get_player )(int num);
  72. /* returns player information on the current king player or NULL if there is no king. */
  73. const client_player_t* (*get_king )();
  74. /* returns a pointer to world_with * world_height world tile information or NULL
  75. * if there is no world. you can reuse the returned pointer during one tick */
  76. const client_maptile_t * (*get_world )();
  77. /* returns information about the current world or NULL if there is no world. */
  78. const client_world_info_t* (*get_world_info)();
  79. /* returns information on world tile at x, y. must not be called if there
  80. * is no world. x and y must be within world coordinates. */
  81. const client_maptile_t * (*get_world_tile)(int x, int y);
  82. /* returns the current intermission message or NULL if there
  83. * is no message. */
  84. const char * (*get_intermission)();
  85. /* return the amount of network traffic the client received. */
  86. int (*get_traffic)();
  87. /* tell the infon client to shutdown. */
  88. void (*shutdown)();
  89. /* write a string to the server */
  90. void (*printf)(const char *fmt, ...);
  91. /* Is it a demo replay? */
  92. int (*is_demo)();
  93. } infon_api_t;
  94. /* the function called after loading the renderer. it receives the infon api and must
  95. * return the renderer api. */
  96. typedef const renderer_api_t *(*render_loader)(const infon_api_t *);
  97. /* api provided by infon */
  98. extern const infon_api_t *infon;
  99. #ifdef WIN32
  100. #define RENDERER_EXPORT_SPEC __declspec(dllexport)
  101. #else
  102. #define RENDERER_EXPORT_SPEC
  103. #endif
  104. #ifdef __cplusplus
  105. #define RENDERER_EXTERN_SPEC extern "C"
  106. #else
  107. #define RENDERER_EXTERN_SPEC extern
  108. #endif
  109. #define RENDERER_SYM renderer_load
  110. RENDERER_EXPORT_SPEC RENDERER_EXTERN_SPEC
  111. const renderer_api_t *RENDERER_SYM (const infon_api_t *api);
  112. #define RENDERER_EXPORT(renderer) \
  113. const infon_api_t *infon; \
  114. RENDERER_EXPORT_SPEC RENDERER_EXTERN_SPEC \
  115. const renderer_api_t *RENDERER_SYM (const infon_api_t *api) { \
  116. infon = api; return &(renderer); \
  117. }
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. /* infon seitige API */
  122. int renderer_init(const char *name);
  123. void renderer_shutdown();
  124. int renderer_open(int w, int h, int fs);
  125. void renderer_close();
  126. void renderer_tick(int game_time, int delta);
  127. void renderer_world_info_changed(const client_world_info_t *info);
  128. void renderer_world_changed (int x, int y);
  129. void renderer_player_joined (client_player_t *player);
  130. void renderer_player_changed (const client_player_t *player, int changed);
  131. void renderer_player_left (const client_player_t *player);
  132. void renderer_creature_spawned (client_creature_t *creature);
  133. void renderer_creature_changed (const client_creature_t *creature, int changed);
  134. void renderer_creature_died (const client_creature_t *creature);
  135. void renderer_scroll_message(const char *buf);
  136. int renderer_wants_shutdown();
  137. #endif