(20140705)

This commit is contained in:
2014-07-05 00:00:00 +02:00
parent 7e6bd08390
commit 29548c6fe0
94 changed files with 432 additions and 829 deletions

View File

@@ -396,7 +396,7 @@ void GameEnts_Init(){
img_hole_spiked=Draw_LoadImage("data/hole_spiked.png");
Draw_SetOffset(img_hole_spiked,-16,-16);
anim_hole_lava=Anim_LoadAnim("data/hole_lava.png",2,3);
anim_hole_lava=Anim_LoadAnim("data/hole_lava.png",32,2,3);
Anim_SetOffset(anim_hole_lava,-16,-16);
img_player_up=Draw_LoadImage("data/player_up.png");
@@ -411,10 +411,10 @@ void GameEnts_Init(){
img_savepoint=Draw_LoadImage("data/save_point.png");
Draw_SetOffset(img_savepoint,-16,-16);
anim_savepoint_active=Anim_LoadAnim("data/save_point_active.png",2,5);
anim_savepoint_active=Anim_LoadAnim("data/save_point_active.png",32,2,5);
Anim_SetOffset(anim_savepoint_active,-16,-16);
anim_exitpoint=Anim_LoadAnim("data/exit_point.png",2,10);
anim_exitpoint=Anim_LoadAnim("data/exit_point.png",32,2,10);
Anim_SetOffset(anim_exitpoint,-16,-48);
img_endpoint=Draw_LoadImage("data/end_point.png");
@@ -438,7 +438,7 @@ void GameEnts_Init(){
img_arrow_right=Draw_LoadImage("data/arrow_right.png");
Draw_SetOffset(img_arrow_right,-16,-16);
anim_fire=Anim_LoadAnim("data/fire.png",3,5);
anim_fire=Anim_LoadAnim("data/fire.png",32,3,5);
Anim_SetOffset(anim_fire,-16,-48);
img_player_broken=Draw_LoadImage("data/player_broken.png");

View File

@@ -25,7 +25,7 @@ typedef struct {
// Anim_LoadAnim
//
//
Anim Anim_LoadAnim(char *fichero,int frames,float fps){
Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps){
DrawImg img;
Animation *anim;
int w,h;
@@ -39,7 +39,10 @@ Anim Anim_LoadAnim(char *fichero,int frames,float fps){
// Create the animation container
anim=malloc(sizeof(Animation));
anim->img=img;
anim->w=width;
if(width<=0){
anim->w=w/frames;
}
anim->fps=fps;
anim->frames=frames;
anim->ftime=1000/fps;

View File

@@ -17,7 +17,7 @@ typedef void *Anim;
// Anim_LoadAnim
//
//
Anim Anim_LoadAnim(char *fichero,int frames,float fps);
Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps);
/////////////////////////////

View File

@@ -18,30 +18,35 @@ static void Audio_MixerCallback(void *ud,Uint8 *stream,int l);
// AudioWave //
///////////////
// Reference to a sound.
typedef struct Tag_AudioWave {
SDL_AudioSpec spec;
typedef struct TAudioWave TAudioWave, *AudioWave;
struct TAudioWave {
unsigned int sampleRate;
int channels;
int bpb;
int BPB;
Uint32 len;
Uint8 *buffer;
struct Tag_AudioWave *next;
} AudioWave;
AudioWave *_waves=NULL;
AudioWave next;
};
AudioWave _waves=NULL;
////////////////////////////////////////////////
// AudioChan //
///////////////
// Reference to a sound.
typedef struct Tag_AudioChan {
AudioWave *wave;
typedef struct TAudioChan TAudioChan, *AudioChan;
struct TAudioChan {
AudioWave wave;
Uint32 pos;
unsigned char rightvol;
unsigned char leftvol;
struct Tag_AudioChan *next;
} AudioChan;
AudioChan *_channels=NULL;
AudioChan *_free_channels=NULL;
AudioChan next;
};
AudioChan _channels=NULL;
AudioChan _free_channels=NULL;
/////////////////////////////
// Audio_Init
@@ -58,7 +63,7 @@ int Audio_Init(){
#endif
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0){
printf("Audio_Init: Failure initializing SDL Audio.\n");
printf("Audio_Init: SDL Error: %s\n",SDL_GetError());
printf("\tSDL Error: %s\n",SDL_GetError());
return(0);
}
@@ -66,15 +71,11 @@ int Audio_Init(){
as.freq = 44100;
as.format = AUDIO_S16SYS;
as.channels = 2;
#ifdef EMSCRIPTEN
as.samples = 4096;
#else
as.samples = 1024;
#endif
as.samples = 2048;
as.callback = Audio_MixerCallback;
if(SDL_OpenAudio(&as, &as2) < 0){
printf("Audio_Init: Failure opening audio.\n");
printf("Audio_Init: SDL Error: %s\n",SDL_GetError());
printf("\tSDL Error: %s\n",SDL_GetError());
return(0);
}
@@ -101,16 +102,16 @@ int Audio_Init(){
// Mixes the audio channels.
static void Audio_MixerCallback(void *ud,Uint8 *stream,int l){
signed short *ptr_out,*ptr_wave;
AudioChan *prevchan;
AudioChan *chan;
AudioWave *wave;
AudioChan prevchan;
AudioChan chan;
AudioWave wave;
int len=l/4; // Asume 16bpb and 2 output chan
int chan_remain;
int len_mix;
int i;
// Clean
memset(stream,0,len);
memset(stream,0,l);
// Mix all the channels
prevchan=NULL;
@@ -118,7 +119,7 @@ static void Audio_MixerCallback(void *ud,Uint8 *stream,int l){
while(chan){
if(!chan->wave){
// Remove finished channels
AudioChan *aux_chan=chan->next;
AudioChan aux_chan=chan->next;
chan->next=_free_channels;
_free_channels=chan;
chan=aux_chan;
@@ -197,41 +198,105 @@ void Audio_Frame(){
//
// Loads a sound, giving a reference.
AudioSnd Audio_LoadSound(char *filename){
AudioWave *wave;
#ifndef EMSCRIPTEN
// Allocate and load the sound
wave=malloc(sizeof(AudioWave));
if( SDL_LoadWAV(filename,
&wave->spec, &wave->buffer, &wave->len) == NULL )
{
printf("Audio_LoadSound: Failure Loading sound: %s\n",filename);
printf("Audio_LoadSound: SDL Error: %s\n",SDL_GetError());
free(wave);
int error = 0;
FILE *f;
char id[5] = { 0, 0, 0, 0, 0 }, *sndBuffer = NULL;
short formatTag, channels, bitsPerSample;
int formatLen, sampleRate, dataSize;
f = fopen(filename, "rb");
if (!f) {
printf("Audio_LoadSound: Failure opening file.\n");
return(NULL);
}
// Asert results
if( wave->spec.format != AUDIO_S16 ||
wave->spec.freq != 44100 ||
wave->spec.channels != 1 )
{
printf("Audio_LoadSound: Failure opening sound. (44.1Khz/16b/1c).\n");
SDL_FreeWAV(wave->buffer);
free(wave);
return(0);
// Read id "RIFF"
fread(id, 4, sizeof(char), f);
if (strcmp(id, "RIFF")) {
printf("Audio_LoadSound: File is not RIFF.\n");
fclose(f);
return(NULL);
}
// Correct the lenght
wave->len/=2;
// File size (-"RIFF")
fseek(f, 4, SEEK_CUR); // size
// Read id "WAVE"
fread(id, 4, sizeof(char), f);
if (strcmp(id, "WAVE")) {
printf("Audio_LoadSound: File is not WAVE.\n");
fclose(f);
return(NULL);
}
// Read the format
fread(id, 1, sizeof(char) * 4, f); // Read "fmt "
fread(&formatLen, 1, sizeof(int), f);
if (formatLen < 14) {
printf("Audio_LoadSound: File too short.\n");
fclose(f);
return (NULL );
}
fread(&formatTag, 1, sizeof(short), f); // 1=PCM
if (formatTag != 1) {
printf("Audio_LoadSound: Not PCM format.\n");
fclose(f);
return (NULL );
}
fread(&channels, 1, sizeof(short), f);
fread(&sampleRate, 1, sizeof(int), f);
fseek(f, 2, SEEK_CUR); // avgBytesSec
fseek(f, 2, SEEK_CUR); // blockAlign
fread(&bitsPerSample, 1, sizeof(short), f);
fseek(f, formatLen - 14, SEEK_CUR); // Align read
// Assert sound format
if (sampleRate!=44100 || channels!=1 || bitsPerSample!=2) {
printf("Audio_LoadSound: Format not supported: "
"sampleRate:%d; channels:%d; BPB:%d\n",
sampleRate, channels, bitsPerSample);
fclose(f);
return(NULL);
}
// Skip no "data" blocks
do{
int lenRead=fread(id, 1, sizeof(char) * 4, f);
if(lenRead<4){ break; }
if (strcmp(id, "data")) {
fread(&dataSize, 1, sizeof(int), f);
fseek(f, dataSize, SEEK_CUR);
}else{
break;
}
}while(1);
if (strcmp(id, "data")) {
printf("Audio_LoadSound: DATA block not found\n");
fclose(f);
return (NULL );
}
// Read the "data" block
fread(&dataSize, 1, sizeof(int), f);
sndBuffer = malloc(sizeof(char)*dataSize);
fread(sndBuffer, dataSize, sizeof(char), f);
fclose(f);
// Build the wave object
AudioWave wave = malloc(sizeof(TAudioWave));
wave->sampleRate = sampleRate;
wave->channels = channels;
wave->buffer = (Uint8 *) sndBuffer;
wave->BPB = bitsPerSample;
wave->bpb = wave->bpb * 8;
wave->len = dataSize / (wave->BPB * wave->channels);
// Take a reference
wave->next=_waves;
_waves=wave;
return((AudioSnd)wave);
#else
return(NULL);
#endif
return (wave);
}
@@ -242,8 +307,8 @@ AudioSnd Audio_LoadSound(char *filename){
void Audio_PlaySound(AudioSnd snd,
float leftvol, float rightvol)
{
AudioChan *chan;
AudioWave *wave;
AudioChan chan;
AudioWave wave;
if(!snd)
return;
@@ -256,7 +321,7 @@ void Audio_PlaySound(AudioSnd snd,
_free_channels=chan->next;
chan->next=NULL;
}else{
chan=malloc(sizeof(AudioChan));
chan=malloc(sizeof(TAudioChan));
chan->next=NULL;
}

View File

@@ -6,19 +6,27 @@
#include <string.h>
#ifdef WIN32
// Windows
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <GL/gl.h>
#include <GL/glext.h>
#define USE_OpenGL 1
#define USE_OpenGLES 0
#else
#ifdef EMSCRIPTEN
//#include <GLES2/gl2.h>
//#define GL_GLEXT_PROTOTYPES 1
//#include <GLES2/gl2ext.h>
// Emscripten
#include <GLES2/gl2.h>
#define GL_GLEXT_PROTOTYPES 1
#include <GLES2/gl2ext.h>
#include <emscripten.h>
#include <GL/gl.h>
#define USE_OpenGL 0
#define USE_OpenGLES 1
#else
// UNIX
#include <GL/gl.h>
#define USE_OpenGL 1
#define USE_OpenGLES 0
#endif
#endif
#include "lodepng.c"
@@ -57,8 +65,71 @@ QuadArray2D _quadArray=NULL;
DrawImage _currentImg=NULL;
float _color[4];
#if USE_OpenGLES
GLuint Draw_CompileShader(GLenum type, const char *source){
GLuint shader = glCreateShader(type);
if (shader == 0) {
return 0;
}
//load the shader source to the shader object and compile it
glShaderSource(shader, 1, &source, NULL);
glCompileShader(shader);
//check if the shader compiled successfully
GLint compiled;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if (!compiled) {
glDeleteShader(shader);
return 0;
}
return shader;
}
GLuint Draw_BuildProgram(
const char *vertexShaderSource,
const char *fragmentShaderSource)
{
// Compile shaders
GLuint vertexShader = Draw_CompileShader(GL_VERTEX_SHADER, vertexShaderSource);
GLuint fragmentShader = Draw_CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSource);
if(vertexShader==0 || fragmentShader==0){
return 0;
}
//create a GL program and link it
GLuint programObject = glCreateProgram();
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
glLinkProgram(programObject);
//check if the program linked successfully
GLint linked;
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
if (!linked)
{
glDeleteProgram(programObject);
return 0;
}
return programObject;
}
GLuint vertPosLoc;
GLuint vertTexLoc;
GLuint vertColorLoc;
GLuint textureLoc;
GLuint projectionMatrixLoc;
GLuint vertexObject;
#define Max_Vertices 6000
#endif
/////////////////////////////
// Draw_Init
@@ -78,6 +149,13 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
}
#endif
// Set globals
proc_t_frame=1000000/pfps;
draw_t_frame=1000000/fps;
_fps=fps;
_width=width;
_height=height;
// Initialize SDL
if(SDL_Init(SDL_INIT_VIDEO)<0){
printf("Draw_Init: Failure initializing SDL.\n");
@@ -85,7 +163,7 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
return(0);
}
#if USE_OpenGL
// Prepare OpenGL inicialization
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
@@ -94,7 +172,7 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
#endif
// Initialize video mode
_screen=SDL_SetVideoMode(width,height,32,SDL_HWSURFACE|SDL_OPENGL);
@@ -104,14 +182,10 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
return(0);
}
SDL_WM_SetCaption(title, NULL);
proc_t_frame=1000000/pfps;
draw_t_frame=1000000/fps;
_fps=fps;
_width=width;
_height=height;
#if USE_OpenGL
// Set the desired state
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
@@ -146,6 +220,90 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
#else
// Show device info
char *str;
printf("\n*********************************\n");
printf("*** Draw Info\n");
str=(char *)glGetString(GL_VENDOR);
printf(" Vendor: %s\n",str);
str=(char *)glGetString(GL_RENDERER);
printf(" Renderer: %s\n",str);
str=(char *)glGetString(GL_VERSION);
printf(" Version: %s\n",str);
printf("*********************************\n");
const char vertexShaderSource[] =
"attribute vec4 aPosition; \n"
"attribute vec2 aTexCoord; \n"
"attribute vec4 aColor; \n"
"varying vec2 vTexCoord; \n"
"varying vec4 vColor; \n"
"uniform mat4 sProjectionMatrix; \n"
"void main() { \n"
" gl_Position = aPosition * \n"
" sProjectionMatrix; \n"
" vTexCoord = aTexCoord; \n"
" vColor = aColor; \n"
"} \n";
const char fragmentShaderSource[] =
"precision mediump float; \n"
"varying vec2 vTexCoord; \n"
"varying vec4 vColor; \n"
"uniform sampler2D sTexture; \n"
"void main() { \n"
" gl_FragColor = texture2D(sTexture, vTexCoord)*vColor; \n"
"} \n";
GLuint programObject=Draw_BuildProgram(
vertexShaderSource,
fragmentShaderSource);
glUseProgram(programObject);
vertPosLoc = glGetAttribLocation(programObject, "aPosition");
vertTexLoc = glGetAttribLocation(programObject, "aTexCoord");
vertColorLoc = glGetAttribLocation(programObject, "aColor");
textureLoc = glGetUniformLocation(programObject, "sTexture");
projectionMatrixLoc = glGetUniformLocation(programObject, "sProjectionMatrix");
glGenBuffers(1, &vertexObject);
glBindBuffer(GL_ARRAY_BUFFER, vertexObject );
glBufferData(GL_ARRAY_BUFFER, Vertex2D_Length*sizeof(float)*Max_Vertices,
NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vertexObject );
glVertexAttribPointer(vertPosLoc, 2, GL_FLOAT,GL_FALSE,
Vertex2D_Length*sizeof(float), (void*)(0*sizeof(float)));
glVertexAttribPointer(vertTexLoc, 2, GL_FLOAT, GL_FALSE,
Vertex2D_Length*sizeof(float), (void*)(2*sizeof(float)));
glVertexAttribPointer(vertColorLoc, 4, GL_FLOAT, GL_FALSE,
Vertex2D_Length*sizeof(float), (void*)(4*sizeof(float)));
glEnableVertexAttribArray(vertPosLoc);
glEnableVertexAttribArray(vertTexLoc);
glEnableVertexAttribArray(vertColorLoc);
glUniform1i(textureLoc, 0);
GLfloat projectionMatrix[16]={
2.0f/(float)_width, 0.0, 0.0, -1.0,
0.0, 2.0/(float)_height, 0.0, -1.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
glUniformMatrix4fv(projectionMatrixLoc,
1, GL_FALSE, projectionMatrix);
#endif
// Enable Alpha blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@@ -159,6 +317,123 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
}
/////////////////////////////
// Draw_UploadGLTexture
//
// Uploads a OpenGL texture.
GLuint Draw_UploadGLTexture(int w, int h, unsigned char *pixels){
GLuint tex;
// Generate OpenGL texture
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Load OpenGL texture
glBindTexture(GL_TEXTURE_2D, tex);
#if USE_OpenGL
glPixelStorei( GL_UNPACK_ROW_LENGTH, w );
#endif
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
w, h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
return(tex);
}
/////////////////////////////
// Draw_Flush
//
// Performs all the queued draw actions.
void Draw_Flush(){
if(_currentImg==NULL || _quadArray->nVertex<=0){
return;
}
if(_currentImg->tex==-1){
_currentImg->tex=Draw_UploadGLTexture(_currentImg->w, _currentImg->h, _currentImg->data);
}
#if USE_OpenGL
// Draw the quad array
glBindTexture(GL_TEXTURE_2D, _currentImg->tex);
glColorPointer( 4, GL_FLOAT, Vertex2D_Length*sizeof(float),
(GLvoid *)(_quadArray->vertexData+4) );
glTexCoordPointer( 2, GL_FLOAT, Vertex2D_Length*sizeof(float),
(GLvoid *)(_quadArray->vertexData+2) );
glVertexPointer( 2, GL_FLOAT, Vertex2D_Length*sizeof(float),
(GLvoid *)(_quadArray->vertexData) );
glDrawArrays(GL_TRIANGLES,0,_quadArray->nVertex);
#else
// Draw the quad array
glBindTexture(GL_TEXTURE_2D, _currentImg->tex);
glBufferSubData(GL_ARRAY_BUFFER, 0,
Vertex2D_Length*sizeof(float)*_quadArray->nVertex,
_quadArray->vertexData);
glDrawArrays(GL_TRIANGLES, 0, _quadArray->nVertex);
#endif
// Empty it
QuadArray2D_Clean(_quadArray);
}
/////////////////////////////
// Draw_Clean
//
// Cleans the game window.
void Draw_Clean(
unsigned char r,
unsigned char g,
unsigned char b)
{
#ifndef EMSCRIPTEN
glClearColor(r/255.0f,g/255.0f,b/255.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
#else
Draw_Flush();
float fr=r/255.0f;
float fg=g/255.0f;
float fb=b/255.0f;
GLfloat vVertices[] = {
0.0, 0.0, // Position 0
0.0, 0.0, // TexCoord 0
fr, fg, fb, 1.0, // Color
0.0, _height, // Position 1
0.0, 1.0, // TexCoord 1
fr, fg, fb, 1.0, // Color
_width, _height, // Position 2
1.0, 1.0, // TexCoord 2
fr, fg, fb, 1.0, // Color
_width, _height, // Position 2
1.0, 1.0, // TexCoord 2
fr, fg, fb, 1.0, // Color
_width, 0.0, // Position 3
1.0, 0.0, // TexCoord 3
fr, fg, fb, 1.0, // Color
0.0, 0.0, // Position 0
0.0, 0.0, // TexCoord 0
fr, fg, fb, 1.0, // Color
};
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vVertices), vVertices);
glDrawArrays(GL_TRIANGLES, 0, 6);
#endif
}
/////////////////////////////
// Draw_LoopIteration
//
@@ -270,47 +545,6 @@ void Draw_Loop(int (*proc)(),void (*draw)(float f)){
}
/////////////////////////////
// Draw_Clean
//
// Cleans the game window.
void Draw_Clean(
unsigned char r,
unsigned char g,
unsigned char b)
{
glClearColor(r/255.0f,g/255.0f,b/255.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
/////////////////////////////
// Draw_UploadGLTexture
//
// Uploads a OpenGL texture.
GLuint Draw_UploadGLTexture(int w, int h, unsigned char *pixels){
GLuint tex;
// Generate OpenGL texture
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Load OpenGL texture
glBindTexture(GL_TEXTURE_2D, tex);
//glPixelStorei( GL_UNPACK_ROW_LENGTH, w );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
w, h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
return(tex);
}
/////////////////////////////
// Draw_CreateImage
//
@@ -394,42 +628,6 @@ void Draw_GetOffset(DrawImg img,int *x,int *y){
}
/////////////////////////////
// Draw_Flush
//
// Performs all the queued draw actions.
void Draw_Flush(){
if(_currentImg==NULL){
return;
}
if(_currentImg->tex==-1){
_currentImg->tex=Draw_UploadGLTexture(_currentImg->w, _currentImg->h, _currentImg->data);
}
// Draw the quad array
glBindTexture(GL_TEXTURE_2D, _currentImg->tex);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer( 4, GL_FLOAT, Vertex2D_Length*sizeof(float),
(GLvoid *)(_quadArray->vertexData+4) );
glTexCoordPointer( 2, GL_FLOAT, Vertex2D_Length*sizeof(float),
(GLvoid *)(_quadArray->vertexData+2) );
glVertexPointer( 2, GL_FLOAT, Vertex2D_Length*sizeof(float),
(GLvoid *)(_quadArray->vertexData) );
glDrawArrays(GL_QUADS,0,_quadArray->nVertex);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
// Empty it
QuadArray2D_Clean(_quadArray);
}
/////////////////////////////
// Draw_DrawImg
//
@@ -518,7 +716,6 @@ void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int i){
//
//
void Draw_SetColor(float r,float g,float b,float a){
glColor4f(r,g,b,a);
_color[0]=r;
_color[1]=g;
_color[2]=b;
@@ -643,6 +840,7 @@ void Draw_DrawText(DrawFnt f,char *text,int x,int y){
//
//
void Draw_SaveScreenshoot(char *filename){
#if USE_OpenGL
SDL_Surface *surf;
unsigned char *image_line;
int i,half_height,line_size;
@@ -690,6 +888,7 @@ void Draw_SaveScreenshoot(char *filename){
// Cleanup
SDL_FreeSurface(surf);
#endif
}

View File

@@ -11,13 +11,6 @@
int Draw_Init(int width,int height,char *title,int pfps,int fps);
/////////////////////////////
// Draw_Loop
//
// Loops updating the game window.
void Draw_Loop(int (*proc)(),void (*draw)(float f));
/////////////////////////////
// Draw_Clean
//
@@ -28,6 +21,13 @@ void Draw_Clean(
unsigned char b);
/////////////////////////////
// Draw_Loop
//
// Loops updating the game window.
void Draw_Loop(int (*proc)(),void (*draw)(float f));
/////////////////////////////
// Draw_Flush
//

View File

@@ -69,7 +69,10 @@ void QuadArray2D_AddQuad(QuadArray2D quadArray,
// Add the vertexes
v[0]=x0; v[1]=y0; v[2]=u0; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
v[0]=x1; v[1]=y0; v[2]=u1; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
v[0]=x1; v[1]=y1; v[2]=u1; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0]=x1; v[1]=y1; v[2]=u1; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0]=x0; v[1]=y1; v[2]=u0; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0]=x0; v[1]=y0; v[2]=u0; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
}

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
// Copyright (C) 2011-2014 Valeriano Alfonso Rodriguez (Kableado)
#include <stdio.h>
#include <math.h>
@@ -45,25 +45,6 @@ void Time_Pause(int pausa){
}while(tend>=t);
}
#else
#ifdef MACOSX
#include <mach/mach_time.h>
// MacOSX
long long Time_GetTime(){
static mach_timebase_info_data_t info = {0,0};
uint64_t t;
if(info.denom==0){
mach_timebase_info(&info);
}
t=mach_absolute_time()*(info.numer / info.denom);
return(t/1000);
}
void Time_Pause(int pausa){
struct timeval tv;
tv.tv_sec=(long long)pausa/1000000;
tv.tv_usec=(long long)pausa%1000000;
select(0, NULL, NULL, NULL, &tv);
}
#else
// UNIX
long long Time_GetTime(){
struct timeval t;
@@ -78,7 +59,6 @@ void Time_Pause(int pausa){
tv.tv_usec=(long long)pausa%1000000;
select(0, NULL, NULL, NULL, &tv);
}
#endif // if MACOSX
#endif // if WIN32

View File

@@ -49,7 +49,7 @@ $(BUILDDIR):
clean:
rm -f $(OBJS) $(BUILDDIR)/$(RESULT)
run: $(BUILDDIR)/$(RESULT)
run: $(BUILDDIR) $(BUILDDIR)/$(RESULT)
$(LAUNCHER) ./$(BUILDDIR)/$(RESULT) debug
rebuild: clean all

View File

@@ -3,7 +3,8 @@ LAUNCHER= start
RM=rm -rf
LIBS=
CFLAGS= -s LEGACY_GL_EMULATION=1 -s ASM_JS=1 -O1
CFLAGS= -s FULL_ES2=1 -s ASM_JS=1 -O1
#LDFLAGS= --embed-file data
LDFLAGS= --preload-file data
RESULT=game.html

View File

@@ -1,9 +0,0 @@
LIBS=-lm -ldl -framework Cocoa -framework SDL -framework OpenGL macosx/SDLMain.m
CFLAGS=-g -DDEBUG -Wall -DMACOSX -ObjC -Dmain=SDL_main
CC=gcc
RM=rm -rf
RESULT=game
BUILDDIR=build-macosx
include Makefile.common

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

View File

@@ -14,10 +14,10 @@
##||........||..||........||## ################
##||..LLLLBB||..||..LLLL..||## ##............##
##||............||........||## ##............##
##||||||||..||||||||||||||||ll########............##
##||||||||||||||||............................EE..##
##||||||||||||||||||||||||||ll########............##
##||||||||..||||||............................EE..##
##||||||||..||||||||||||||||llmmmmmmmm............##
##||....BB....||..........||mm mm............##
##||....BB..||............||mm mm............##
##||..LLLL..||||||BBLLLL..||mm mm............##
##||........||||||........||mm mmmmmmmmmmmmmm##
##||||||||||||||||||||||||||mm

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 KiB

View File

@@ -1,23 +0,0 @@
33 23
############ll################ ######ll############ll####
##..........................## ##......................##
##..................||......ll########....||||||||||||||....##
##..S1..............||..............S2....||................##
##..................||......llmmmmmmmm....||....||||||||||||##
##..........................mm mm....||................##
##mmmmmmmmmmllmmmmmmmmmmmmmmmm mmmmmmmmmmmmll..llmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
##########S3##########
##..................##
##..................##
ll..................ll
mm..BBBBBB..BBBBBB..mm
mm||||||||ll||||||||mm
mm..................mm
mm..................mm
mm........EE........mm
mmmmmmmmmmmmmmmmmmmmmm

View File

@@ -1,51 +0,0 @@
100 100
##################
##......S1......##
##..............##
##..............##
##..............##
##mmmmll..llmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
############S2##############
##||||||||........||||||||##
##||||||||..BBll..||||||||##
ll||....||||BB....||||||||ll
mm||..||||||||||||||||||||mm
mm||..||||||||||||||||||||mm
mm||..||||||||||||||||||||mm
mm||..........BB||||BB..||mm
mm||||||||||..||||||||||||mm
mmmmmmmmmmll..llmmmmmmmmmmmm
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
############S3############
##......||......||......##
##......||..BB..||......##
ll......||||||||||..BB..ll
mm||||||rrrrllrrrr||||||mm
mm......................mm
mm||||||....BB....||||||mm
mm......rr||||||rr......mm
mm......||rrrrrr||......mm
mm....BB||......||......mm
mmmmmmmmmmll..llmmmmmmmmmm
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
########..########
##..............##
##..............##
##..............##
##......EE......##
##mmmmmmmmmmmmmm##

View File

@@ -1,23 +0,0 @@
33 23
############ll################ ##########################
##..........................## ##......................##
##..................LL......ll########....LLLLLLLLLLLLLL....##
##..S1..............LL..............S2....LL................##
##..................LL......llmmmmmmmm....LL....LLLLLLLLLLLL##
##..........................mm mm....LL................##
##mmmmmmmmmmllmmmmmmmmmmmmmmmm mmmmmmmmmmmmll..llmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
##########S3##########
##..................##
##..................##
ll..................ll
##..BBBBBB..BBBBBB..##
##LLLLLLLLrr||||||||##
##..................##
##..................##
##........EE........##
##mmmmmmmmmmmmmmmmmm##

View File

@@ -1,29 +0,0 @@
100 100
##################
##......S1......##
##..............##
##..............##
##..............##
##mmmmll..llmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
##############S2##############
##||||||||||||..||||||||||||##
##||........||..||........||## ################
##||..LLLLBB||..||..LLLL..||## ##............##
##||............||........||## ##............##
##||||||||..||||||||||||||||ll########............##
##||||||||||||||||............................EE..##
##||||||||..||||||||||||||||llmmmmmmmm............##
##||....BB....||..........||mm mm............##
##||..LLLL..||||||BBLLLL..||mm mm............##
##||........||||||........||mm mmmmmmmmmmmmmm##
##||||||||||||||||||||||||||mm
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

View File

@@ -1,26 +0,0 @@
33 26
############ll################ ######ll##########ll######
##..........................## ##................VV....##
##..........................ll########......................##
##..S1..............................S2......................##
##..........................llmmmmmmmm>>....................##
##..................AA......mm mm........AA............##
##mmmmmmmmmmllmmmmmmmmmmmmmmmm mmmmmmmmmmmmll..llmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
##########S3##########
##..................##
##............BBBB..##
##................<<##
ll..BBBB............ll
##>>................##
##............BBBB..##
##................<<##
ll..BBBB............ll
##>>................##
##..................##
##........EE........##
##mmmmmmmmmmmmmmmmmm##

View File

@@ -1,69 +0,0 @@
100 100
##################
##......S1......##
##..............##
##..............##
##..............##
##mmmmll..llmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
####ll######S2######ll####
##......................##
##..BB..BB......BB..BB..##
##......................##
##LLLLLLLLrr||rrLLLLLLLL##
##......AA......AA......##
##mmmmmmmmll..llmmmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
############S3############
##....VV..VV..........LL##
##LLLLLLLLLLLLLLLLLL..LL##
##LL..................LL##
##LL..LLLLLLLLLLLLLLLLLL##
##LL..................LL##
##LLLLLLLLLLLLLLLLLL..LL##
##LL..................LL##
##LL..LLLLLLLLLLLLLLLLLL##
##LL..........AA..AA....##
##mmmmmmmmll..llmmmmmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
mm..mm
######VV##VVS4############
##LLLLLLLLLL..LLLLLLLLLL##
##LLLLLLLLLL..........LL##
>>LLLLLLLLLLLLLLLLLL..LL##
mmLL..................LL##
mmLL..LLLLLLLLLLLLLLLLLL<<
mmLL..................LLmm
>>LLLLLLLLLLLLLLLLLL..LLmm
mmLL..................LLmm
mmLL..LLLLLLLLLLLLLLLLLL<<
mmLL..........LLLLLLLLLLmm
mmLLLLLLLLLL..LLLLLLLLLLmm
mmmmmmmmmmmm..AAmmAAmmmmmm
ll..ll
mm..mm
mm..mm
mm..mm
mm..mm
########..########
##..............##
##..............##
##..............##
##......EE......##
##mmmmmmmmmmmmmm##

View File

@@ -1,21 +0,0 @@
100 100
##################
##......S1......##
##..............##
##..............##
##..............##
##mmmmll..llmmmm##
mm..mm
mm..mm
mm..mm
mm..mm
########..########
##..............##
##..............##
##..............##
##......FF......##
##mmmmmmmmmmmmmm##

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

BIN
game.save

Binary file not shown.

BIN
macosx/.DS_Store vendored

Binary file not shown.

View File

@@ -1,16 +0,0 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
*/
#ifndef _SDLMain_h_
#define _SDLMain_h_
#import <Cocoa/Cocoa.h>
@interface SDLMain : NSObject
@end
#endif /* _SDLMain_h_ */

View File

@@ -1,381 +0,0 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
*/
#include <SDL/SDL.h>
#include "SDLMain.h"
#include <sys/param.h> /* for MAXPATHLEN */
#include <unistd.h>
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare
it ourselves here. */
@interface NSApplication(SDL_Missing_Methods)
- (void)setAppleMenu:(NSMenu *)menu;
@end
/* Use this flag to determine whether we use SDLMain.nib or not */
#define SDL_USE_NIB_FILE 0
/* Use this flag to determine whether we use CPS (docking) or not */
#define SDL_USE_CPS 1
#ifdef SDL_USE_CPS
/* Portions of CPS.h */
typedef struct CPSProcessSerNum
{
UInt32 lo;
UInt32 hi;
} CPSProcessSerNum;
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
#endif /* SDL_USE_CPS */
static int gArgc;
static char **gArgv;
static BOOL gFinderLaunch;
static BOOL gCalledAppMainline = FALSE;
static NSString *getApplicationName(void)
{
const NSDictionary *dict;
NSString *appName = 0;
/* Determine the application name */
dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
if (dict)
appName = [dict objectForKey: @"CFBundleName"];
if (![appName length])
appName = [[NSProcessInfo processInfo] processName];
return appName;
}
#if SDL_USE_NIB_FILE
/* A helper category for NSString */
@interface NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
@end
#endif
@interface NSApplication (SDLApplication)
@end
@implementation NSApplication (SDLApplication)
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
/* The main class of the application, the application's delegate */
@implementation SDLMain
/* Set the working directory to the .app's parent directory */
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
chdir(parentdir); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}
}
#if SDL_USE_NIB_FILE
/* Fix menu to contain the real app name instead of "SDL App" */
- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
{
NSRange aRange;
NSEnumerator *enumerator;
NSMenuItem *menuItem;
aRange = [[aMenu title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
enumerator = [[aMenu itemArray] objectEnumerator];
while ((menuItem = [enumerator nextObject]))
{
aRange = [[menuItem title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
if ([menuItem hasSubmenu])
[self fixMenu:[menuItem submenu] withAppName:appName];
}
}
#else
static void setApplicationMenu(void)
{
/* warning: this code is very odd */
NSMenu *appleMenu;
NSMenuItem *menuItem;
NSString *title;
NSString *appName;
appName = getApplicationName();
appleMenu = [[NSMenu alloc] initWithTitle:@""];
/* Add menu items */
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
/* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu];
/* Finally give up our references to the objects */
[appleMenu release];
[menuItem release];
}
/* Create a window menu */
static void setupWindowMenu(void)
{
NSMenu *windowMenu;
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
/* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
[windowMenu addItem:menuItem];
[menuItem release];
/* Put menu into the menubar */
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
[windowMenuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:windowMenuItem];
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
/* Finally give up our references to the objects */
[windowMenu release];
[windowMenuItem release];
}
/* Replacement for NSApplicationMain */
static void CustomApplicationMain (int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;
/* Ensure the application object is initialised */
[NSApplication sharedApplication];
#ifdef SDL_USE_CPS
{
CPSProcessSerNum PSN;
/* Tell the dock about us */
if (!CPSGetCurrentProcess(&PSN))
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
[NSApplication sharedApplication];
}
#endif /* SDL_USE_CPS */
/* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]];
setApplicationMenu();
setupWindowMenu();
/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];
/* Start the main event loop */
[NSApp run];
[sdlMain release];
[pool release];
}
#endif
/*
* Catch document open requests...this lets us notice files when the app
* was launched by double-clicking a document, or when a document was
* dragged/dropped on the app's icon. You need to have a
* CFBundleDocumentsType section in your Info.plist to get this message,
* apparently.
*
* Files are added to gArgv, so to the app, they'll look like command line
* arguments. Previously, apps launched from the finder had nothing but
* an argv[0].
*
* This message may be received multiple times to open several docs on launch.
*
* This message is ignored once the app's mainline has been called.
*/
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
const char *temparg;
size_t arglen;
char *arg;
char **newargv;
if (!gFinderLaunch) /* MacOS is passing command line args. */
return FALSE;
if (gCalledAppMainline) /* app has started, ignore this document. */
return FALSE;
temparg = [filename UTF8String];
arglen = SDL_strlen(temparg) + 1;
arg = (char *) SDL_malloc(arglen);
if (arg == NULL)
return FALSE;
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
if (newargv == NULL)
{
SDL_free(arg);
return FALSE;
}
gArgv = newargv;
SDL_strlcpy(arg, temparg, arglen);
gArgv[gArgc++] = arg;
gArgv[gArgc] = NULL;
return TRUE;
}
/* Called when the internal event loop has just started running */
- (void) applicationDidFinishLaunching: (NSNotification *) note
{
int status;
/* Set the working directory to the .app's parent directory */
[self setupWorkingDirectory:gFinderLaunch];
#if SDL_USE_NIB_FILE
/* Set the main menu to contain the real app name instead of "SDL App" */
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
#endif
/* Hand off to main application code */
gCalledAppMainline = TRUE;
status = SDL_main (gArgc, gArgv);
/* We're done, thank you for playing */
exit(status);
}
@end
@implementation NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
{
unsigned int bufferSize;
unsigned int selfLen = [self length];
unsigned int aStringLen = [aString length];
unichar *buffer;
NSRange localRange;
NSString *result;
bufferSize = selfLen + aStringLen - aRange.length;
buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
/* Get first part into buffer */
localRange.location = 0;
localRange.length = aRange.location;
[self getCharacters:buffer range:localRange];
/* Get middle part into buffer */
localRange.location = 0;
localRange.length = aStringLen;
[aString getCharacters:(buffer+aRange.location) range:localRange];
/* Get last part into buffer */
localRange.location = aRange.location + aRange.length;
localRange.length = selfLen - localRange.location;
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
/* Build output string */
result = [NSString stringWithCharacters:buffer length:bufferSize];
NSDeallocateMemoryPages(buffer, bufferSize);
return result;
}
@end
#ifdef main
# undef main
#endif
/* Main entry point to executable - should *not* be SDL_main! */
int main (int argc, char **argv)
{
/* Copy the arguments into a global variable */
/* This is passed if we are launched by double-clicking */
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
gArgv[0] = argv[0];
gArgv[1] = NULL;
gArgc = 1;
gFinderLaunch = YES;
} else {
int i;
gArgc = argc;
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
for (i = 0; i <= argc; i++)
gArgv[i] = argv[i];
gFinderLaunch = NO;
}
#if SDL_USE_NIB_FILE
NSApplicationMain (argc, argv);
#else
CustomApplicationMain (argc, argv);
#endif
return 0;
}

Binary file not shown.