⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crm32pro.h

📁 Motoko it s a 2D library to handle the graphical user interface of the game. It supports the basic c
💻 H
字号:
// --------------------------------------------------------------------------- 
//   						   CRM32Pro Library 
//  				      MegaStorm Systems (c) 2006
//							Roberto Prieto Prieto 
// ---------------------------------------------------------------------------
#ifndef CRM32Pro_H
#define CRM32Pro_H
 
// ------------------------------INCLUDES-------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "SDL/SDL.h"  
#include "SDL/SDL_thread.h"

// ----------------------------MAGIC LIBRARY STUFF----------------------------
#define RecoverSurf         // By default, auto recover surfaces support is enabled.
#if defined(_WINDOWS) || defined(WIN32) || defined(WIN64) // Is a Windows platform?
     #ifdef WIN64
      #undef RecoverSurf    // In Windows64, auto recover support is not needed.
    #endif
    #ifndef _WINDOWS
      #define _WINDOWS
    #endif
    #ifdef _WINDLL 
	  #define DllHandle __declspec(dllexport)    
	  #define DllExport __declspec(dllexport)
    #endif
    #ifndef _WINDLL
	  #define DllExport
	  #define DllHandle                          // Support static library.
      #ifndef CRM32PRO_STATIC 
        #undef DllHandle
        #define DllHandle __declspec(dllimport)  // Support shared library.
      #endif
    #endif	
#elif defined(__unix__) || defined(__UNIX__) // Otherwise, is a linux platform?
    #define _LINUX
    #define DllHandle  
    #define DllExport  
    #undef RecoverSurf    // In Linux, auto recover support is not needed.
#else                                        // Platform unknown, provocate compiling error.
    #error PLATFORM UNKNOWN - OVERRIDE THIS LINE TO FORCE COMPILING
#endif
  
// ---------------------------------------------------------------------------
/** @defgroup MODULE1 MODULE 1: CRM32Pro main and generic functions (v2.1).
 * This module contains main and generic functions:<br>
 * Init() and Quit(): these are the main functions of the library. They replace to SDL_Init() and SDL_Quit. <br>
 * SetVideoMode() uses Config struct to setup a video mode, it replaces SDL_SetVideoMode(). <br>
 * Update() is the main way to update all systems: graphics,events,timing,etc.It also replace SDL_Flip().<br>
 * XML parser, CRC32 functions, true random number generation and get useful information. <br>
 * Note that you always have to call to CRM32Pro.Init() to initialize the library and CRM32Pro.Quit() to close it. <br>
 * - Created on 10 June 2001
 * - Last modified on 8 May 2006*/
// ---------------------------------------------------------------------------
//! @{  

// -Video backend-
#define RENDER_DEFAULT 1 //!< Used with Config.VideoRender to use default backend. Default setting.
#define RENDER_WINDIB  2 //!< Used with Config.VideoRenderer to use Windib backend. Only for Win32/Win64.
#define RENDER_DIRECTX 4 //!< Used with Config.VideoRenderer to use DirectX backend. Only for Win32.
#define RENDER_X11     8 //!< Used with Config.VideoRenderer to use X11 backend. Only for Linux.
#define RENDER_FBCON  16 //!< Used with Config.VideoRenderer to use Frame Buffer Console backend. Only for Linux.
#define RENDER_DGA    32 //!< Used with Config.VideoRenderer to use DGA backend. Only for Linux.
#define RENDER_OPENGL 64 //!< Used with Config.VideoRenderer to use OpenGL backend. For Win32/Win64 and Linux.

// -Video acceleration mode-
#define ACCEL_SOFTWARE    1 //!< Used with Config.VideoAccel to set software mode with optimizations.
#define ACCEL_HARDSMOOTH  2 //!< Used with Config.VideoAccel to set hardware mode with smooth system (double-buffer).
#define ACCEL_HARDSPEED   3 //!< Used with Config.VideoAccel to set hardware mode at full speed.

// -Customs events-
#define EVENT_LOGICWAIT 30  //!< Event type returned by CRM32Pro.Update() while it is waiting to fulfill the Logic Rate.

//! CRM32Pro
/*! Main library interface.*/ 
class DllExport CRM32Pro_Main 
{
    public:
		// -Constructor-
		CRM32Pro_Main();
		// -Destructor-
		~CRM32Pro_Main();
		// -Init system-	
		int Init(unsigned int flags);  
		// -Quit system-		
		void Quit(void);      
		// -Update sytem-
		int Update(SDL_Event *ev=NULL);
		// -Clean up update system-
		void CleanUp(void);
		// -Set a video mode-
		int SetVideoMode(void);
		// -Blit a surface-
		int Blit(SDL_Surface *src, SDL_Rect *srcrect,SDL_Surface *dst, SDL_Rect *dstrect);
		// -Free a surface (using safe mode)-
		void FreeSurface(SDL_Surface *&);
		// -Set a callback function to blit your graphics at Rendering Frame Rate-
		void SetRenderCallback(void (*myRenderFunc)(void));
		// -Get current logic time-
		float GetLogicTime();

		// -Print version,copyright and compiled date and get string-
		void PrintVersion();       
		char *GetVersion();        
		char *GetCopyright();      
        // -Print useful information- 
		void VideoInfo(); 
		void AudioInfo();
	    void SurfaceInfo(SDL_Surface *surface);

		// -CRC32-
		unsigned int CRC32(char *buffer, int Size); 
		unsigned int CRC32(char *filename);

		// -True random number generator-
		void RandSeed(unsigned int seed); // Random seed
		Uint32 Rand();              // Random number on [0,0xffffffff] interval 
		double RandReal();          // Random number on [0,1] interval

		// -XML parser system-		
		int XMLOpen(char *filename);
		int XMLOpen(char *fileDPF,char *blockname);
		int XMLSave(int id, char *filename);
		int XMLSave(int id, char *fileDPF, char *blockname);
		void XMLClose(int id);

		int XMLNodePointTo(int id,int nparam,char *, ...);
		int XMLNodeFirst(int id);
		int XMLNodeNext(int id);
		int XMLNodeParent(int id);
		int XMLNodeChild(int id);
		int XMLNodeRemove(int id);
		int XMLNodeCreate(int id, char *name);
		int XMLNodeRename(int id, char *name);
		char *XMLNodeGetName(int id);
		
		int XMLAttributeSet(int id,char *name,char *value);
		int XMLAttributeSet(int id,char *name,int value);
		int XMLAttributeSet(int id,char *name,double value);
		int XMLAttributeGet(int id,char *name, char **value);
		int XMLAttributeGet(int id,char *name, int *value);
		int XMLAttributeGet(int id,char *name, double *value);
		int XMLAttributeRemove(int id, char *name);

		char *XMLTextGet(int id);
		int XMLTextSet(int id, char *value);
		int XMLTextRemove(int id);
		
		//! Main config struct. <br>You can manually fill it or using CRM32Pro.LoadConfig() loading an external XML.
		struct sConfig
		{
			// 1.General section
			char *Title;         //!< Title or name of your application. It is usually used as window title.
			SDL_Surface *Icon;   //!< Pointer to surface to assign it as icon.
			char bMTFriendly;    //!< MultiTasks Friendly flag.When it is enabled, it will give execution flow to OS scheduler for at least 1ms each Render Frame. By default is disabled.

			// 2.Video section
			Uint8 VideoRenderer; //!< See RENDER_xxx defines.			
			Uint8 VideoAccel;    //!< See ACCEL_xxx defines.
			Uint8 VideoWindow;   //!< 0 to force fullscreen or 1 to select window mode.
			Uint8 VideoBPP;      //!< Bits Per Pixel, you can choose 8,16 or 32.
			Uint16 VideoWidth;   //!< Video screen width.
			Uint16 VideoHeight;  //!< Video screen height.

			// 3.Audio section
			Uint8 AudioEnable;   //!< 0 to disable or 1 to enable sound system.
			int   AudioFormat;   //!< AUDIO_S8 to 8bits or AUDIO_S16 to 16bits sound resolution.
			int   AudioFreq;     //!< Frequency in Hz (11025,22050,44200).
			int   AudioMode;     //!< 1 for mono, 2 for stereo, 4 for surround and 6 for surround with center and lfe.
			int   AudioBuffer;   //!< Mixing buffer size, a common and good value is 4096.
			Uint8 AudioMusicVol; //!< Music volume.
			Uint8 AudioSoundVol; //!< Sound volume.
		} Config; 
		int LoadConfig(char *filename);
		int SaveConfig(char *filename);

		// -Common vars-
		SDL_Surface *screen;     //!< Main screen surface. You always have to use it to blit your graphics.
        int mouse_x;             //!< Mouse X position. Updated automatically.
        int mouse_y;             //!< Mouse Y position. Updated automatically.
        Uint8 mouse_buttons;     //!< Current state of mouse磗 buttons. Updated automatically.
        Uint8 mouse_prevbuttons; //!< Previous state of mouse磗 buttons. Updated automatically.
		Uint8 *keystate;         //!< Array of keys state. Updated automatically.
		Uint32 iStartTime;       //!< Store the start ticks(SDL_GetTicks()) when CRM32Pro was initialized.
		Uint8 iAutoSurfRecovery; //!< Flag to set on/off auto surface recovery.It is automatically setup in DirectX hardware mode.

		// -Resources internal control-
        int iNTiles,iNSprites,iNFonts;

	private:
		class cInternalMain *IInternal;	
};
 
 // High optimized memory copy
 extern "C" DllExport void *(*CRM32Pro_memcpy)(void *dest, const void *src, size_t n); //!< Optimized 磎emcpy()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -