One Man Army Games
presents: OMALIB This is a set of routines We I threw together because SDL routines have a lot of things that we I don't need since I'm blitting to a 2d surface. It includes routines to create a window based on a configuration held in a file, load a masked bitmap from a file including changing the video mode to something usable, blit a bitmap, read any input from the keyboard, mouse, or joysticks, and do a couple other trivial things. Eventually, I want to take this lib and make it so you can choose between SDL and OpenGL, so I may add a #define for SDL_Surface ptr so I can keep that open. This works best when popped into a .bi file and included into your program so you don't have to do anything else. I'll have to do a LOT more work on it before it's useful to most people, but I'm posting the initial code here anyway, since it's a useful amalgamation of subs/functions for anyone who doesn't want to have to trudge through setting up APIs when they just want to get something coded. Functions are: declare sub omaSDL_Init() Creates a window based on a configuration stored in config.cfg, an example of which is in Star Phalanx and Rambo vs. Kitty Cat. If there is no file, it will create a 640x480x16bit window. If there's a problem, it will exit gracefully, with an error message describing the problem. A font file called vera.ttf must exist in the ./data directory for this command to work. This command MUST be called before any other omaLib functions are used. declare sub omaQuit () This will exit SDL and FB. declare sub omaGetScreenDimensions (byref w as integer,byref h as integer) This will return the dimensions of the screen surface. declare Sub omaPageFlip() Will flip the page, and do all the things which need to be done when that happens. It currently won't clear the screen when you pageflip, for better or for worse. Nothing will happen on the screen unless omaPageFlip() is called first. declare function omaLoadMaskedGraphic(filename$) as sdl_Surface ptr This function will load a BMP file from filename$ into a sdl_Surface ptr you declare. It will also apply masking to the colour magenta (255,255,0), and convert the bitmap to the ideal screen surface. If there's an error, it will quit everything gracefully with a text error message describing the problem.
declare sub omaBlitImage(x as integer,y as integer,image as sdl_surface ptr) There isn't much work involved in blitting with SDL, but this makes the job even easier.
declare sub omaDebugEvent (Text$) Add a debug event. This currently prints to the screen if DebugEvents are active declare sub omaDebugEventsActive (status as integer) Activates or deactivates DebugEvents. This will give extra information from inside each routine (which uses it), and will display any messages you've included in your own code using the omaDebugEvent sub. declare function omaMultiKey (x) This is the UltimaInput function. Any key press, mouse movement/button press or joystick movement/button press will activate a certain multikey code, which can be polled for. declare function omagetSingleEvent as integer Another function from UltimaInput, this will wait for any input event, then return that event. This is useful for configuration because there are too many code events to remember!! declare sub omaqfakBlitImage(x AS INTEGER,y AS INTEGER,number AS INTEGER, image AS sdl_surface PTR) This is a custom blitting routine created specifically for Quest for a King by One Man Army games. Given a bitmap 40 pixels high and at least (number + 1) * 40 pixels wide, omaqfakBlitImage will draw a 40x40 bitmap on the screen, whose source is a 40x40 area from image whose position is chosen by adding number * 40 to the y coordinate of the source 40x40 bitmap. To better understand this, understand that Quest for a Kings sprites are 40x40, and they are stored on a long bitmap with each sprite sitting side by side next to each other. setting number to a certain value will cause that sprite to be drawn. declare sub omaKillSurface(Picture AS SDL_Surface PTR) This will deallocate the memory used by a surface. It isn't needed for most applications. declare sub omaSetFramePeriod (x AS INTEGER) By default, omaLib limits the frames per seond to 30 by forcing frames to occur only (1/30 * 1000) ms, or about every 34 miliseconds.. This command allows you to set another time, in miliseconds, which will be forced to occur every (1/fps) * 1000 miliseconds. This will effectively raise or lower the frame rate, depennding on which numer is used. To find the time needed for a certain FPS, use the above formula. declare sub omaPrint(BYVAL x AS INTEGER, BYVAL y AS INTEGER, BYVAL clr AS SDL_Color, text AS STRING) omaPrint will write the contents of text onto the screen at the location (x, y) in the colour clr. Here's a sample program showing most of the elements in action:
|