Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
Environment.h
Go to the documentation of this file.
1 /*
2  Harmonic Flow Framework
3  Copyright (C) 2011-2018 Andreas Widen <andreas@harmonicflow.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #pragma once
22 
23 /** @file
24  * @brief Singleton interface for platform specific things.
25 */
26 
27 #include "debug/CrtDbgInc.h"
28 
29 #include <string>
30 #include <stdio.h>
31 #include <map>
32 
33 #include "ThreadListener.h"
34 
35 #include "platform/Geometry.h"
36 #include "unicode/UString.h"
37 #include "boundary/Rect.h"
38 #include "vector/Vector2.h"
39 #include "HFDataTypes.h"
40 #include "zlib/zlib.h"
41 #include "util/StringUtil.h"
42 
43 /**
44  * @brief HFCore::Mouse max count to initialize.
45  */
46 #define MOUSE_COUNT_MAX 1
47 
48 /**
49  * @brief HFCore::Touch max count to initialize.
50  *
51  * @note iOS and Android only at this point.
52  */
53 #define TOUCH_COUNT_MAX 1 // no multi touch yet.
54 
55 /**
56  * @brief HFCore::GamePad max count to initialize.
57  */
58 #define GAMEPAD_COUNT_MAX 4
59 
60 /**
61  * @brief HFCore::Mouse double click delay in milliseconds.
62  */
63 #define DOUBLE_CLICK_MAX_DELAY 400
64 
65 /**
66  * @brief Get HFCore::Environment instance shortcut macro.
67  */
68 #define HFCORE_ENV HFCore::Environment::instance()
69 
70 /**
71  * @brief Get HFCore::ResourceManager instance shortcut macro.
72  */
73 #define HFCORE_RESMGR HFCORE_ENV->getResourceManager()
74 
75 /**
76  * @brief Get HFCore::WidgetManager instance shortcut macro.
77  */
78 #define HFCORE_WIDMGR HFCORE_ENV->getWidgetManager()
79 
80 /**
81  * @brief Get HFCore::FileDirUtils instance shortcut macro.
82  */
83 #define HFCORE_FDU HFCORE_ENV->getFileDirUtils()
84 
85 /**
86  * @brief Get HFCore::Preferences instance shortcut macro.
87  */
88 #define HFCORE_PREF HFCORE_ENV->getPreferencesManager()
89 
90 /**
91  * @brief Get HFCore::Storage instance shortcut macro.
92  */
93 #define HFCORE_STORAGE HFCORE_ENV->getStorage()
94 
95 /**
96  * @brief Get HFCore::PersistenceLayer instance shortcut macro.
97  */
98 #define HFCORE_PERSLAY HFCORE_ENV->getPersistenceLayer()
99 
100 /**
101  * @brief Get HFCore::WebManager instance shortcut macro.
102  */
103 #define HFCORE_WEBMGR HFCORE_ENV->getWebManager()
104 
105 /**
106  * @brief Get HFCore::ActorManager instance shortcut macro.
107  */
108 #define HFCORE_ACTMGR HFCORE_ENV->getActorManager()
109 
110 /**
111  * @brief Get HFCore::SoundPlayer instance shortcut macro.
112  */
113 #define HFCORE_SOUND HFCORE_ENV->getSoundPlayer()
114 
115 /**
116  * @brief Get HFCore::Camera instance shortcut macro.
117  */
118 #define HFCORE_CAMERA HFCORE_ENV->getCamera()
119 
120 namespace HFCore
121 {
122  class Game;
123  class GamePad;
124  class Graphics;
125  class Image;
126  class Keyboard;
127  class Mouse;
128  class Touch;
129  class PersistenceLayer;
130  class ResourceManager;
131  class WidgetManager;
132  class FileDirUtils;
133  class Preferences;
134  class WebManager;
135  class ActorManager;
136  class Camera;
137  class Sound;
138  class SoundPlayer;
139  class Storage;
140  class Font;
141 
142  /**
143  * @brief Singleton interface for platform specific things.
144  *
145  * Environment drives the main loop and offers access to platform
146  * interfaces, logging, timing, window management, controllers add/remove,
147  * game config, threads, cursor handling, screensaver, clipboard, image
148  * loading, preferences etc. Basically all platform specific things will
149  * land in the Environment interface.
150  */
152  {
153  public:
154  /**
155  * @brief Environment singleton instance.
156  *
157  * @return Environment singleton instance.
158  */
159  static Environment *instance();
160 
161  /**
162  * @brief Initializes Environment and all platform interfaces.
163  *
164  * This method should be used to initialize the Game. It creates
165  * all platform specific interfaces, creates the Window, adds the
166  * PAK data file to use, loads game configuration and settings
167  * etc. After init() is done you should call startMainLoop() and
168  * destroy() when exiting.
169  *
170  * @param game Singleton Game instance.
171  * @param windowTitle Window title.
172  * @param publisherName Publisher name.
173  * @param prefFileName Preferences file name.
174  * @param pakDataFile PakInterface PAK data file.
175  * @param pakDataFilePassword PakInterface PAK data file password.
176  * @param windowIconPath Window icon to use, if any.
177  * @param cryptoKey Default Crypto key to use internally.
178  * @param androidActivityClass Android java activity class path.
179  * Must be set if targeting Android platform. It should be full
180  * path like so: "org/libhffwk/demo1/HFActivity".
181  *
182  * @note Game configuration data must be stored in the file
183  * <b>'data/config.xml'</b>. Check out
184  * <b>'demos/demo1-minimal/data/config.xml'</b> for an example.
185  *
186  * @see startMainLoop()
187  * @see stopMainLoop()
188  * @see destroy()
189  * @see isShuttingDown()
190  */
191  virtual void init(Game *game,
192  const UString &windowTitle,
193  const UString &publisherName,
194  const UString &prefFileName,
195  const UString &pakDataFile,
196  const UString &pakDataFilePassword,
197  const UString &windowIconPath,
198  uint8_hf *cryptoKey,
199  const UString &androidActivityClass);
200 
201  /**
202  * @brief Destroy the singleton Environment instance and do
203  * cleanup.
204  *
205  * @see init()
206  * @see startMainLoop()
207  * @see stopMainLoop()
208  * @see isShuttingDown()
209  */
210  virtual void destroy();
211 
212  /**
213  * @brief Start the main loop.
214  *
215  * @see init()
216  * @see destroy()
217  * @see stopMainLoop()
218  * @see isShuttingDown()
219  */
220  virtual void startMainLoop() = 0;
221 
222  /**
223  * @brief Stop the main loop.
224  *
225  * @see init()
226  * @see destroy()
227  * @see startMainLoop()
228  * @see isShuttingDown()
229  */
230  virtual void stopMainLoop() = 0;
231 
232  /**
233  * @brief Checks if currently shutting down the main loop.
234  *
235  * @return true if shutting down, else false.
236  *
237  * @see init()
238  * @see destroy()
239  * @see startMainLoop()
240  * @see stopMainLoop()
241  */
242  virtual bool isShuttingDown() = 0;
243 
244  /**
245  * @brief Enable debug.
246  *
247  * @param enabled true to enable debug, otherwise false.
248  */
249  virtual void setDebugEnabled(bool enabled) = 0;
250 
251  /**
252  * @brief Check if debug is enabled.
253  *
254  * @return true if debug is enabled, else false.
255  */
256  virtual bool isDebugEnabled() = 0;
257 
258  /**
259  * @brief Initialize timer.
260  */
261  virtual void initTimer() = 0;
262 
263  /**
264  * @brief Get Ticks in milliseconds since start.
265  *
266  * @return Ticks in milliseconds.
267  */
268  virtual uint32_hf getTicks() = 0;
269 
270  /**
271  * @brief Get Time in Seconds since start.
272  *
273  * @return Time in seconds.
274  *
275  * @see pauseTime()
276  * @see resumeTime()
277  * @see isTimePaused()
278  * @see getPauseDuration()
279  */
280  virtual fp32_hf getTime() = 0;
281 
282 
283  /**
284  * @brief Pause time.
285  *
286  * @see getTime()
287  * @see resumeTime()
288  * @see isTimePaused()
289  * @see getPauseDuration()
290  */
291  virtual void pauseTime() = 0;
292 
293  /**
294  * @brief Resume paused time.
295  *
296  * @see getTime()
297  * @see pauseTime()
298  * @see isTimePaused()
299  * @see getPauseDuration()
300  */
301  virtual void resumeTime() = 0;
302 
303  /**
304  * @brief Checks if time is paused.
305  *
306  * @return true if time is paused, else false.
307  *
308  * @see getTime()
309  * @see pauseTime()
310  * @see resumeTime()
311  * @see getPauseDuration()
312  */
313  virtual bool isTimePaused() = 0;
314 
315  /**
316  * @brief Get Pause duration in seconds.
317  *
318  * @return Paused time in seconds.
319  *
320  * @see getTime()
321  * @see pauseTime()
322  * @see resumeTime()
323  * @see isTimePaused()
324  */
325  virtual fp32_hf getPauseDuration() = 0;
326 
327  /**
328  * @brief Get Max frame rate.
329  *
330  * @return Max frame rate.
331  *
332  * @see setMaxFrameRate()
333  */
334  virtual int32_hf getMaxFrameRate() = 0;
335 
336  /**
337  * @brief Set max frame rate.
338  *
339  * @param framesPerSecond Max frame rate.
340  *
341  * @see getMaxFrameRate()
342  */
343  virtual void setMaxFrameRate(int32_hf framesPerSecond) = 0;
344 
345  /**
346  * @brief Sleep for given time in milliseconds.
347  *
348  * @param milliseconds Time to sleep in milliseconds.
349  */
350  virtual void sleep(int32_hf milliseconds) = 0;
351 
352  /**
353  * @brief Determines whether to pause the game loop or not.
354  *
355  * Useful for Game pause.
356  *
357  * @param pause true to pause, else false.
358  *
359  * @note Timing will continue so it's just away for game to
360  * set/check if needed.
361  *
362  * @see getUpdatePaused()
363  */
364  virtual void setUpdatePaused(bool pause) = 0;
365 
366  /**
367  * @brief Checks if update is in paused state or not.
368  *
369  * @return true if paused, else false.
370  *
371  * @see setUpdatePaused()
372  */
373  virtual bool getUpdatePaused() = 0;
374 
375  /**
376  * @brief Get Graphics interface.
377  *
378  * @return Graphics interface.
379  *
380  * @see createGraphics()
381  */
382  virtual Graphics *getGraphics() = 0;
383 
384  /**
385  * @brief Create new Graphics interface.
386  *
387  * @return Graphics interface.
388  *
389  * @see getGraphics()
390  */
391  virtual Graphics *createGraphics() = 0;
392 
393  /**
394  * @brief Create Geometry.
395  *
396  * @param vertexType Geometry::VertexType enum.
397  * @param bufferUsage HF_BufferUsage enum.
398  * @param bufferSize Number of vector elements except for
399  * Geometry::VERTEX_TYPE_CUSTOM where bufferSize should be
400  * in bytes.
401  *
402  * @return Geometry pointer.
403  */
404  virtual Geometry *createGeometry(Geometry::VertexType vertexType,
405  HF_BufferUsage bufferUsage,
406  uint32_hf bufferSize) = 0;
407 
408  /**
409  * @brief Create Geometry.
410  *
411  * @param bufferUsage HF_BufferUsage enum.
412  * @param vertPosCol Geometry::VertexPosColVector vector.
413  *
414  * @return Geometry pointer.
415  */
416  virtual Geometry *createGeometry(HF_BufferUsage bufferUsage,
417  Geometry::VertexPosColVector *vertPosCol) = 0;
418 
419  /**
420  * @brief Create Geometry.
421  *
422  * @param bufferUsage HF_BufferUsage enum.
423  * @param vertPosTex Geometry::VertexPosTexVector vector.
424  * @param vertTextures Geometry::VertexTextureVector vector.
425  *
426  * @return Geometry pointer.
427  */
428  virtual Geometry *createGeometry(HF_BufferUsage bufferUsage,
429  Geometry::VertexPosTexVector *vertPosTex,
430  Geometry::VertexTextureVector *vertTextures = NULL
431  ) = 0;
432 
433  /**
434  * @brief Create Geometry.
435  *
436  * @param bufferUsage HF_BufferUsage enum.
437  * @param vertPosColTex Geometry::VertexPosColTexVector vector.
438  * @param vertTextures Geometry::VertexTextureVector vector.
439  *
440  * @return Geometry pointer.
441  */
442  virtual Geometry *createGeometry(HF_BufferUsage bufferUsage,
443  Geometry::VertexPosColTexVector *vertPosColTex,
444  Geometry::VertexTextureVector *vertTextures = NULL
445  ) = 0;
446 
447  /**
448  * @brief Create Geometry.
449  *
450  * @param bufferUsage HF_BufferUsage enum.
451  * @param vertPosColNor Geometry::VertexPosColNorVector vector.
452  *
453  * @return Geometry pointer.
454  */
455  virtual Geometry *createGeometry(HF_BufferUsage bufferUsage,
456  Geometry::VertexPosColNorVector *vertPosColNor) = 0;
457 
458  /**
459  * @brief Create Geometry.
460  *
461  * @param bufferUsage HF_BufferUsage enum.
462  * @param vertPosNorTex Geometry::VertexPosNorTexVector vector.
463  * @param vertTextures Geometry::VertexTextureVector vector.
464  *
465  * @return Geometry pointer.
466  */
467  virtual Geometry *createGeometry(HF_BufferUsage bufferUsage,
468  Geometry::VertexPosNorTexVector *vertPosNorTex,
469  Geometry::VertexTextureVector *vertTextures = NULL
470  ) = 0;
471 
472  /**
473  * @brief Create Geometry.
474  *
475  * @param bufferUsage HF_BufferUsage enum.
476  * @param vertPosColNorTex
477  * Geometry::VertexPosColNorTexVector vector.
478  * @param vertTextures Geometry::VertexTextureVector vector.
479  *
480  * @return Geometry pointer.
481  */
482  virtual Geometry *createGeometry(HF_BufferUsage bufferUsage,
483  Geometry::VertexPosColNorTexVector *vertPosColNorTex,
484  Geometry::VertexTextureVector *vertTextures = NULL
485  ) = 0;
486 
487  /**
488  * @brief Create Geometry.
489  *
490  * @param bufferUsage HF_BufferUsage enum.
491  * @param vertexAttribVector Geometry::VertexAttributeVector.
492  * @param data Pointer to vertex data.
493  * @param numVertices Number of vertices.
494  * @param dataSizeBytes Size of data in bytes.
495  *
496  * @return Geometry pointer.
497  */
498  virtual Geometry *createGeometry(HF_BufferUsage bufferUsage,
499  Geometry::VertexAttributeVector *vertexAttribVector,
500  void *data, uint32_hf numVertices,
501  uint32_hf dataSizeBytes) = 0;
502 
503  /**
504  * @brief Get Mouse count.
505  *
506  * @return Mouse count.
507  */
508  virtual int32_hf getMouseCount() = 0;
509 
510  /**
511  * @brief Get Mouse for a given index.
512  *
513  * @param mouseId Mouse id.
514  *
515  * @return Pointer to Mouse.
516  */
517  virtual Mouse *getMouse(int32_hf mouseId) = 0;
518 
519  /**
520  * @brief Get first Mouse.
521  *
522  * @return Mouse at index 0.
523  */
524  virtual Mouse *getFirstMouse() = 0;
525 
526  /**
527  * @brief Get Keyboard count.
528  *
529  * @return Keyboard count.
530  */
531  virtual int32_hf getKeyboardCount() = 0;
532 
533  /**
534  * @brief Get Keyboard at given index.
535  *
536  * @param i Index.
537  *
538  * @return Keyboard at index.
539  */
540  virtual Keyboard *getKeyboard(int32_hf i) = 0;
541 
542  /**
543  * @brief Get GamePad count.
544  *
545  * @return GamePad count.
546  */
547  virtual int32_hf getGamePadCount() = 0;
548 
549  /**
550  * @brief Get GamePad at given index.
551  *
552  * @param i Index.
553  *
554  * @return GamePad at index.
555  */
556  virtual GamePad *getGamePad(int32_hf i) = 0;
557 
558  /**
559  * @brief Get Touch at given index.
560  *
561  * @param touchId Index.
562  *
563  * @return Touch at index.
564  */
565  virtual Touch *getTouch(int32_hf touchId) = 0;
566 
567  /**
568  * @brief Get Touch count.
569  *
570  * @return Touch count.
571  */
572  virtual int32_hf getTouchCount() = 0;
573 
574  /**
575  * @brief Called automatically when a Mouse is added. It then
576  * calls callback method Game::handleMouseAdded().
577  *
578  * @param mouseId Mouse index.
579  *
580  * @see fireMouseRemoved()
581  * @see Game::handleMouseAdded()
582  */
583  void fireMouseAdded(int32_hf mouseId);
584 
585  /**
586  * @brief Called automatically when a Mouse is removed. It then
587  * calls callback method Game::handleMouseRemoved().
588  *
589  * @param mouseId Mouse index.
590  *
591  * @see fireMouseAdded()
592  * @see Game::handleMouseRemoved()
593  */
594  void fireMouseRemoved(int32_hf mouseId);
595 
596  /**
597  * @brief Called automatically when a Touch is added. It then
598  * calls callback method Game::handleTouchAdded().
599  *
600  * @param touchId Touch index.
601  *
602  * @see fireTouchRemoved()
603  * @see Game::handleTouchAdded()
604  */
605  void fireTouchAdded(int32_hf touchId);
606 
607  /**
608  * @brief Called automatically when a Touch is removed. It then
609  * calls callback method Game::handleTouchRemoved().
610  *
611  * @param touchId Touch index.
612  *
613  * @see fireTouchAdded()
614  * @see Game::handleTouchRemoved()
615  */
616  void fireTouchRemoved(int32_hf touchId);
617 
618  /**
619  * @brief Called automatically when a GamePad is added. It then
620  * calls callback method Game::handleGamePadAdded().
621  *
622  * @param gamePadId GamePad index.
623  *
624  * @see fireGamePadRemoved()
625  * @see Game::handleGamePadAdded()
626  */
627  void fireGamePadAdded(int32_hf gamePadId);
628 
629  /**
630  * @brief Called automatically when a GamePad is removed. It then
631  * calls callback method Game::handleGamePadRemoved().
632  *
633  * @param gamePadId GamePad index.
634  *
635  * @see fireGamePadAdded()
636  * @see Game::handleGamePadRemoved()
637  */
638  void fireGamePadRemoved(int32_hf gamePadId);
639 
640  /**
641  * @brief Determines whether to show or hide system mouse.
642  *
643  * @param show true to show system mouse, else false.
644  */
645  virtual void showSystemMouse(bool show) = 0;
646 
647  /**
648  * @brief Checks if system mouse is shown.
649  *
650  * @return true if system mouse is shown, else false.
651  */
652  virtual bool getSystemMouseShown() = 0;
653 
654  /**
655  * @brief Determines whether to show or hide custom mouse cursor.
656  *
657  * Custom cursor = custom Image cursor.
658  *
659  * @param show true to show custom cursor, else false.
660  */
661  virtual void showCustomCursor(bool show) = 0;
662 
663  /**
664  * @brief Checks if custom cursor is shown.
665  *
666  * @return true if custom cursor is shown, else false.
667  */
668  virtual bool getCustomCursorShown() = 0;
669 
670  /**
671  * @brief Set Custom Image to use as mouse cursor.
672  *
673  * @param cursorImage Image to use.
674  * @param offset Offset x, y for tweaking cursor sweet spot.
675  */
676  virtual void setCustomMouseCursor(Image *cursorImage,
677  Vector2 &offset) = 0;
678 
679  /**
680  * @brief Set Custom Image to use as mouse cursor.
681  *
682  * @param atlasImage Image to use.
683  * @param cursorRect Image Rect to use.
684  * @param offset Offset x, y for tweaking cursor sweet spot.
685  */
686  virtual void setCustomMouseCursor(Image *atlasImage, Rect &cursorRect,
687  Vector2 &offset) = 0;
688 
689  /**
690  * @brief Set Cursor position.
691  *
692  * @param x Cursor x position.
693  * @param y Cursor y position.
694  */
695  virtual void setCursorPosition(uint32_hf x, uint32_hf y) = 0;
696 
697  /**
698  * @brief Set Mouse position.
699  *
700  * @param x Mouse x position.
701  * @param y Mouse y position.
702  */
703  virtual void setMousePosition(int32_hf x, int32_hf y) = 0;
704 
705  /**
706  * @brief Get Mouse X position.
707  *
708  * @return Mouse X position.
709  */
710  virtual int32_hf getMousePosX() = 0;
711 
712  /**
713  * @brief Get Mouse Y position.
714  *
715  * @return Mouse Y position.
716  */
717  virtual int32_hf getMousePosY() = 0;
718 
719  /**
720  * @brief Get pointer to ResourceManager interface.
721  *
722  * Can also be retrieved using shortcut macro:
723  * @code
724  * HFCORE_ENV
725  * @endcode
726  *
727  * @return ResourceManager pointer.
728  */
729  virtual ResourceManager *getResourceManager() = 0;
730 
731  /**
732  * @brief Get pointer to WidgetManager interface.
733  *
734  * Can also be retrieved using shortcut macro:
735  * @code
736  * HFCORE_WIDMGR
737  * @endcode
738  *
739  * @return WidgetManager pointer.
740  */
741  virtual WidgetManager *getWidgetManager() = 0;
742 
743  /**
744  * @brief Get pointer to FileDirUtils interface.
745  *
746  * Can also be retrieved using shortcut macro:
747  * @code
748  * HFCORE_FDU
749  * @endcode
750  *
751  * @return FileDirUtils pointer.
752  */
753  virtual FileDirUtils *getFileDirUtils() = 0;
754 
755  /**
756  * @brief Get pointer to Preferences interface.
757  *
758  * Can also be retrieved using shortcut macro:
759  * @code
760  * HFCORE_PREF
761  * @endcode
762  *
763  * @return Preferences pointer.
764  */
765  virtual Preferences *getPreferencesManager() = 0;
766 
767  /**
768  * @brief Get pointer to PersistenceLayer interface.
769  *
770  * Can also be retrieved using shortcut macro:
771  * @code
772  * HFCORE_PERSLAY
773  * @endcode
774  *
775  * @return PersistenceLayer pointer.
776  */
777  virtual PersistenceLayer *getPersistenceLayer() = 0;
778 
779  /**
780  * @brief Get pointer to WebManager interface.
781  *
782  * Can also be retrieved using shortcut macro:
783  * @code
784  * HFCORE_WEBMGR
785  * @endcode
786  *
787  * @return WebManager pointer.
788  */
789  virtual WebManager *getWebManager() = 0;
790 
791  /**
792  * @brief Get pointer to ActorManager interface.
793  *
794  * Can also be retrieved using shortcut macro:
795  * @code
796  * HFCORE_ACTMGR
797  * @endcode
798  *
799  * @return ActorManager pointer.
800  */
801  virtual ActorManager *getActorManager();
802 
803  /**
804  * @brief Get pointer to Camera interface.
805  *
806  * Can also be retrieved using shortcut macro:
807  * @code
808  * HFCORE_CAMERA
809  * @endcode
810  *
811  * @return Camera pointer.
812  */
813  virtual Camera *getCamera() = 0;
814 
815  /**
816  * @brief Get game configuration UStringMap which contains all
817  * settings stored in 'data/config.xml'.
818  *
819  * @return UStringMap containing all game config settings.
820  */
822 
823  /**
824  * @brief Get game config value for given name.
825  *
826  * @param name Game config name to get.
827  *
828  * @return Game config value for given name.
829  *
830  * @note Game configuration data must be stored in the file
831  * <b>'data/config.xml'</b>. Check out
832  * <b>'demos/demo1-minimal/data/config.xml'</b> for an example.
833  */
834  virtual UString getGameConfigValue(const UString &name) = 0;
835 
836  /**
837  * @brief Get game config value for given name.
838  *
839  * @param name Game config name to get.
840  *
841  * @return Game config value for given name.
842  *
843  * @note Game configuration data must be stored in the file
844  * <b>'data/config.xml'</b>. Check out
845  * <b>'demos/demo1-minimal/data/config.xml'</b> for an example.
846  */
847  virtual int32_hf getGameConfigValueInt(const UString &name) = 0;
848 
849  /**
850  * @brief Get game config value for given name.
851  *
852  * @param name Game config name to get.
853  *
854  * @return Game config value for given name.
855  *
856  * @note Game configuration data must be stored in the file
857  * <b>'data/config.xml'</b>. Check out
858  * <b>'demos/demo1-minimal/data/config.xml'</b> for an example.
859  */
860  virtual fp32_hf getGameConfigValueFloat(const UString &name) = 0;
861 
862  /**
863  * @brief Get game config value for given name.
864  *
865  * @param name Game config name to get.
866  *
867  * @return Game config value for given name.
868  *
869  * @note Game configuration data must be stored in the file
870  * <b>'data/config.xml'</b>. Check out
871  * <b>'demos/demo1-minimal/data/config.xml'</b> for an example.
872  */
873  virtual bool getGameConfigValueBool(const UString &name) = 0;
874 
875  /**
876  * @brief Determines whether to render debug info
877  * (FPS, Render calls etc).
878  *
879  * It depends on setSystemFont() being set as it's the Font used
880  * for the actual rendering.
881  *
882  * @param render true to render debug info, else false.
883  *
884  * @see getRenderDebugInfo()
885  * @see setSystemFont()
886  */
887  virtual void setRenderDebugInfo(bool render) = 0;
888 
889  /**
890  * @brief Checks if render debug info is set.
891  *
892  * @return true if render debug info set, else false.
893  *
894  * @see setRenderDebugInfo()
895  */
896  virtual bool getRenderDebugInfo() = 0;
897 
898  /**
899  * @brief Set system Font to use for debug rendering.
900  *
901  * @param sysFont Font to use.
902  *
903  * @see getSystemFont()
904  * @see setRenderDebugInfo()
905  * @see drawDebugInfo()
906  */
907  virtual void setSystemFont(HFCore::Font *sysFont) = 0;
908 
909  /**
910  * @brief Get system Font in use for debug rendering.
911  *
912  * @return Font in use for debug rendering.
913  *
914  * @see setSystemFont()
915  */
916  virtual HFCore::Font *getSystemFont() = 0;
917 
918  /**
919  * @brief Get pointer to SoundPlayer interface.
920  *
921  * Can also be retrieved using shortcut macro:
922  * @code
923  * HFCORE_SOUND
924  * @endcode
925  *
926  * @return SoundPlayer pointer.
927  */
928  virtual SoundPlayer *getSoundPlayer() = 0;
929 
930  /**
931  * @brief Useful for showing error messagebox
932  * (not showing messagebox yet for all platforms though).
933  *
934  * @param message String containing message.
935  */
936  virtual void showError(const std::string &message) = 0;
937 
938  /**
939  * @brief Get currently stored crypto key.
940  *
941  * @return Crypto key.
942  */
943  virtual uint8_hf *getCryptoKey() = 0;
944 
945  /**
946  * @brief Checks if window is resizable.
947  *
948  * @return true if window is resizable, else false.
949  */
950  virtual bool isWindowResizable() = 0;
951 
952  /**
953  * @brief Checks if window is borderless.
954  *
955  * @return true if window is borderless, else false.
956  */
957  virtual bool isWindowBorderless() = 0;
958 
959  /**
960  * @brief Checks if currently in fullscreen mode.
961  *
962  * @return true if fullscreen, else false.
963  */
964  virtual bool isFullScreen() = 0;
965 
966  /**
967  * @brief Toggle fullscreen / windowed mode.
968  */
969  virtual void toggleFullScreen() = 0;
970 
971  /**
972  * @brief Enable fullscreen toggle.
973  *
974  * @see disableFullScreenToggle()
975  */
976  virtual void enableFullScreenToggle() = 0;
977 
978  /**
979  * @brief Disable fullscreen toggle.
980  *
981  * @see enableFullScreenToggle()
982  */
983  virtual void disableFullScreenToggle() = 0;
984 
985  /**
986  * @brief Checks if OK to toggle fullscreen / windowed mode.
987  *
988  * @return true if toggle ok, else false.
989  */
990  virtual bool isOKToToggleFullscreen() = 0;
991 
992  /**
993  * @brief Get current fullscreen mode.
994  *
995  * @return Current fullscreen mode.
996  */
997  virtual HF_FullscreenMode getFullscreenMode() = 0;
998 
999  /**
1000  * @brief Write to debug log and console (printf).
1001  *
1002  * The following shortcut macro is also available:
1003  * @code
1004  * envDebugLog("File: %s, z: %f\r\n", file.c_str(), z);
1005  * @endcode
1006  *
1007  * @param fmt Format string (example: "File: %s, z: %f\r\n")
1008  * @param ... Parameters used by format string, if any.
1009  *
1010  * @see setDebugLogFile()
1011  */
1012  virtual void debugLog(const int8_hf *fmt, ...) = 0;
1013 
1014  /**
1015  * @brief Set debug log file to use.
1016  *
1017  * Default log file 'debug.log' is stored under the folder
1018  * FileDirUtils::getAppDataFolder().
1019  *
1020  * @param logFile FILE to use.
1021  *
1022  * @see debugLog()
1023  * @see FileDirUtils::getAppDataFolder()
1024  */
1025  virtual void setDebugLogFile(FILE *logFile) = 0;
1026 
1027  /**
1028  * @brief Write to engine log.
1029  *
1030  * The following shortcut macro is also available:
1031  * @code
1032  * envEngineLog("File: %s, z: %f\r\n", file.c_str(), z);
1033  * @endcode
1034  *
1035  * @param fmt Format string (example: "File: %s, z: %f\r\n")
1036  * @param ... Parameters used by format string, if any.
1037  *
1038  * @see setEngineLogFile()
1039  */
1040  virtual void engineLog(const int8_hf *fmt, ...) = 0;
1041 
1042  /**
1043  * @brief Set engine log file to use.
1044  *
1045  * Default log file 'engine.log' is stored under the folder
1046  * FileDirUtils::getAppDataFolder().
1047  *
1048  * @param logFile FILE to use.
1049  *
1050  * @see engineLog()
1051  * @see FileDirUtils::getAppDataFolder()
1052  */
1053  virtual void setEngineLogFile(FILE *logFile) = 0;
1054 
1055  /**
1056  * @brief Write to game log.
1057  *
1058  * The following shortcut macro is also available:
1059  * @code
1060  * envGameLog("File: %s, z: %f\r\n", file.c_str(), z);
1061  * @endcode
1062  *
1063  * @param fmt Format string (example: "File: %s, z: %f\r\n")
1064  * @param ... Parameters used by format string, if any.
1065  *
1066  * @see setGameLogFile()
1067  */
1068  virtual void gameLog(const int8_hf *fmt, ...) = 0;
1069 
1070  /**
1071  * @brief Set game log file to use.
1072  *
1073  * Default log file 'game.log' is stored under the folder
1074  * FileDirUtils::getAppDataFolder().
1075  *
1076  * @param logFile FILE to use.
1077  *
1078  * @see gameLog()
1079  * @see FileDirUtils::getAppDataFolder()
1080  */
1081  virtual void setGameLogFile(FILE *logFile) = 0;
1082 
1083  /**
1084  * @brief Take screenshot and store in
1085  * FileDirUtils::getAppDataFolder().
1086  */
1087  virtual void screenshot() = 0;
1088 
1089  /**
1090  * @brief 'sprintf' std lib wrapper.
1091  *
1092  * Example:
1093  * @code
1094  * HFCORE_ENV->hf_sprintf(buf, bufSize, "%02x", digest[i]);
1095  * @endcode
1096  *
1097  * @param pBuffer Buffer.
1098  * @param bufferLenChars Buffer length.
1099  * @param pFormat Format string.
1100  * @param ... Parameters used by format string, if any.
1101  *
1102  * @return The number of characters that would have been written
1103  * if n had been sufficiently large, not counting the terminating
1104  * null character. If an encoding error occurs, a negative number
1105  * is returned. Notice that only when this returned value is
1106  * non-negative and less than n, the string has been completely
1107  * written.
1108  */
1109  virtual int32_hf hf_sprintf(int8_hf *pBuffer, int32_hf bufferLenChars,
1110  const int8_hf *pFormat, ...) = 0;
1111 
1112  /**
1113  * @brief 'stricmp' std lib wrapper. Compare two strings.
1114  *
1115  * @param pStr1 String 1
1116  * @param pStr2 String 2
1117  *
1118  * @return Return an integer less than, equal to, or greater than
1119  * zero if pStr1 (or the first n bytes thereof) is found,
1120  * respectively, to be less than, to match, or be greater than
1121  * pStr2.
1122  */
1123  virtual int32_hf hf_stricmp(const int8_hf *pStr1, const int8_hf *pStr2) = 0;
1124 
1125  /**
1126  * @brief Get pointer to Storage interface.
1127  *
1128  * Can also be retrieved using shortcut macro:
1129  * @code
1130  * HFCORE_STORAGE
1131  * @endcode
1132  *
1133  * @return Storage pointer.
1134  */
1135  virtual Storage *getStorage() = 0;
1136 
1137  /**
1138  * @brief Creates new thread which calls Game::saveDataThread().
1139  */
1140  virtual void createGameSaveThread() = 0;
1141 
1142  /**
1143  * @brief Create a new thread and get callback through
1144  * ThreadListener interface.
1145  *
1146  * @param threadInfo Pointer to HF_ThreadInfo struct.
1147  * @param listener ThreadListner is the listener class which will
1148  * receive the callbacks.
1149  *
1150  * @return thread_hf pointer.
1151  *
1152  * @see waitThread()
1153  */
1154  virtual thread_hf createThread(HF_ThreadInfo *threadInfo,
1155  ThreadListener *listener) = 0;
1156 
1157  /**
1158  * @brief Wait until given thread is done.
1159  *
1160  * @param thread The thread_hf pointer that was returned from the
1161  * createThread() call that started this thread.
1162  * @param threadReturnVal Pointer to an integer that will receive
1163  * the value returned from the thread function by its 'return'.
1164  *
1165  * @see createThread()
1166  */
1167  virtual void waitThread(thread_hf thread,
1168  int32_hf *threadReturnVal) = 0;
1169 
1170  /**
1171  * @brief Draw custom mouse cursor if enabled and set (called
1172  * automatically from Graphics::endScene() method).
1173  *
1174  * @param g Graphics pointer.
1175  *
1176  * @see showCustomCursor()
1177  * @see setCustomMouseCursor()
1178  */
1179  virtual void drawCustomMouseCursor(Graphics *g) = 0;
1180 
1181  /**
1182  * @brief Draw debug info if enabled (CTRL+ALT+f enables).
1183  *
1184  * Use 'CTRL+ALT+f' keys to enable. setSystemFont() must also be
1185  * set. When enabled and system font is set this method will be
1186  * called automatically from Graphics::endScene().
1187  *
1188  * @param g Graphics pointer.
1189  *
1190  * @see setSystemFont()
1191  */
1192  virtual void drawDebugInfo(Graphics *g) = 0;
1193 
1194  /**
1195  * @brief Reset internal draw count counter.
1196  */
1197  virtual void resetDrawCount() = 0;
1198 
1199  /**
1200  * @brief Get draw count.
1201  *
1202  * @return Draw count.
1203  */
1204  virtual uint32_hf getDrawCount() = 0;
1205 
1206  /**
1207  * @brief Create new Window.
1208  *
1209  * Example code:
1210  * @code
1211  * // Default Window flags:
1212  * uint32_hf flags = HF_WINDOW_OPENGL | HF_WINDOW_SHOWN;
1213  *
1214  * if (HFCORE_ENV->getGameConfigValueBool("WindowResizable"))
1215  * flags |= HF_WINDOW_RESIZABLE;
1216  *
1217  * if (HFCORE_ENV->getGameConfigValueBool("WindowBorderless"))
1218  * flags |= HF_WINDOW_BORDERLESS;
1219  *
1220  * if (!mWindowed)
1221  * flags |= HF_WINDOW_FULLSCREEN;
1222  *
1223  * // Create the window:
1224  * HF_Window window;
1225  * window = HFCORE_ENV->createWindow(title.c_str(), width,
1226  * height, flags,
1227  * HF_WINDOW_POS_CENTERED,
1228  * HF_WINDOW_POS_CENTERED);
1229  * @endcode
1230  *
1231  * @param windowTitle Window title.
1232  * @param w Window width.
1233  * @param h Window height.
1234  * @param windowflags see HF_WindowFlags in HFDataTypes.h for
1235  * available Window flags.
1236  * @param x Window X position, default is centered.
1237  * @param y Window Y position, default is centered.
1238  *
1239  * @return The new HF_Window.
1240  *
1241  * @see destroyWindow()
1242  */
1243  virtual HF_Window createWindow(const int8_hf *windowTitle, int32_hf w,
1244  int32_hf h, uint32_hf windowflags,
1247 
1248  /**
1249  * @brief Destroy Window.
1250  *
1251  * @param window Window to destroy.
1252  *
1253  * @see createWindow()
1254  */
1255  virtual void destroyWindow(HF_Window window) = 0;
1256 
1257  /**
1258  * @brief Safe destroy window.
1259  *
1260  * Safe destroy = put the Window in cache to be processed later
1261  * with a call to processSafeDeleteListWindow(). Useful if you
1262  * don't want to destroy immediately. processSafeDeleteListWindow()
1263  * is always called before exit of program.
1264  *
1265  * @param window Window to destroy.
1266  *
1267  * @see processSafeDeleteListWindow()
1268  */
1269  virtual void safeDestroyWindow(HF_Window window) = 0;
1270 
1271  /**
1272  * @brief Process the cache of Window's to destroy (those put by
1273  * safeDestroyWindow()).
1274  *
1275  * @see safeDestroyWindow()
1276  */
1277  virtual void processSafeDeleteListWindow() = 0;
1278 
1279  /**
1280  * @brief Show Window.
1281  *
1282  * @param window Window to show.
1283  *
1284  * @see hideWindow()
1285  */
1286  virtual void showWindow(HF_Window window) = 0;
1287 
1288  /**
1289  * @brief Hide Window.
1290  *
1291  * @param window Window to hide.
1292  *
1293  * @see showWindow()
1294  */
1295  virtual void hideWindow(HF_Window window) = 0;
1296 
1297  /**
1298  * @brief Get Window brightness (range 0.0f - 1.0f).
1299  *
1300  * @param window Window to check brightness for.
1301  *
1302  * @return Returns the brightness for the display where 0.0f is
1303  * completely dark and 1.0f is normal brightness.
1304  *
1305  * @see setWindowBrightness()
1306  */
1307  virtual fp32_hf getWindowBrightness(HF_Window window) = 0;
1308 
1309  /**
1310  * @brief Set Window brightness (range 0.0f - 1.0f).
1311  *
1312  * @param window Window to set brightness for.
1313  * @param brightness The brightness (gamma multiplier) value to
1314  * set where 0.0f is completely dark and 1.0f is normal
1315  * brightness.
1316  *
1317  * @see getWindowBrightness()
1318  */
1319  virtual void setWindowBrightness(HF_Window window, fp32_hf brightness) = 0;
1320 
1321  /**
1322  * @brief Get the data pointer associated with a window.
1323  *
1324  * @param window Window to query.
1325  * @param name The name of the pointer.
1326  *
1327  * @return Returns the data pointer associated with name.
1328  *
1329  * @see setWindowData()
1330  */
1331  virtual void *getWindowData(HF_Window window, const int8_hf *name) = 0;
1332 
1333  /**
1334  * @brief Set / associate an arbitrary named pointer with a
1335  * window.
1336  *
1337  * @param window Window to associate with the pointer.
1338  * @param name The name of the pointer.
1339  * @param data The associated pointer.
1340  *
1341  * @see getWindowData()
1342  */
1343  virtual void setWindowData(HF_Window window, const int8_hf *name,
1344  void *data) = 0;
1345 
1346  /**
1347  * @brief Get Window flags.
1348  *
1349  * @param window Window to query.
1350  *
1351  * @return Returns a mask of the HF_WindowFlags associated with
1352  * window.
1353  */
1354  virtual uint32_hf getWindowFlags(HF_Window window) = 0;
1355 
1356  /**
1357  * @brief Get Window by given ID.
1358  *
1359  * @param windowID ID for the query.
1360  *
1361  * @return HF_Window for windowID. If not found attribute 'window'
1362  * will be NULL.
1363  *
1364  * @see getWindowID()
1365  */
1366  virtual HF_Window getWindowFromID(uint32_hf windowID) = 0;
1367 
1368  /**
1369  * @brief Get ID for a given Window.
1370  *
1371  * @param window Window used for query.
1372  *
1373  * @return Window ID.
1374  *
1375  * @see getWindowFromID()
1376  */
1377  virtual uint32_hf getWindowID(HF_Window window) = 0;
1378 
1379  /**
1380  * @brief Get Window position.
1381  *
1382  * @param window Window to get position for.
1383  * @param[out] x Window X position if not NULL.
1384  * @param[out] y Window Y position if not NULL.
1385  *
1386  * @see setWindowPosition()
1387  */
1388  virtual void getWindowPosition(HF_Window window, int32_hf *x, int32_hf *y) = 0;
1389 
1390  /**
1391  * @brief Set Window position.
1392  *
1393  * @param window Window to set position for.
1394  * @param x Window X position to set.
1395  * @param y Window Y position to set.
1396  *
1397  * @see getWindowPosition()
1398  */
1399  virtual void setWindowPosition(HF_Window window, int32_hf x, int32_hf y) = 0;
1400 
1401  /**
1402  * @brief Get Window size.
1403  *
1404  * @param window Window to query.
1405  * @param[out] w Window width if not NULL.
1406  * @param[out] h Window height if not NULL.
1407  *
1408  * @see setWindowSize()
1409  */
1410  virtual void getWindowSize(HF_Window window, int32_hf *w, int32_hf *h) = 0;
1411 
1412  /**
1413  * @brief Set Window size.
1414  *
1415  * @param window Window to set size for.
1416  * @param w Window width to set.
1417  * @param h Window height to set.
1418  *
1419  * @see getWindowSize()
1420  */
1421  virtual void setWindowSize(HF_Window window, int32_hf w, int32_hf h) = 0;
1422 
1423  /**
1424  * @brief Set Window title.
1425  *
1426  * @param window Window to set title for.
1427  * @param windowTitle Window title.
1428  */
1429  virtual void setWindowTitle(HF_Window window, const int8_hf *windowTitle) = 0;
1430 
1431  /**
1432  * @brief Get Window title.
1433  *
1434  * @param window Window to get title for.
1435  *
1436  * @return Window title.
1437  */
1438  virtual const int8_hf *getWindowTitle(HF_Window window) = 0;
1439 
1440  /**
1441  * @brief Get main Window ID (id from window created at
1442  * startup / init).
1443  *
1444  * @return Window ID.
1445  *
1446  * @see getMainWindow()
1447  */
1448  virtual uint32_hf getMainWindowID() = 0;
1449 
1450  /**
1451  * @brief Get main Window (window created at startup / init).
1452  *
1453  * @return Main Window.
1454  *
1455  * @see getMainWindowID()
1456  */
1457  virtual HF_Window getMainWindow() = 0;
1458 
1459  /**
1460  * @brief Get Window display mode for a given window.
1461  *
1462  * @param window Window to get display mode for.
1463  * @param[out] displayMode Filled HF_DisplayMode.
1464  *
1465  * @return true if success, else false.
1466  *
1467  * @see setWindowDisplayMode()
1468  */
1469  virtual bool getWindowDisplayMode(HF_Window window,
1470  HF_DisplayMode *displayMode) = 0;
1471 
1472  /**
1473  * @brief Set Window display mode for a given window.
1474  *
1475  * @param window Window to set display mode for.
1476  * @param displayMode Filled HF_DisplayMode to set.
1477  *
1478  * @see getWindowDisplayMode()
1479  */
1480  virtual void setWindowDisplayMode(HF_Window window,
1481  HF_DisplayMode displayMode) = 0;
1482 
1483  /**
1484  * @brief Get Desktop display mode.
1485  *
1486  * @param displayIndex The index of the display to query.
1487  * @param[out] displayMode An HF_DisplayMode structure filled in
1488  * with the current display mode.
1489  *
1490  * @return true if success, else false.
1491  */
1492  virtual bool getDesktopDisplayMode(int32_hf displayIndex,
1493  HF_DisplayMode *displayMode) = 0;
1494 
1495  /**
1496  * @brief Use this function to get the desktop area represented
1497  * by a display, with the primary display located at 0,0.
1498  *
1499  * @param displayIndex The index of the display to query.
1500  *
1501  * @return Rect filled in with the display bounds.
1502  */
1503  virtual HFCore::Rect getDisplayBoundsRect(int32_hf displayIndex) = 0;
1504 
1505  /**
1506  * @brief Use this function to get the closest match to the
1507  * requested display mode.
1508  *
1509  * @param displayIndex The index of the display to query.
1510  * @param target An HF_DisplayMode structure containing the
1511  * desired display mode.
1512  * @param[out] closest An HF_DisplayMode structure filled in
1513  * with the closest match of the available display modes.
1514  *
1515  * @return Returns the passed in value closest or NULL if no
1516  * matching video mode was available.
1517  */
1518  virtual bool getClosestDisplayMode(int32_hf displayIndex, HF_DisplayMode target,
1519  HF_DisplayMode *closest) = 0;
1520 
1521  /**
1522  * @brief Use this function to get information about a specific
1523  * display mode.
1524  *
1525  * @param displayIndex The index of the display to query.
1526  * @param displayModeIndex The index of the display mode to query.
1527  * @param[out] displayMode An HF_DisplayMode structure filled in
1528  * with the mode at displayModeIndex.
1529  *
1530  * @return true if success, else false.
1531  */
1532  virtual bool getDisplayMode(int32_hf displayIndex, int32_hf displayModeIndex,
1533  HF_DisplayMode *displayMode) = 0;
1534 
1535  /**
1536  * @brief Use this function to return the number of available
1537  * display modes.
1538  *
1539  * @param displayIndex The index of the display to query.
1540  *
1541  * @return Returns a number >= 1 on success or a negative error
1542  * code on failure.
1543  */
1544  virtual int32_hf getNumDisplayModes(int32_hf displayIndex) = 0;
1545 
1546  /**
1547  * @brief Use this function to return the number of available
1548  * video displays.
1549  *
1550  * @return Returns a number >= 1 or a negative error code on
1551  * failure.
1552  */
1553  virtual int32_hf getNumVideoDisplays() = 0;
1554 
1555  /**
1556  * @brief Get main Window OpenGL context.
1557  *
1558  * @return Main window OpenGL context.
1559  */
1561 
1562  /**
1563  * @brief Create OpenGL context for given window.
1564  *
1565  * @param window Window to create OpenGL context for.
1566  *
1567  * @return openGLcontext_hf associated with window.
1568  *
1569  * @see deleteOpenGLContext()
1570  * @see safeDeleteOpenGLContext()
1571  * @see processSafeDeleteListOpenGLContext()
1572  * @see makeCurrentOpenGLContext()
1573  */
1574  virtual openGLContext_hf createOpenGLContext(HF_Window window) = 0;
1575 
1576  /**
1577  * @brief Delete OpenGL context.
1578  *
1579  * @param ctx OpenGL context.
1580  *
1581  * @see createOpenGLContext()
1582  * @see safeDeleteOpenGLContext()
1583  * @see processSafeDeleteListOpenGLContext()
1584  * @see makeCurrentOpenGLContext()
1585  */
1586  virtual void deleteOpenGLContext(openGLContext_hf ctx) = 0;
1587 
1588  /**
1589  * @brief Safe delete OpenGL context.
1590  *
1591  * Safe delete = put the context in cache to be processed later
1592  * with a call to processSafeDeleteListOpenGLContext(). Useful
1593  * if you don't want to destroy immediately.
1594  * processSafeDeleteListOpenGLContext() is always called before
1595  * exit of program.
1596  *
1597  * @param ctx OpenGL context.
1598  *
1599  * @see createOpenGLContext()
1600  * @see deleteOpenGLContext()
1601  * @see processSafeDeleteListOpenGLContext()
1602  * @see makeCurrentOpenGLContext()
1603  */
1604  virtual void safeDeleteOpenGLContext(openGLContext_hf ctx) = 0;
1605 
1606  /**
1607  * @brief Process the cache of OpenGL context's to destroy
1608  * (those put by safeDeleteOpenGLContext()).
1609  *
1610  * @see createOpenGLContext()
1611  * @see deleteOpenGLContext()
1612  * @see safeDeleteOpenGLContext()
1613  * @see makeCurrentOpenGLContext()
1614  */
1615  virtual void processSafeDeleteListOpenGLContext() = 0;
1616 
1617  /**
1618  * @brief Set current OpenGL context for given Window.
1619  *
1620  * @param window Window to set OpenGL context for.
1621  * @param ctx OpenGL context.
1622  *
1623  * @see createOpenGLContext()
1624  * @see deleteOpenGLContext()
1625  * @see safeDeleteOpenGLContext()
1626  * @see processSafeDeleteListOpenGLContext()
1627  */
1628  virtual void makeCurrentOpenGLContext(HF_Window window,
1629  openGLContext_hf ctx) = 0;
1630 
1631  /**
1632  * @brief Use this function to return whether the screensaver is
1633  * currently enabled.
1634  *
1635  * @return true if screensaver is enabled, else false.
1636  *
1637  * @see enableScreenSaver()
1638  * @see disableScreenSaver()
1639  */
1640  virtual bool isScreenSaverEnabled() = 0;
1641 
1642  /**
1643  * @brief Use this function to allow the screen to be blanked by
1644  * a screen saver.
1645  *
1646  * @see isScreenSaverEnabled()
1647  * @see disableScreenSaver()
1648  */
1649  virtual void enableScreenSaver() = 0;
1650 
1651  /**
1652  * @brief Use this function to prevent the screen from being
1653  * blanked by a screen saver.
1654  *
1655  * @see isScreenSaverEnabled()
1656  * @see enableScreenSaver()
1657  */
1658  virtual void disableScreenSaver() = 0;
1659 
1660  /**
1661  * @brief Use this function to get UTF-8 text from the clipboard.
1662  *
1663  * @return UTF-8 text string from the clipboard.
1664  *
1665  * @see setClipboardText()
1666  */
1667  virtual std::string getClipboardText() = 0;
1668 
1669  /**
1670  * @brief Use this function to put UTF-8 text into the clipboard.
1671  *
1672  * @param text Clipboard text.
1673  *
1674  * @see getClipboardText()
1675  */
1676  virtual void setClipboardText(std::string &text) = 0;
1677 
1678  /**
1679  * @brief Use this function to determine the L1 cache line size
1680  * of the CPU.
1681  *
1682  * @return L1 cache line size of the CPU.
1683  *
1684  * @see getCPUCount()
1685  */
1686  virtual int32_hf getCPUCacheLineSize() = 0;
1687 
1688  /**
1689  * @brief Use this function to return the number of CPU cores
1690  * available.
1691  *
1692  * @return Number of CPU cores available.
1693  *
1694  * @see getCPUCacheLineSize()
1695  */
1696  virtual int32_hf getCPUCount() = 0;
1697 
1698  /**
1699  * @brief Use this function to get the current power supply
1700  * details.
1701  *
1702  * @param[out] seconds Seconds of battery life left. You can pass
1703  * a NULL here if you don't care. Will return -1 if we can't
1704  * determine a value, or we're not running on a battery.
1705  * @param[out] percent Percentage of battery life left, between 0
1706  * and 100. You can pass a NULL here if you don't care. Will
1707  * return -1 if we can't determine a value, or we're not running
1708  * on a battery
1709  *
1710  * @return Returns the state of the battery.
1711  */
1712  virtual HF_PowerState getPowerInfo(int32_hf *seconds, int32_hf *percent) = 0;
1713 
1714  /**
1715  * @brief Use this function to count the number of joysticks
1716  * attached to the system.
1717  *
1718  * @return Number of joysticks attached to the system.
1719  */
1720  virtual int32_hf getNumGamePads() = 0;
1721 
1722  /**
1723  * @brief Get main window/screen width.
1724  *
1725  * @return Window width.
1726  *
1727  * @see getScreenHeight()
1728  */
1729  virtual int32_hf getScreenWidth() = 0;
1730 
1731  /**
1732  * @brief Get main window/screen height.
1733  *
1734  * @return Window height.
1735  *
1736  * @see getScreenWidth()
1737  */
1738  virtual int32_hf getScreenHeight() = 0;
1739 
1740  /**
1741  * @brief Get main window/screen width and height.
1742  *
1743  * @param[out] w Window width if not NULL.
1744  * @param[out] h Window height if not NULL.
1745  *
1746  * @see setScreenSize()
1747  */
1748  virtual void getScreenSize(int32_hf *w, int32_hf *h) = 0;
1749 
1750  /**
1751  * @brief Set main window/screen width and height.
1752  *
1753  * @param w Window width to set.
1754  * @param h Window height to set.
1755  *
1756  * @see getScreenSize()
1757  */
1758  virtual void setScreenSize(int32_hf w, int32_hf h) = 0;
1759 
1760  /**
1761  * @brief Get logical screen width.
1762  *
1763  * @return Logical screen width.
1764  *
1765  * @note Only useful when LogicalScaleMode is enabled. See
1766  * Graphics::setLogicalScale() for more information.
1767  *
1768  * @see getLogicalScreenHeight()
1769  * @see getLogicalScreenSize()
1770  * @see setLogicalScreenSize()
1771  * @see setLogicalViewportSize()
1772  * @see getLogicalViewportSize()
1773  * @see getLogicalOrthoSize()
1774  */
1775  virtual int32_hf getLogicalScreenWidth() = 0;
1776 
1777  /**
1778  * @brief Get logical screen height.
1779  *
1780  * @return Logical screen height.
1781  *
1782  * @note Only useful when LogicalScaleMode is enabled. See
1783  * Graphics::setLogicalScale() for more information.
1784  *
1785  * @see getLogicalScreenWidth()
1786  * @see getLogicalScreenSize()
1787  * @see setLogicalScreenSize()
1788  * @see setLogicalViewportSize()
1789  * @see getLogicalViewportSize()
1790  * @see getLogicalOrthoSize()
1791  */
1792  virtual int32_hf getLogicalScreenHeight() = 0;
1793 
1794  /**
1795  * @brief Get logical screen width and height.
1796  *
1797  * @param w Logical screen width if not NULL.
1798  * @param h Logical screen height if not NULL.
1799  *
1800  * @note Only useful when LogicalScaleMode is enabled. See
1801  * Graphics::setLogicalScale() for more information.
1802  *
1803  * @see getLogicalScreenWidth()
1804  * @see getLogicalScreenHeight()
1805  * @see setLogicalScreenSize()
1806  * @see setLogicalViewportSize()
1807  * @see getLogicalViewportSize()
1808  * @see getLogicalOrthoSize()
1809  */
1810  virtual void getLogicalScreenSize(int32_hf *w, int32_hf *h) = 0;
1811 
1812  /**
1813  * @brief Set logical screen width and height.
1814  *
1815  * @param w Logical screen width.
1816  * @param h Logical screen height.
1817  *
1818  * @note Only useful when LogicalScaleMode is enabled. See
1819  * Graphics::setLogicalScale() for more information.
1820  *
1821  * @see getLogicalScreenWidth()
1822  * @see getLogicalScreenHeight()
1823  * @see getLogicalScreenSize()
1824  * @see setLogicalViewportSize()
1825  * @see getLogicalViewportSize()
1826  * @see getLogicalOrthoSize()
1827  */
1828  virtual void setLogicalScreenSize(int32_hf w, int32_hf h) = 0;
1829 
1830  /**
1831  * @brief Setup the logical viewport.
1832  *
1833  * @param x Pixel coordinate of the upper-left corner of the
1834  * viewport. Unless you want to render to a subset, this member
1835  * can be set to 0.
1836  * @param y Pixel coordinate of the upper-left corner of the
1837  * viewport. Unless you want to render to a subset, this member
1838  * can be set to 0.
1839  * @param w Width dimension of the clip volume, in pixels. Unless
1840  * you are rendering only to a subset, this member should be set
1841  * to the width of the screen.
1842  * @param h Height dimension of the clip volume, in pixels.
1843  * Unless you are rendering only to a subset, this member should
1844  * be set to the height of the screen.
1845  *
1846  * @note Only useful when LogicalScaleMode is enabled. See
1847  * Graphics::setLogicalScale() for more information.
1848  *
1849  * @see getLogicalScreenWidth()
1850  * @see getLogicalScreenHeight()
1851  * @see getLogicalScreenSize()
1852  * @see setLogicalScreenSize()
1853  * @see getLogicalViewportSize()
1854  * @see getLogicalOrthoSize()
1855  */
1856  virtual void setLogicalViewportSize(int32_hf x, int32_hf y,
1857  int32_hf w, int32_hf h) = 0;
1858 
1859  /**
1860  * @brief Get logical viewport size.
1861  *
1862  * @param x Upper-left X corner of the viewport if not NULL.
1863  * @param y Upper-left Y corner of the viewport if not NULL.
1864  * @param w Width of the viewport if not NULL.
1865  * @param h Height of the viewport if not NULL.
1866  *
1867  * @note Only useful when LogicalScaleMode is enabled. See
1868  * Graphics::setLogicalScale() for more information.
1869  *
1870  * @see getLogicalScreenWidth()
1871  * @see getLogicalScreenHeight()
1872  * @see getLogicalScreenSize()
1873  * @see setLogicalScreenSize()
1874  * @see setLogicalViewportSize()
1875  * @see getLogicalOrthoSize()
1876  */
1877  virtual void getLogicalViewportSize(int32_hf *x, int32_hf *y,
1878  int32_hf *w, int32_hf *h) = 0;
1879 
1880  /**
1881  * @brief Get logical ortho size.
1882  *
1883  * @param w Ortho width.
1884  * @param h Ortho height.
1885  *
1886  * @note Only useful when LogicalScaleMode is enabled. See
1887  * Graphics::setLogicalScale() for more information.
1888  *
1889  * @see getLogicalScreenWidth()
1890  * @see getLogicalScreenHeight()
1891  * @see getLogicalScreenSize()
1892  * @see setLogicalScreenSize()
1893  * @see setLogicalViewportSize()
1894  * @see getLogicalViewportSize()
1895  */
1896  virtual void getLogicalOrthoSize(fp32_hf *w, fp32_hf *h) = 0;
1897 
1898  /**
1899  * @brief Get Desktop Width.
1900  *
1901  * @return Desktop width.
1902  *
1903  * @see getDesktopHeight()
1904  */
1905  virtual int32_hf getDesktopWidth() = 0;
1906 
1907  /**
1908  * @brief Get Desktop Height.
1909  *
1910  * @return Desktop Height.
1911  *
1912  * @see getDesktopWidth()
1913  */
1914  virtual int32_hf getDesktopHeight() = 0;
1915 
1916  /**
1917  * @brief Get Desktop width and height.
1918  *
1919  * @param w Desktop width, if not NULL.
1920  * @param h Desktop height, if not NULL.
1921  *
1922  * @see setDesktopSize()
1923  */
1924  virtual void getDesktopSize(int32_hf *w, int32_hf *h) = 0;
1925 
1926  /**
1927  * @brief Get Desktop width and height.
1928  *
1929  * @param w Desktop width to set.
1930  * @param h Desktop height to set.
1931  *
1932  * @see getDesktopSize()
1933  */
1934  virtual void setDesktopSize(int32_hf w, int32_hf h) = 0;
1935 
1936  /**
1937  * @brief Get Preferences SoundPlayer music volume for current
1938  * profile.
1939  *
1940  * @return Music volume in the range 0 - 1000.
1941  *
1942  * @see getPrefSoundVol()
1943  * @see getPrefFullscreen()
1944  * @see getPrefCustomCursor()
1945  * @see getPrefLanguage()
1946  */
1947  virtual int32_hf getPrefMusicVol();
1948 
1949  /**
1950  * @brief Get Preferences Sound volume for current profile.
1951  *
1952  * @return Sound volume in the range 0 - 1000.
1953  *
1954  * @see getPrefMusicVol()
1955  * @see getPrefFullscreen()
1956  * @see getPrefCustomCursor()
1957  * @see getPrefLanguage()
1958  */
1959  virtual int32_hf getPrefSoundVol();
1960 
1961  /**
1962  * @brief Get Preferences Fullscreen mode for current profile.
1963  *
1964  * @return true if fullscreen, else false.
1965  *
1966  * @see getPrefMusicVol()
1967  * @see getPrefSoundVol()
1968  * @see getPrefCustomCursor()
1969  * @see getPrefLanguage()
1970  */
1971  virtual bool getPrefFullscreen();
1972 
1973  /**
1974  * @brief Get Preferences custom cursor mode for current profile.
1975  *
1976  * @return true if using custom cursor, else false.
1977  *
1978  * @see getPrefMusicVol()
1979  * @see getPrefSoundVol()
1980  * @see getPrefFullscreen()
1981  * @see getPrefLanguage()
1982  */
1983  virtual bool getPrefCustomCursor();
1984 
1985  /**
1986  * @brief Get Preferences language for current profile.
1987  *
1988  * @return Preference language.
1989  *
1990  * @see getPrefMusicVol()
1991  * @see getPrefSoundVol()
1992  * @see getPrefFullscreen()
1993  * @see getPrefCustomCursor()
1994  */
1995  virtual UString getPrefLanguage();
1996 
1997  /**
1998  * @brief Create new Image.
1999  *
2000  * @return Image instance.
2001  */
2002  virtual Image *createImage() = 0;
2003 
2004  /**
2005  * @brief Get audio device id for the default device opened during
2006  * Environment::init().
2007  *
2008  * @return HF_AudioDeviceID for default audio device opened during
2009  * Environment::init().
2010  */
2012 
2013  /**
2014  * @brief Get HF_AudioRate enum for rate value.
2015  *
2016  * This function is useful for converting Game config value to
2017  * enum value.
2018  *
2019  * @param rate Rate to convert to HF_AudioRate enum.
2020  *
2021  * @return HF_AudioRate enum for rate value.
2022  */
2024 
2025  /**
2026  * @brief Get HF_AudioChannels enum for channels value.
2027  *
2028  * This function is useful for converting Game config value to
2029  * enum value.
2030  *
2031  * @param channels Channels to convert to HF_AudioChannels enum.
2032  *
2033  * @return HF_AudioChannels enum for channels value.
2034  */
2036 
2037  /**
2038  * @brief Get HF_AudioBufferSize enum for buffer value.
2039  *
2040  * This function is useful for converting Game config value to
2041  * enum value.
2042  *
2043  * @param buffer Buffer size to convert to HF_AudioBufferSize
2044  * enum.
2045  *
2046  * @return HF_AudioBufferSize enum for buffer value.
2047  */
2049 
2050  /**
2051  * @brief Get int value for rate enum.
2052  *
2053  * @param rate HF_AudioRate enum value.
2054  *
2055  * @return int value for rate enum.
2056  */
2058 
2059  /**
2060  * @brief Get int value for channels enum.
2061  *
2062  * @param channels HF_AudioChannels enum value.
2063  *
2064  * @return int value for channels enum.
2065  */
2067 
2068  /**
2069  * @brief Get int value for bufferSize enum.
2070  *
2071  * @param bufferSize HF_AudioBufferSize enum value.
2072  *
2073  * @return int value for bufferSize enum.
2074  */
2076 
2077  /**
2078  * @brief Determines whether we've a Mouse double click.
2079  *
2080  * If there is a Mouse double click within DOUBLE_CLICK_MAX_DELAY
2081  * return true.
2082  *
2083  * @return true if Mouse double click, else false.
2084  */
2085  bool mouseDoubleClickDetected();
2086 
2087  /**
2088  * @brief Get Window title name.
2089  *
2090  * @return Window title name.
2091  */
2093 
2094  /**
2095  * @brief Get Publisher Name.
2096  *
2097  * @return Publisher Name.
2098  */
2100 
2101  /**
2102  * @brief Get Preferences file name.
2103  *
2104  * @return Preferences file name.
2105  */
2107 
2108  /**
2109  * @brief Get PakInterface PAK data file name.
2110  *
2111  * @return PAK file name.
2112  */
2114 
2115  /**
2116  * @brief Get Window icon path.
2117  *
2118  * @return Window icon path.
2119  */
2121 
2122  /**
2123  * @brief Get Android java activity class path.
2124  *
2125  * @return Android java activity class path.
2126  */
2128 
2129  /**
2130  * @brief Get singleton Game instance.
2131  *
2132  * @return Singleton Game instance.
2133  */
2134  Game *getGameInstance();
2135 
2136  /**
2137  * @brief Compress inData using zlib.
2138  *
2139  * @param inData Data to compress.
2140  * @param inDataSize Data to compress size.
2141  * @param[out] outData Compressed output data.
2142  * @param[out] outDataSize Compressed output data size.
2143  * @param compLevel zlib compression level to use.
2144  *
2145  * @return true if successful, else false.
2146  *
2147  * @see zlibDeCompress()
2148  * @see loadzlibCompressedFile()
2149  * @see savezlibCompressedFile()
2150  */
2151  static bool zlibCompress(const int8_hf *inData,
2152  int32_hf inDataSize,
2153  int8_hf **outData,
2154  int32_hf *outDataSize,
2155  int32_hf compLevel = Z_DEFAULT_COMPRESSION);
2156 
2157  /**
2158  * @brief Decompress inData using zlib.
2159  *
2160  * @param inData Data to decompress.
2161  * @param inDataSize Data to decompress size.
2162  * @param[out] outData Decompressed output data.
2163  * @param[out] outDataSize Decompressed output data size.
2164  *
2165  * @return true if successful, else false.
2166  *
2167  * @see zlibCompress()
2168  * @see loadzlibCompressedFile()
2169  * @see savezlibCompressedFile()
2170  */
2171  static bool zlibDeCompress(const int8_hf *inData,
2172  int32_hf inDataSize,
2173  int8_hf **outData,
2174  int32_hf *outDataSize);
2175 
2176  /**
2177  * @brief Load a zlib compressed file and return raw data.
2178  *
2179  * @param fileName File name to load and decompress.
2180  * @param[out] outData Decompressed output data.
2181  * @param[out] outDataSize Decompressed output data size.
2182  *
2183  * @return true if successful, else false.
2184  *
2185  * @see zlibCompress()
2186  * @see zlibDeCompress()
2187  * @see savezlibCompressedFile()
2188  */
2189  static bool loadzlibCompressedFile(const int8_hf *fileName,
2190  int8_hf **outData,
2191  int32_hf *outDataSize);
2192 
2193  /**
2194  * @brief Compress inFileName and store compressed as outFileName.
2195  *
2196  * @param inFileName Input file.
2197  * @param outFileName Output file.
2198  *
2199  * @return true if successful, else false.
2200  *
2201  * @see zlibCompress()
2202  * @see zlibDeCompress()
2203  * @see loadzlibCompressedFile()
2204  */
2205  static bool savezlibCompressedFile(const int8_hf *inFileName,
2206  const int8_hf *outFileName);
2207 
2208  /**
2209  * @brief Store and save inData in a new file with fileName.
2210  *
2211  * @param fileName File name.
2212  * @param inData Input data to store in file.
2213  * @param inDataSize Input data size.
2214  *
2215  * @return true if successful, else false.
2216  */
2217  static bool saveFile(const int8_hf *fileName,
2218  const int8_hf *inData,
2219  int32_hf inDataSize);
2220 
2221  protected:
2222  /**
2223  * @brief Constructor.
2224  */
2225  Environment();
2226 
2227  /**
2228  * @brief Destructor.
2229  */
2230  virtual ~Environment();
2231 
2232  /**
2233  * @brief Initiate TinyXML = Set IO callback hooks.
2234  *
2235  * IO hooks:
2236  * TiXmlSetIOHooks(TiXmlFileOpen, TiXmlFileRead,
2237  * TiXmlFileSize, TiXmlFileClose)
2238  */
2239  void InitTinyXML();
2240 
2241  /**
2242  * @brief TinyXML IO hook for FileOpen.
2243  *
2244  * @param pFilePathUtf8 File path Utf-8.
2245  *
2246  * @return File handle void pointer.
2247  */
2248  static void *TiXmlFileOpen(const int8_hf *pFilePathUtf8);
2249 
2250  /**
2251  * @brief TinyXML IO hook for FileRead.
2252  *
2253  * @param pContext File handle context.
2254  * @param pBuffer Buffer.
2255  * @param readSizeBytes Read size bytes.
2256  *
2257  * @return 1 if successful, else 0.
2258  */
2259  static int32_hf TiXmlFileRead(void *pContext, void *pBuffer,
2260  int32_hf readSizeBytes);
2261 
2262  /**
2263  * @brief TinyXML IO hook for FileSize.
2264  *
2265  * @param pContext File handle context.
2266  *
2267  * @return File size.
2268  */
2269  static int32_hf TiXmlFileSize(void *pContext);
2270 
2271  /**
2272  * @brief TinyXML IO hook for FileClose.
2273  *
2274  * @param pContext File handle context.
2275  */
2276  static void TiXmlFileClose(void *pContext);
2277 
2278  private:
2279  static Environment *gInstance;
2280 
2281  protected:
2282  /**
2283  * @brief Singleton Game instance.
2284  */
2286 
2287  /**
2288  * @brief Window title.
2289  */
2291 
2292  /**
2293  * @brief Publisher name.
2294  */
2296 
2297  /**
2298  * @brief Preferences file name.
2299  */
2301 
2302  /**
2303  * @brief PakInterface PAK file name.
2304  */
2306 
2307  /**
2308  * @brief PakInterface PAK file password.
2309  */
2311 
2312  /**
2313  * @brief Window icon path.
2314  */
2316 
2317  /**
2318  * @brief Android java activity class path.
2319  */
2321 
2322  /**
2323  * @brief ActorManager interface instance.
2324  */
2326 
2327  /**
2328  * @brief Default audio device id opened during
2329  * Environment::init().
2330  */
2332  };
2333 }
2334 
2335 // shorthand notation for debug logging:
2336 #if defined(HF_PLATFORM_WINDOWS_D3D9)
2337 #ifdef __MINGW32__
2338 #define envDebugLog(format, args...) HFCore::Environment::instance()->debugLog( format , ## args )
2339 #define envEngineLog(format, args...) HFCore::Environment::instance()->engineLog( format , ## args )
2340 #define envGameLog(format, args...) HFCore::Environment::instance()->gameLog( format , ## args )
2341 #else
2342 #define envDebugLog(format,...) HFCore::Environment::instance()->debugLog( format , __VA_ARGS__ )
2343 #define envEngineLog(format,...) HFCore::Environment::instance()->engineLog( format , __VA_ARGS__ )
2344 #define envGameLog(format,...) HFCore::Environment::instance()->gameLog( format , __VA_ARGS__ )
2345 #endif
2346 #elif defined(HF_PLATFORM_WINDOWS_OPENGL)
2347 #ifdef __MINGW32__
2348 #define envDebugLog(format, args...) HFCore::Environment::instance()->debugLog( format , ## args )
2349 #define envEngineLog(format, args...) HFCore::Environment::instance()->engineLog( format , ## args )
2350 #define envGameLog(format, args...) HFCore::Environment::instance()->gameLog( format , ## args )
2351 #else
2352 #define envDebugLog(format,...) HFCore::Environment::instance()->debugLog( format , __VA_ARGS__ )
2353 #define envEngineLog(format,...) HFCore::Environment::instance()->engineLog( format , __VA_ARGS__ )
2354 #define envGameLog(format,...) HFCore::Environment::instance()->gameLog( format , __VA_ARGS__ )
2355 #endif
2356 #elif defined(HF_PLATFORM_OSX)
2357 #define envDebugLog(format, args...) HFCore::Environment::instance()->debugLog( format , ## args )
2358 #define envEngineLog(format, args...) HFCore::Environment::instance()->engineLog( format , ## args )
2359 #define envGameLog(format, args...) HFCore::Environment::instance()->gameLog( format , ## args )
2360 #elif defined(HF_PLATFORM_LINUX) // used for Doxygen:
2361 /**
2362  * @brief Shortcut macro for logging to 'debug.log'.
2363  */
2364 #define envDebugLog(format, args...) HFCore::Environment::instance()->debugLog( format , ## args )
2365 
2366 /**
2367  * @brief Shortcut macro for logging to 'engine.log'.
2368  */
2369 #define envEngineLog(format, args...) HFCore::Environment::instance()->engineLog( format , ## args )
2370 
2371 /**
2372  * @brief Shortcut macro for logging to 'game.log'.
2373  */
2374 #define envGameLog(format, args...) HFCore::Environment::instance()->gameLog( format , ## args )
2375 #elif defined (HF_PLATFORM_IOS)
2376 #define envDebugLog(format, args...) HFCore::Environment::instance()->debugLog( format , ## args )
2377 #define envEngineLog(format, args...) HFCore::Environment::instance()->engineLog( format , ## args )
2378 #define envGameLog(format, args...) HFCore::Environment::instance()->gameLog( format , ## args )
2379 #elif defined(HF_PLATFORM_ANDROID)
2380 #define envDebugLog(format, args...) HFCore::Environment::instance()->debugLog( format , ## args )
2381 #define envEngineLog(format, args...) HFCore::Environment::instance()->engineLog( format , ## args )
2382 #define envGameLog(format, args...) HFCore::Environment::instance()->gameLog( format , ## args )
2383 #else
2384 #error "Environment (panic) -> unknown platform"
2385 #endif
unsigned int uint32_hf
A type definition for unsigned int.
Definition: HFDataTypes.h:354
virtual ~Environment()
Destructor.
Definition: Environment.cpp:87
UString getWindowIconPath()
Get Window icon path.
virtual bool getClosestDisplayMode(int32_hf displayIndex, HF_DisplayMode target, HF_DisplayMode *closest)=0
Use this function to get the closest match to the requested display mode.
virtual HF_AudioRate getAudioRateEnumForInt(int32_hf rate)
Get HF_AudioRate enum for rate value.
virtual int32_hf getDesktopHeight()=0
Get Desktop Height.
virtual int32_hf getCPUCacheLineSize()=0
Use this function to determine the L1 cache line size of the CPU.
virtual int32_hf hf_stricmp(const int8_hf *pStr1, const int8_hf *pStr2)=0
&#39;stricmp&#39; std lib wrapper. Compare two strings.
std::vector< VertexPosColNor > VertexPosColNorVector
typedef for Vector holding VertexPosColNor struct.
Definition: Geometry.h:361
virtual int32_hf getMaxFrameRate()=0
Get Max frame rate.
virtual bool getSystemMouseShown()=0
Checks if system mouse is shown.
std::map< UString, UString > UStringMap
typedef for Map for holding UString pair.
Definition: StringUtil.h:98
virtual void getLogicalOrthoSize(fp32_hf *w, fp32_hf *h)=0
Get logical ortho size.
virtual void pauseTime()=0
Pause time.
Interface useful for controlling the Camera.
Definition: Camera.h:70
virtual fp32_hf getTime()=0
Get Time in Seconds since start.
virtual void hideWindow(HF_Window window)=0
Hide Window.
virtual void init(Game *game, const UString &windowTitle, const UString &publisherName, const UString &prefFileName, const UString &pakDataFile, const UString &pakDataFilePassword, const UString &windowIconPath, uint8_hf *cryptoKey, const UString &androidActivityClass)
Initializes Environment and all platform interfaces.
virtual bool isWindowResizable()=0
Checks if window is resizable.
virtual UString getPrefLanguage()
Get Preferences language for current profile.
virtual int32_hf getCPUCount()=0
Use this function to return the number of CPU cores available.
virtual int32_hf getDesktopWidth()=0
Get Desktop Width.
virtual int32_hf getNumVideoDisplays()=0
Use this function to return the number of available video displays.
virtual Camera * getCamera()=0
Get pointer to Camera interface.
Interface for unicode string class UString.
Definition: UString.h:35
std::vector< VertexPosTex > VertexPosTexVector
typedef for Vector holding VertexPosTex struct.
Definition: Geometry.h:351
Interface for PersistenceLayer base class.
virtual void setMaxFrameRate(int32_hf framesPerSecond)=0
Set max frame rate.
Interface useful when rendering custom Geometry.
Definition: Geometry.h:70
virtual void processSafeDeleteListWindow()=0
Process the cache of Window&#39;s to destroy (those put by safeDestroyWindow()).
virtual openGLContext_hf getMainWindowOpenGLContext()=0
Get main Window OpenGL context.
Interface for handling Actor&#39;s.
Definition: ActorManager.h:69
virtual bool getPrefFullscreen()
Get Preferences Fullscreen mode for current profile.
virtual HFCore::Font * getSystemFont()=0
Get system Font in use for debug rendering.
virtual void getLogicalScreenSize(int32_hf *w, int32_hf *h)=0
Get logical screen width and height.
virtual Touch * getTouch(int32_hf touchId)=0
Get Touch at given index.
void InitTinyXML()
Initiate TinyXML = Set IO callback hooks.
Definition: Environment.cpp:98
virtual void setEngineLogFile(FILE *logFile)=0
Set engine log file to use.
Thread info struct used for HFCore::ThreadListener callbacks.
Definition: HFDataTypes.h:633
int int32_hf
A type definition for int.
Definition: HFDataTypes.h:349
virtual void showCustomCursor(bool show)=0
Determines whether to show or hide custom mouse cursor.
virtual int32_hf getNumDisplayModes(int32_hf displayIndex)=0
Use this function to return the number of available display modes.
Interface for input type GamePad / Joystick.
Definition: GamePad.h:40
virtual StringUtil::UStringMap & getGameConfigMap()=0
Get game configuration UStringMap which contains all settings stored in &#39;data/config.xml&#39;.
virtual void drawCustomMouseCursor(Graphics *g)=0
Draw custom mouse cursor if enabled and set (called automatically from Graphics::endScene() method)...
virtual bool isFullScreen()=0
Checks if currently in fullscreen mode.
Environment()
Constructor.
Definition: Environment.cpp:75
void fireGamePadAdded(int32_hf gamePadId)
Called automatically when a GamePad is added. It then calls callback method Game::handleGamePadAdded(...
static bool savezlibCompressedFile(const int8_hf *inFileName, const int8_hf *outFileName)
Compress inFileName and store compressed as outFileName.
HF_AudioRate
Audio rate / frequency enum.
Definition: HFDataTypes.h:599
virtual void showWindow(HF_Window window)=0
Show Window.
Interface for playing Sound&#39;s and Music streams.
Definition: SoundPlayer.h:82
UString mPrefFileName
Preferences file name.
Definition: Environment.h:2300
HF_PowerState
Power status enum.
Definition: HFDataTypes.h:475
void fireTouchAdded(int32_hf touchId)
Called automatically when a Touch is added. It then calls callback method Game::handleTouchAdded().
virtual void engineLog(const int8_hf *fmt,...)=0
Write to engine log.
virtual int32_hf getAudioBufferSizeIntForEnum(HF_AudioBufferSize bufferSize)
Get int value for bufferSize enum.
virtual void setWindowSize(HF_Window window, int32_hf w, int32_hf h)=0
Set Window size.
virtual void enableFullScreenToggle()=0
Enable fullscreen toggle.
static bool zlibDeCompress(const int8_hf *inData, int32_hf inDataSize, int8_hf **outData, int32_hf *outDataSize)
Decompress inData using zlib.
virtual int32_hf getLogicalScreenHeight()=0
Get logical screen height.
virtual void destroy()
Destroy the singleton Environment instance and do cleanup.
virtual void debugLog(const int8_hf *fmt,...)=0
Write to debug log and console (printf).
virtual HF_AudioChannels getAudioChannelsEnumForInt(int32_hf channels)
Get HF_AudioChannels enum for channels value.
Framework data types, defines, typedef&#39;s, enum and structs.
virtual uint8_hf * getCryptoKey()=0
Get currently stored crypto key.
virtual HF_AudioBufferSize getAudioBufferSizeEnumForInt(int32_hf buffer)
Get HF_AudioBufferSize enum for buffer value.
virtual bool isWindowBorderless()=0
Checks if window is borderless.
position window centered
Definition: HFDataTypes.h:458
VertexType
Vertex type enum.
Definition: Geometry.h:321
virtual void setWindowDisplayMode(HF_Window window, HF_DisplayMode displayMode)=0
Set Window display mode for a given window.
virtual FileDirUtils * getFileDirUtils()=0
Get pointer to FileDirUtils interface.
virtual SoundPlayer * getSoundPlayer()=0
Get pointer to SoundPlayer interface.
virtual void getDesktopSize(int32_hf *w, int32_hf *h)=0
Get Desktop width and height.
virtual Mouse * getMouse(int32_hf mouseId)=0
Get Mouse for a given index.
virtual int32_hf getPrefSoundVol()
Get Preferences Sound volume for current profile.
std::vector< VertexAttribute > VertexAttributeVector
typedef for Vector holding custom vertex attributes.
Definition: Geometry.h:391
std::vector< VertexPosColNorTex > VertexPosColNorTexVector
typedef for Vector holding VertexPosColNorTex struct.
Definition: Geometry.h:371
static void * TiXmlFileOpen(const int8_hf *pFilePathUtf8)
TinyXML IO hook for FileOpen.
virtual void setCustomMouseCursor(Image *cursorImage, Vector2 &offset)=0
Set Custom Image to use as mouse cursor.
virtual void setLogicalScreenSize(int32_hf w, int32_hf h)=0
Set logical screen width and height.
virtual uint32_hf getWindowFlags(HF_Window window)=0
Get Window flags.
virtual void enableScreenSaver()=0
Use this function to allow the screen to be blanked by a screen saver.
UString getPakDataFileName()
Get PakInterface PAK data file name.
virtual void disableFullScreenToggle()=0
Disable fullscreen toggle.
virtual void setUpdatePaused(bool pause)=0
Determines whether to pause the game loop or not.
Interface for Web related things.
Definition: WebManager.h:35
UString getPublisherName()
Get Publisher Name.
HF_AudioBufferSize
Audio buffer size enum.
Definition: HFDataTypes.h:622
bool mouseDoubleClickDetected()
Determines whether we&#39;ve a Mouse double click.
virtual void initTimer()=0
Initialize timer.
virtual int32_hf getScreenWidth()=0
Get main window/screen width.
virtual bool isTimePaused()=0
Checks if time is paused.
virtual std::string getClipboardText()=0
Use this function to get UTF-8 text from the clipboard.
Display mode struct.
Definition: HFDataTypes.h:487
virtual void toggleFullScreen()=0
Toggle fullscreen / windowed mode.
UString getPrefFileName()
Get Preferences file name.
virtual bool isScreenSaverEnabled()=0
Use this function to return whether the screensaver is currently enabled.
virtual void setLogicalViewportSize(int32_hf x, int32_hf y, int32_hf w, int32_hf h)=0
Setup the logical viewport.
void fireTouchRemoved(int32_hf touchId)
Called automatically when a Touch is removed. It then calls callback method Game::handleTouchRemoved(...
void * openGLContext_hf
A type definition for void*.
Definition: HFDataTypes.h:319
UString mPakDataFile
PakInterface PAK file name.
Definition: Environment.h:2305
virtual void setWindowData(HF_Window window, const int8_hf *name, void *data)=0
Set / associate an arbitrary named pointer with a window.
static bool loadzlibCompressedFile(const int8_hf *fileName, int8_hf **outData, int32_hf *outDataSize)
Load a zlib compressed file and return raw data.
virtual Graphics * getGraphics()=0
Get Graphics interface.
UString mPakDataFilePassword
PakInterface PAK file password.
Definition: Environment.h:2310
virtual WidgetManager * getWidgetManager()=0
Get pointer to WidgetManager interface.
virtual uint32_hf getWindowID(HF_Window window)=0
Get ID for a given Window.
virtual void setScreenSize(int32_hf w, int32_hf h)=0
Set main window/screen width and height.
static Environment * instance()
Environment singleton instance.
Definition: Environment.cpp:92
static int32_hf TiXmlFileSize(void *pContext)
TinyXML IO hook for FileSize.
virtual void getLogicalViewportSize(int32_hf *x, int32_hf *y, int32_hf *w, int32_hf *h)=0
Get logical viewport size.
virtual void resetDrawCount()=0
Reset internal draw count counter.
virtual bool getPrefCustomCursor()
Get Preferences custom cursor mode for current profile.
virtual HFCore::Rect getDisplayBoundsRect(int32_hf displayIndex)=0
Use this function to get the desktop area represented by a display, with the primary display located ...
void fireMouseRemoved(int32_hf mouseId)
Called automatically when a Mouse is removed. It then calls callback method Game::handleMouseRemoved(...
HF_AudioDeviceID mAudioDeviceID
Default audio device id opened during Environment::init().
Definition: Environment.h:2331
#define NULL
Convenient define for 0.
Definition: HFDataTypes.h:42
A two-dimensional floating point vector and associated math functions.
Definition: Vector2.h:42
virtual void setGameLogFile(FILE *logFile)=0
Set game log file to use.
Interface for ThreadListener callback methods.
virtual void getScreenSize(int32_hf *w, int32_hf *h)=0
Get main window/screen width and height.
Singleton interface for platform specific things.
Definition: Environment.h:151
virtual WebManager * getWebManager()=0
Get pointer to WebManager interface.
Interface for Preferences base class.
Definition: Preferences.h:124
virtual void setCursorPosition(uint32_hf x, uint32_hf y)=0
Set Cursor position.
ActorManager * mActorManager
ActorManager interface instance.
Definition: Environment.h:2325
virtual int32_hf getMouseCount()=0
Get Mouse count.
virtual int32_hf getMousePosY()=0
Get Mouse Y position.
Interface for input type Touch.
Definition: Touch.h:44
void * thread_hf
A type definition for void*.
Definition: HFDataTypes.h:324
std::vector< VertexPosCol > VertexPosColVector
typedef for Vector holding VertexPosCol struct.
Definition: Geometry.h:346
HF_AudioChannels
Audio channels enum.
Definition: HFDataTypes.h:610
virtual int32_hf getAudioRateIntForEnum(HF_AudioRate rate)
Get int value for rate enum.
Specialized Boundary representing a Rect.
virtual Image * createImage()=0
Create new Image.
virtual void resumeTime()=0
Resume paused time.
char int8_hf
A type definition for char.
Definition: HFDataTypes.h:329
Game * mGame
Singleton Game instance.
Definition: Environment.h:2285
Interface for ThreadListener callback methods.
Interface for unicode string class UString.
virtual void setMousePosition(int32_hf x, int32_hf y)=0
Set Mouse position.
UString mPublisherName
Publisher name.
Definition: Environment.h:2295
static int32_hf TiXmlFileRead(void *pContext, void *pBuffer, int32_hf readSizeBytes)
TinyXML IO hook for FileRead.
virtual Keyboard * getKeyboard(int32_hf i)=0
Get Keyboard at given index.
WidgetManager manages Widget&#39;s and interacts with Game interface.
virtual bool getUpdatePaused()=0
Checks if update is in paused state or not.
virtual int32_hf getTouchCount()=0
Get Touch count.
virtual int32_hf getKeyboardCount()=0
Get Keyboard count.
std::vector< VertexPosNorTex > VertexPosNorTexVector
typedef for Vector holding VertexPosNorTex struct.
Definition: Geometry.h:366
std::vector< Texture > VertexTextureVector
typedef for Vector holding Texture struct.
Definition: Geometry.h:376
virtual uint32_hf getTicks()=0
Get Ticks in milliseconds since start.
virtual void stopMainLoop()=0
Stop the main loop.
virtual void setDebugEnabled(bool enabled)=0
Enable debug.
virtual void screenshot()=0
Take screenshot and store in FileDirUtils::getAppDataFolder().
virtual void showSystemMouse(bool show)=0
Determines whether to show or hide system mouse.
virtual void makeCurrentOpenGLContext(HF_Window window, openGLContext_hf ctx)=0
Set current OpenGL context for given Window.
virtual int32_hf getLogicalScreenWidth()=0
Get logical screen width.
Window handle struct.
Definition: HFDataTypes.h:429
virtual bool isOKToToggleFullscreen()=0
Checks if OK to toggle fullscreen / windowed mode.
void fireMouseAdded(int32_hf mouseId)
Called automatically when a Mouse is added. It then calls callback method Game::handleMouseAdded().
static bool zlibCompress(const int8_hf *inData, int32_hf inDataSize, int8_hf **outData, int32_hf *outDataSize, int32_hf compLevel=Z_DEFAULT_COMPRESSION)
Compress inData using zlib.
virtual void waitThread(thread_hf thread, int32_hf *threadReturnVal)=0
Wait until given thread is done.
virtual ResourceManager * getResourceManager()=0
Get pointer to ResourceManager interface.
std::vector< VertexPosColTex > VertexPosColTexVector
typedef for Vector holding VertexPosColTex struct.
Definition: Geometry.h:356
virtual bool getRenderDebugInfo()=0
Checks if render debug info is set.
virtual void deleteOpenGLContext(openGLContext_hf ctx)=0
Delete OpenGL context.
Interface for ResourceManager which handles all Resource loading etc.
static bool saveFile(const int8_hf *fileName, const int8_hf *inData, int32_hf inDataSize)
Store and save inData in a new file with fileName.
virtual bool getGameConfigValueBool(const UString &name)=0
Get game config value for given name.
A two-dimensional floating point vector and associated math functions.
virtual void disableScreenSaver()=0
Use this function to prevent the screen from being blanked by a screen saver.
virtual void gameLog(const int8_hf *fmt,...)=0
Write to game log.
virtual int32_hf getGameConfigValueInt(const UString &name)=0
Get game config value for given name.
Interface for Storage and File IO stuff.
Definition: Storage.h:36
virtual PersistenceLayer * getPersistenceLayer()=0
Get pointer to PersistenceLayer interface.
virtual bool getWindowDisplayMode(HF_Window window, HF_DisplayMode *displayMode)=0
Get Window display mode for a given window.
virtual bool getCustomCursorShown()=0
Checks if custom cursor is shown.
UString mWindowTitle
Window title.
Definition: Environment.h:2290
virtual void setDesktopSize(int32_hf w, int32_hf h)=0
Get Desktop width and height.
Interface useful for generic directory and file operations.
Definition: FileDirUtils.h:57
Game * getGameInstance()
Get singleton Game instance.
Definition: Actor.h:34
virtual void processSafeDeleteListOpenGLContext()=0
Process the cache of OpenGL context&#39;s to destroy (those put by safeDeleteOpenGLContext()).
virtual int32_hf getScreenHeight()=0
Get main window/screen height.
virtual GamePad * getGamePad(int32_hf i)=0
Get GamePad at given index.
virtual thread_hf createThread(HF_ThreadInfo *threadInfo, ThreadListener *listener)=0
Create a new thread and get callback through ThreadListener interface.
Interface for Resource type Image.
Definition: Image.h:63
Interface for Resource type Font.
Definition: Font.h:84
virtual void * getWindowData(HF_Window window, const int8_hf *name)=0
Get the data pointer associated with a window.
virtual void setRenderDebugInfo(bool render)=0
Determines whether to render debug info (FPS, Render calls etc).
virtual void showError(const std::string &message)=0
Useful for showing error messagebox (not showing messagebox yet for all platforms though)...
virtual void setSystemFont(HFCore::Font *sysFont)=0
Set system Font to use for debug rendering.
virtual Geometry * createGeometry(Geometry::VertexType vertexType, HF_BufferUsage bufferUsage, uint32_hf bufferSize)=0
Create Geometry.
virtual HF_Window createWindow(const int8_hf *windowTitle, int32_hf w, int32_hf h, uint32_hf windowflags, int32_hf x=HF_WINDOW_POS_CENTERED, int32_hf y=HF_WINDOW_POS_CENTERED)=0
Create new Window.
virtual openGLContext_hf createOpenGLContext(HF_Window window)=0
Create OpenGL context for given window.
void fireGamePadRemoved(int32_hf gamePadId)
Called automatically when a GamePad is removed. It then calls callback method Game::handleGamePadRemo...
virtual int32_hf getAudioChannelsIntForEnum(HF_AudioChannels channels)
Get int value for channels enum.
Interface for input type Keyboard.
Definition: Keyboard.h:41
virtual int32_hf hf_sprintf(int8_hf *pBuffer, int32_hf bufferLenChars, const int8_hf *pFormat,...)=0
&#39;sprintf&#39; std lib wrapper.
virtual void startMainLoop()=0
Start the main loop.
virtual HF_Window getMainWindow()=0
Get main Window (window created at startup / init).
virtual fp32_hf getGameConfigValueFloat(const UString &name)=0
Get game config value for given name.
virtual void getWindowPosition(HF_Window window, int32_hf *x, int32_hf *y)=0
Get Window position.
HF_FullscreenMode
Fullscreen modes enum.
Definition: HFDataTypes.h:465
Specialized Boundary representing a Rect.
Definition: Rect.h:34
virtual HF_AudioDeviceID getAudioDeviceID()
Get audio device id for the default device opened during Environment::init().
virtual bool isShuttingDown()=0
Checks if currently shutting down the main loop.
virtual bool getDisplayMode(int32_hf displayIndex, int32_hf displayModeIndex, HF_DisplayMode *displayMode)=0
Use this function to get information about a specific display mode.
Interface for all rendering related things.
Definition: Graphics.h:120
virtual Mouse * getFirstMouse()=0
Get first Mouse.
virtual HF_FullscreenMode getFullscreenMode()=0
Get current fullscreen mode.
virtual ActorManager * getActorManager()
Get pointer to ActorManager interface.
virtual void setWindowPosition(HF_Window window, int32_hf x, int32_hf y)=0
Set Window position.
UString mAndroidActivityClass
Android java activity class path.
Definition: Environment.h:2320
virtual void setClipboardText(std::string &text)=0
Use this function to put UTF-8 text into the clipboard.
Interface used by the framework to drive the main loop.
Definition: Game.h:67
UString getAndroidActivityClass()
Get Android java activity class path.
virtual void safeDeleteOpenGLContext(openGLContext_hf ctx)=0
Safe delete OpenGL context.
unsigned char uint8_hf
A type definition for unsigned char.
Definition: HFDataTypes.h:334
virtual HF_Window getWindowFromID(uint32_hf windowID)=0
Get Window by given ID.
virtual void drawDebugInfo(Graphics *g)=0
Draw debug info if enabled (CTRL+ALT+f enables).
virtual HF_PowerState getPowerInfo(int32_hf *seconds, int32_hf *percent)=0
Use this function to get the current power supply details.
virtual void createGameSaveThread()=0
Creates new thread which calls Game::saveDataThread().
static void TiXmlFileClose(void *pContext)
TinyXML IO hook for FileClose.
virtual void setDebugLogFile(FILE *logFile)=0
Set debug log file to use.
virtual fp32_hf getWindowBrightness(HF_Window window)=0
Get Window brightness (range 0.0f - 1.0f).
virtual void setWindowTitle(HF_Window window, const int8_hf *windowTitle)=0
Set Window title.
virtual void destroyWindow(HF_Window window)=0
Destroy Window.
virtual void getWindowSize(HF_Window window, int32_hf *w, int32_hf *h)=0
Get Window size.
virtual Storage * getStorage()=0
Get pointer to Storage interface.
virtual int32_hf getGamePadCount()=0
Get GamePad count.
virtual void setWindowBrightness(HF_Window window, fp32_hf brightness)=0
Set Window brightness (range 0.0f - 1.0f).
virtual bool getDesktopDisplayMode(int32_hf displayIndex, HF_DisplayMode *displayMode)=0
Get Desktop display mode.
virtual uint32_hf getMainWindowID()=0
Get main Window ID (id from window created at startup / init).
virtual Preferences * getPreferencesManager()=0
Get pointer to Preferences interface.
Interface for input type Mouse.
Definition: Mouse.h:46
virtual fp32_hf getPauseDuration()=0
Get Pause duration in seconds.
virtual void safeDestroyWindow(HF_Window window)=0
Safe destroy window.
virtual int32_hf getNumGamePads()=0
Use this function to count the number of joysticks attached to the system.
virtual Graphics * createGraphics()=0
Create new Graphics interface.
Interface useful when rendering custom Geometry.
UString mWindowIconPath
Window icon path.
Definition: Environment.h:2315
virtual bool isDebugEnabled()=0
Check if debug is enabled.
Interface for string related helper methods.
virtual int32_hf getPrefMusicVol()
Get Preferences SoundPlayer music volume for current profile.
float fp32_hf
A type definition for float.
Definition: HFDataTypes.h:359
virtual void sleep(int32_hf milliseconds)=0
Sleep for given time in milliseconds.
uint32_hf HF_AudioDeviceID
A type definition for uint32_hf used as Audio device id.
Definition: HFDataTypes.h:386
virtual int32_hf getMousePosX()=0
Get Mouse X position.
virtual UString getGameConfigValue(const UString &name)=0
Get game config value for given name.
virtual uint32_hf getDrawCount()=0
Get draw count.
HF_BufferUsage
Buffer usage enum.
Definition: HFDataTypes.h:643
UString getWindowTitle()
Get Window title name.