1 /** @file api_base.h Public Base API.
2  * @ingroup base
3  *
4  * @authors Copyright © 2012-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
5  * @authors Copyright © 2013 Daniel Swanson <danij@dengine.net>
6  *
7  * @par License
8  * GPL: http://www.gnu.org/licenses/gpl.html
9  *
10  * <small>This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by the
12  * Free Software Foundation; either version 2 of the License, or (at your
13  * option) any later version. This program is distributed in the hope that it
14  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details. You should have received a copy of the GNU
17  * General Public License along with this program; if not, see:
18  * http://www.gnu.org/licenses</small>
19  */
20 
21 #ifndef DOOMSDAY_API_BASE_H
22 #define DOOMSDAY_API_BASE_H
23 
24 #include <de/str.h>
25 #include <doomsday/resource/resourceclass.h>
26 #include <doomsday/game.h>
27 #include "apis.h"
28 #include "api_uri.h"
29 
30 /// @addtogroup game
31 /// @{
32 
33 /**
34  * Extended info about a registered game component.
35  * @see DD_GameInfo() @ingroup game
36  */
37 typedef struct gameinfo_s {
38     AutoStr *title;
39     AutoStr *author;
40     AutoStr *identityKey;
41 } GameInfo;
42 
43 /// @}
44 
45 // The Base API.
DENG_API_TYPEDEF(Base)46 DENG_API_TYPEDEF(Base)
47 {
48     de_api_t api;
49 
50     void (*Quit)(void);
51 
52     int (*GetInteger)(int ddvalue);
53     void (*SetInteger)(int ddvalue, int parm);
54     void *(*GetVariable)(int ddvalue);
55     void (*SetVariable)(int ddvalue, void *ptr);
56 
57     /**
58      * Register a new game.
59      *
60      * @param definition  GameDef structure defining the new game.
61      *
62      * @return  Unique identifier/name assigned to resultant game.
63      *
64      * @note Game registration order defines the order of the automatic game
65      * identification/selection logic.
66      */
67     //gameid_t (*DefineGame)(GameDef const *definition);
68 
69     /**
70      * Adds a new resource to the list for the identified @a game.
71      *
72      * @note Resource order defines the load order of resources (among those of
73      * the same type). Resources are loaded from most recently added to least
74      * recent.
75      *
76      * @param game      Unique identifier/name of the game.
77      * @param classId   Class of resource being defined.
78      * @param fFlags    File flags (see @ref fileFlags).
79      * @param names     One or more known potential names, seperated by semicolon
80      *                  (e.g., <pre> "name1;name2" </pre>). Valid names include
81      *                  absolute or relative file paths, possibly with encoded
82      *                  symbolic tokens, or predefined symbols into the virtual
83      *                  file system.
84      * @param params    Additional parameters. Usage depends on resource type.
85      *                  For package resources this may be C-String containing a
86      *                  semicolon delimited list of identity keys.
87      */
88     //void (*AddGameResource)(gameid_t game, resourceclassid_t classId, int fFlags,
89     //                        char const *names, void const *params);
90 
91     /**
92      * Retrieve extended info about the current game.
93      *
94      * @param info      Info structure to be populated.
95      *
96      * @return          @c true if successful else @c false (i.e., no game loaded).
97      */
98     dd_bool (*GameInfo_)(GameInfo *info);
99 
100     /**
101      * Determines whether the current run of the thinkers should be considered a
102      * "sharp" tick. Sharp ticks occur exactly 35 times per second. Thinkers may be
103      * called at any rate faster than this; in order to retain compatibility with
104      * the original Doom engine game logic that ran at 35 Hz, such logic should
105      * only be executed on sharp ticks.
106      *
107      * @return @c true, if a sharp tick is currently in effect.
108      *
109      * @ingroup playsim
110      */
111     dd_bool (*IsSharpTick)(void);
112 
113     /**
114      * Send a packet over the network.
115      *
116      * @param to_player  Player number to send to. The server is number zero.
117      *                   May include @ref netSendFlags.
118      * @param type       Type of the packet.
119      * @param data       Data of the packet.
120      * @param length     Length of the data.
121      */
122     void (*SendPacket)(int to_player, int type, void const *data, size_t length);
123 
124     /**
125      * To be called by the game after loading a save state to instruct the engine
126      * perform map setup once more.
127      */
128     void (*SetupMap)(int mode, int flags);
129 }
130 DENG_API_T(Base);
131 
132 #ifndef DENG_NO_API_MACROS_BASE
133 #define Sys_Quit                  _api_Base.Quit
134 #define DD_GetInteger             _api_Base.GetInteger
135 #define DD_SetInteger             _api_Base.SetInteger
136 #define DD_GetVariable            _api_Base.GetVariable
137 #define DD_SetVariable            _api_Base.SetVariable
138 //#define DD_DefineGame             _api_Base.DefineGame
139 //#define DD_GameIdForKey           _api_Base.GameIdForKey
140 //#define DD_AddGameResource        _api_Base.AddGameResource
141 #define DD_GameInfo               _api_Base.GameInfo_
142 #define DD_IsSharpTick            _api_Base.IsSharpTick
143 #define Net_SendPacket            _api_Base.SendPacket
144 #define R_SetupMap                _api_Base.SetupMap
145 #endif
146 
147 #ifdef __DOOMSDAY__
148 DENG_USING_API(Base);
149 #endif
150 
151 #endif // DOOMSDAY_API_BASE_H
152