vlib.h

00001 /*
00002 
00003   Velocity  v1.5
00004   Copyright 2006, 2007 Gabriel Anderson
00005 
00006   This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 */
00021 
00022 //---------------------------------------------------------------------------------//
00023 // Includes                                                                        //
00024 //---------------------------------------------------------------------------------//
00025 
00026 #include <pspkernel.h>
00027 #include <pspdisplay.h>
00028 #include <pspdebug.h>
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include <stdarg.h>
00032 #include <math.h>
00033 #include <ctype.h>
00034 #include <string.h>
00035 #include <pspctrl.h>
00036 #include <pspgu.h>
00037 #include <psprtc.h>
00038 #include <psppower.h>
00039 #include <malloc.h>
00040 #include <png.h>
00041 #include <pspaudio.h>
00042 #include <pspatrac3.h>
00043 #include <pspvfpu.h>
00044 #include <jpeglib.h>
00045 
00046 #if defined(__cplusplus)
00047 extern "C" {
00048 #endif
00049 
00050 //---------------------------------------------------------------------------------//
00051 // Data                                                                            //
00052 //---------------------------------------------------------------------------------//
00053 
00054 extern SceCtrlData ctrl;
00055 
00056 // Structs for Verts!
00057 
00058 typedef struct {
00059   u32 color;
00060   short x, y, z;
00061 }
00062 CP_Vertex_2D; // Color, Position, 2D
00063 
00064 typedef struct {
00065   short u, v;
00066   short x, y, z;
00067 }
00068 TP_Vertex_2D; // Texture, Position, 2D
00069 
00070 typedef struct {
00071   u32 color;
00072   float x, y, z;
00073 }
00074 CP_Vertex_3D; // Color, Position, 3D
00075 
00076 typedef struct {
00077   float nx, ny, nz;
00078   u32 color;
00079   float x, y, z;
00080 }
00081 NCP_Vertex_3D; // Normals, Color, Position, 3D
00082 
00083 typedef struct {
00084   float u, v;
00085   float x, y, z;
00086 }
00087 TP_Vertex_3D; // Texture, Position, 3D
00088 
00089 typedef struct {
00090   float nx, ny, nz;
00091   float u, v;
00092   float x, y, z;
00093 }
00094 NTP_Vertex_3D; // Normals, Texture, Position, 3D
00095 
00096 // Holds an image
00097 typedef struct {
00098   // Public
00099   float x, y, width, height;
00100   float startX, startY, endX, endY;
00101   float angle, centerX, centerY;
00102 
00103   // Private
00104   // DO NOT CHANGE EVER
00105   int initWidth, initHeight;
00106   int realWidth, realHeight; // Width and height of the texture (both pow2)
00107   int totalSize; // The total size of the image (bytes)
00108   short location;
00109   u32* data; // image data
00110 }
00111 Image;
00112 
00113 // Holds a model
00114 typedef struct {
00115   float posX, posY, posZ;
00116   float sizeX, sizeY, sizeZ;
00117   float rotX, rotY, rotZ;
00118   int vertTotal;
00119   u32 __attribute__ ( ( aligned ( 16 ) ) ) *displayList;
00120   TP_Vertex_3D *verts;
00121   Image *img;
00122 }
00123 Model;
00124 
00125 // Holds audio
00126 typedef struct {}
00127 Audio;
00128 
00129 // Holds font
00130 typedef struct {}
00131 Font;
00132 
00133 typedef struct {
00134   union {
00135     struct {
00136 int select:
00137 1, start:
00138       3;
00139 int up:
00140 1, right:
00141 1, down:
00142 1, left:
00143       1;
00144 int L:
00145 1, R:
00146       1;
00147 int triangle:
00148 3, circle:
00149 1, cross:
00150 1, square:
00151       1;
00152 int home:
00153 1, hold:
00154 1, wlanOn:
00155 1, remote:
00156 1, volUp:
00157       1;
00158 int volDown:
00159 1, screen:
00160 1, note:
00161 1, disc:
00162 1, ms:
00163       1;
00164     };
00165     int value; // what buttons are on
00166   } pressed; // For checking if a button is pressed
00167 
00168   union {
00169     struct {
00170 int select:
00171 1, start:
00172       3;
00173 int up:
00174 1, right:
00175 1, down:
00176 1, left:
00177       1;
00178 int L:
00179 1, R:
00180       1;
00181 int triangle:
00182 3, circle:
00183 1, cross:
00184 1, square:
00185       1;
00186 int home:
00187 1, hold:
00188 1, wlanOn:
00189 1, remote:
00190 1, volUp:
00191       1;
00192 int volDown:
00193 1, screen:
00194 1, note:
00195 1, disc:
00196 1, ms:
00197       1;
00198     };
00199     int value; // what buttons are on
00200   } held; // For checking if a button is held
00201 
00202   union {
00203     struct {
00204 int select:
00205 1, start:
00206       3;
00207 int up:
00208 1, right:
00209 1, down:
00210 1, left:
00211       1;
00212 int L:
00213 1, R:
00214       1;
00215 int triangle:
00216 3, circle:
00217 1, cross:
00218 1, square:
00219       1;
00220 int home:
00221 1, hold:
00222 1, wlanOn:
00223 1, remote:
00224 1, volUp:
00225       1;
00226 int volDown:
00227 1, screen:
00228 1, note:
00229 1, disc:
00230 1, ms:
00231       1;
00232     };
00233     int value; // what buttons are on
00234   } released; // For checking if a button is released
00235 
00236   int repeatMask; // what buttons are going to be repeated
00237   int repeatCounter; // A counter for the button repeats when held
00238   int repeatInit; // The amount of time between the first repeat when held (this only happens once, unless the button is released and held again(physically))
00239   int repeatInterval; // The amount of time between repeats after the first repeat (this is continous, and is used until the button is released(physically))
00240 
00241   short analogX; // The current of the analog nub horizontally. Can be anywhere from 128 to -128.
00242   short analogY; // The current of the analog nub horizontally. Can be anywhere from 128 to -128.
00243 }
00244 CONTROLLER;
00245 
00246 extern CONTROLLER *button;
00247 
00248 extern u32* fbp0;
00249 extern u32* fbp1;
00250 extern u16* zbp;
00251 extern unsigned int __attribute__ ( ( aligned ( 16 ) ) ) DList[262144];
00252 
00253 extern int curFps, lastFps;  // for calculating the frames per second
00254 
00255 extern u32 tickResolution;
00256 extern u64 fpsTickNow;
00257 extern u64 fpsTickLast;
00258 
00259 extern CONTROLLER buttonInit;
00260 extern SceCtrlData ctrl;
00261 
00262 extern float deltaTime; // The current delta time, used for time based movement
00263 
00264 extern const int PRINT_BUFF;
00265 
00266 extern const int IN_RAM;
00267 extern const int IN_VRAM;
00268 
00269 extern const int OFF;
00270 extern const int ON;
00271 
00272 extern const int POINTS;
00273 extern const int LINES;
00274 extern const int LINE_STRIP;
00275 extern const int TRIANGLES;
00276 extern const int TRIANGLE_STRIP;
00277 extern const int TRIANGLE_FAN;
00278 extern const int SPRITES;
00279 
00280 extern const float PI;
00281 extern const float PI_180;
00282 extern short drawingStarted;
00283 
00284 extern ScePspFMatrix4 m_ortho, m_projection, m_projection_view, m_projection_model, m_ortho_view, m_ortho_model;
00285 
00286 #define RGB(r,g,b)  ((r) | ((g)<<8) | ((b)<<16) | (0xff<<24))
00287 #define RGBA(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
00288 
00289 #define IsSet(val,flag) (val&flag)==flag
00290 
00291 #define MASK_NONE 0x0
00292 #define MASK_SELECT 0x000001
00293 #define MASK_START 0x000008
00294 #define MASK_UP 0x000010
00295 #define MASK_RIGHT 0x000020
00296 #define MASK_DOWN 0x000040
00297 #define MASK_LEFT 0x000080
00298 #define MASK_LTRIG 0x000100
00299 #define MASK_RTRIG 0x000200
00300 #define MASK_TRIANGLE 0x001000
00301 #define MASK_CIRCLE 0x002000
00302 #define MASK_CROSS 0x004000
00303 #define MASK_SQUARE 0x008000
00304 #define MASK_HOME 0x010000
00305 #define MASK_HOLD 0x020000
00306 #define MASK_NOTE 0x800000
00307 #define MASK_SCREEN 0x400000
00308 #define MASK_VOLUP 0x100000
00309 #define MASK_VOLDOWN 0x200000
00310 #define MASK_WLANON 0x040000
00311 #define MASK_REMOTE 0x080000
00312 #define MASK_DISC 0x1000000
00313 #define MASK_MS 0x2000000
00314 #define MASK_ALL MASK_SELECT|MASK_START|MASK_UP|MASK_RIGHT|MASK_DOWN|MASK_LEFT|MASK_LTRIG|MASK_RTRIG|MASK_TRIANGLE|MASK_CIRCLE|MASK_CROSS|MASK_SQUARE
00315 
00316 //---------------------------------------------------------------------------------//
00317 // Vram                                                                            //
00318 //---------------------------------------------------------------------------------//
00319 
00320 void* vrelptr ( void *ptr );  // make a pointer relative to memory base address (ATTENTION: A NULL rel ptr is not illegal/invalid!)
00321 void* vabsptr ( void *ptr );  // make a pointer absolute (default return type of valloc)
00322 
00323 void* valloc ( size_t size );
00324 void vfree ( void* ptr );
00325 size_t vmemavail();
00326 size_t vlargestblock();
00327 
00328 #ifdef _DEBUG
00329 // Debug printf (to stdout) a trace of the current Memblocks
00330 void __memwalk();
00331 #endif
00332 
00333 
00334 //---------------------------------------------------------------------------------//
00335 // General                                                                         //
00336 //---------------------------------------------------------------------------------//
00337 
00340 
00369 void start_vLib ( void );
00370 
00399 void stop_vLib ( void );
00400 
00429 void start_drawing ( void );
00430 
00460 void end_drawing ( void );
00461 
00465 void sync_frame ( void );
00466 
00470 void flip_screen ( void );
00471 
00475 void wait_to_vsync ( void );
00476 
00482 void clear_screen ( void );
00483 
00494 void set_clear_color ( u32 color );
00495 
00500 void update_delta_time ( void );
00501 
00504 //---------------------------------------------------------------------------------//
00505 // Shape                                                                           //
00506 //---------------------------------------------------------------------------------//
00507 
00510 
00523 void draw_pixel ( float x, float y, u32 color );
00524 
00539 void draw_line ( float startX, float startY, float endX, float endY, u32 color );
00540 
00556 void draw_grad_line ( float startX, float startY, float endX, float endY, u32 color1, u32 color2 );
00557 
00572 void draw_rect ( float x, float y, float width, float height, u32 color );
00573 
00591 void draw_grad_rect ( float x, float y, float width, float height, u32 color1, u32 color2, u32 color3, u32 color4 );
00592 
00607 void draw_fill_rect ( float x, float y, float width, float height, u32 color );
00608 
00626 void draw_fill_grad_rect ( float x, float y, float width, float height, u32 color1, u32 color2, u32 color3, u32 color4 );
00627 
00630 //---------------------------------------------------------------------------------//
00631 // Image                                                                           //
00632 //---------------------------------------------------------------------------------//
00633 
00636 
00660 Image *load_image ( const char *filename, int location ); // Determines the type of image and loads it
00661 
00672 void unload_image ( Image *img );
00673 
00701 void draw_image ( Image *img );
00702 
00722 void set_linear_filter ( short state );
00723 
00724 //void flip ( Image *img );
00725 //void setImageAlpha ( Image *img, u8 alpha );
00726 
00729 //---------------------------------------------------------------------------------//
00730 // Model                                                                           //
00731 //---------------------------------------------------------------------------------//
00732 
00735 
00736 Model *load_model ( const char *filename );
00737 void unload_model ( Model *mdl );
00738 
00739 void draw_model ( Model *mdl, Image *img );
00740 
00741 void set_fog ( float near, float far, unsigned int color ); // Need to add in a toggle to turn this on/off
00742 void disable_fog ( void );
00743 
00746 //---------------------------------------------------------------------------------//
00747 // Camera                                                                          //
00748 //---------------------------------------------------------------------------------//
00749 
00752 
00753 void set_camera_3rd_person ( float posX, float posY, float posZ, float rotX, float rotY, float zoom );
00754 
00757 //---------------------------------------------------------------------------------//
00758 // Audio                                                                           //
00759 //---------------------------------------------------------------------------------//
00760 
00763 
00764 Audio *load_audio ( const char *filename );
00765 void play_audio ( Audio *aud, int stream );
00766 
00769 //---------------------------------------------------------------------------------//
00770 // Font                                                                            //
00771 //---------------------------------------------------------------------------------//
00772 
00775 
00776 Font *load_font ( const char *filename );
00777 void print ( Font *fnt, char *format );
00778 
00781 //---------------------------------------------------------------------------------//
00782 // Controller                                                                      //
00783 //---------------------------------------------------------------------------------//
00784 
00787 
00863 CONTROLLER *read_input ( int masked, int init, int interval );
00864 
00867 //---------------------------------------------------------------------------------//
00868 // VFPU                                                                         //
00869 //---------------------------------------------------------------------------------//
00870 
00873 
00874 // Some simple math operations
00875 float vfpu_sinf ( float rad );
00876 float vfpu_cosf ( float rad );
00877 float vfpu_sqrtf ( float x );
00878 
00879 // Matrix operations
00880 void vfpu_identity_m ( ScePspFMatrix4 *m );
00881 void vfpu_translate_m ( ScePspFMatrix4 *m, float x, float y, float z );
00882 void vfpu_rotateX_m ( ScePspFMatrix4 *m, float x );
00883 void vfpu_rotateY_m ( ScePspFMatrix4 *m, float y );
00884 void vfpu_rotateZ_m ( ScePspFMatrix4 *m, float z );
00885 void vfpu_rotateXYZ_m ( ScePspFMatrix4 *m, float x, float y, float z );
00886 void vfpu_rotateZYX_m ( ScePspFMatrix4 *m, float z, float y, float x );
00887 void vfpu_scale_m ( ScePspFMatrix4 *m, float x, float y, float z );
00888 void vfpu_lookAt_m ( ScePspFMatrix4 *m, ScePspFVector3* eye, ScePspFVector3* center, ScePspFVector3* up );
00889 void vfpu_perspective_m ( ScePspFMatrix4 *m, float fovy, float aspect, float near, float far );
00890 void vfpu_ortho_m ( ScePspFMatrix4 *m, float left, float right, float bottom, float top, float near, float far );
00891 
00894 //---------------------------------------------------------------------------------//
00895 // Debugging                                                                       //
00896 //---------------------------------------------------------------------------------//
00897 
00900 
00901 // The functions are all going to be combined with some of the other functions to make an all powerful super function!
00902 void fps ( void );
00903 void fpsX ( const char *format, ... );
00904 void sysmon ( void );
00905 void sysmonX ( const char *format, ... );
00906 
00909 // Some functions I use to benchmark functions. DO NOT USE!
00910 void start_ticker ( void );
00911 int end_ticker ( void );
00912 
00913 #if defined(__cplusplus)
00914 }
00915 #endif

Generated on Tue Mar 20 23:01:06 2007 for vLib by  doxygen 1.4.7