Fixed nasty crashes in TeeWorlds, it's still unplayable and FPS is hell low, but you can connect to a server now

This commit is contained in:
pelya
2010-09-06 16:34:08 +03:00
parent a624926c92
commit 768f48b345
10 changed files with 62 additions and 7 deletions

View File

@@ -575,6 +575,9 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_f
else if(format == IMG_ALPHA)
{
oglformat = GL_ALPHA;
#ifdef ANDROID
oglformat = GL_RGBA; // No pure alpha textures on Android
#endif
glesType = GL_UNSIGNED_SHORT_4_4_4_4;
}
@@ -625,7 +628,7 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_f
((Uint16 *)tmpdata)[ y*(Uint32)w+x ] = CONVERT_RGB888_RGB565( ((* ((Uint32 *)(texdata+(y*w+x)*3))) & 0xFFFFFF) );
}
}
else // RGBA
else // RGBA or ALPHA
{
for(y = 0; y < h; y++)
for(x = 0; x < w; x++)

View File

@@ -41,6 +41,11 @@ void inp_mouse_relative(int *x, int *y)
*y = ny*sens;
}
void inp_mouse_absolute(int *x, int *y)
{
SDL_GetMouseState(x, y);
}
enum
{
INPUT_BUFFER_SIZE=32

View File

@@ -14,6 +14,10 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifdef ANDROID
#include <strings.h>
#include <alloca.h>
#endif
enum
{
@@ -143,9 +147,17 @@ static int iabs(int i)
static void mix(short *final_out, unsigned frames)
{
int mix_buffer[MAX_FRAMES*2] = {0};
int i, s;
int master_vol;
#ifdef ANDROID
// The size of buffer SDL returns to us may vary greatly across devices, and will easily exceed MAX_FRAMES size -> segfault
// (on older devices the buffer should be large, otherwise the sound will be choppy)
// Why didn't they just use SDL_mixer there, and go on with own buggy mixer implementation?
int * mix_buffer = (int *)alloca(frames * 2 * sizeof(int));
bzero(mix_buffer, frames * 2 * sizeof(int));
#else
int mix_buffer[MAX_FRAMES*2] = {0};
#endif
/* aquire lock while we are mixing */
lock_wait(sound_lock);
@@ -252,7 +264,7 @@ static void sdlcallback(void *unused, Uint8 *stream, int len)
int snd_init()
{
SDL_AudioSpec format;
SDL_AudioSpec format, format2;
sound_lock = lock_create();
@@ -270,14 +282,14 @@ int snd_init()
format.userdata = NULL;
/* Open the audio device and start playing sound! */
if(SDL_OpenAudio(&format, NULL) < 0)
if(SDL_OpenAudio(&format, &format2) < 0)
{
dbg_msg("client/sound", "unable to open audio: %s", SDL_GetError());
return -1;
}
else
dbg_msg("client/sound", "sound init successful");
SDL_PauseAudio(0);
sound_enabled = 1;

View File

@@ -31,11 +31,10 @@ MACRO_CONFIG_INT(b_sort, 0, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(b_sort_order, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(b_max_requests, 10, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Number of requests to use when refreshing server browser")
MACRO_CONFIG_INT(snd_buffer_size, 512, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size")
#ifdef ANDROID
MACRO_CONFIG_INT(snd_buffer_size, 1024, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size")
MACRO_CONFIG_INT(snd_rate, 22050, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound mixing rate")
#else
MACRO_CONFIG_INT(snd_buffer_size, 512, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size")
MACRO_CONFIG_INT(snd_rate, 48000, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound mixing rate")
#endif
MACRO_CONFIG_INT(snd_enable, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound enable")

View File

@@ -38,6 +38,8 @@ typedef struct
*/
void inp_mouse_relative(int *x, int *y);
void inp_mouse_absolute(int *x, int *y);
/*
Function: inp_mouse_scroll
TODO

View File

@@ -178,6 +178,9 @@ bool CONTROLS::on_mousemove(float x, float y)
if(gameclient.snap.gameobj && gameclient.snap.gameobj->paused)
return false;
mouse_pos += vec2(x, y); // TODO: ugly
#ifdef ANDROID
mouse_pos = vec2(x, y);
#endif
//
float camera_max_distance = 200.0f;

View File

@@ -52,6 +52,9 @@ bool EMOTICON::on_mousemove(float x, float y)
return false;
selector_mouse += vec2(x,y);
#ifdef ANDROID
selector_mouse = vec2(x,y);
#endif
return true;
}
@@ -92,10 +95,18 @@ void EMOTICON::on_render()
was_active = true;
int x, y;
#ifdef ANDROID
// No relative mouse here, we've got touchscreen
inp_mouse_absolute(&x, &y);
selector_mouse.x = x;
selector_mouse.y = y;
#else
inp_mouse_relative(&x, &y);
selector_mouse.x += x;
selector_mouse.y += y;
#endif
if (length(selector_mouse) > 140)
selector_mouse = normalize(selector_mouse) * 140;

View File

@@ -928,6 +928,12 @@ bool MENUS::on_mousemove(float x, float y)
mouse_pos.x += x;
mouse_pos.y += y;
#ifdef ANDROID
mouse_pos.x = x;
mouse_pos.y = y;
#endif
if(mouse_pos.x < 0) mouse_pos.x = 0;
if(mouse_pos.y < 0) mouse_pos.y = 0;
if(mouse_pos.x > gfx_screenwidth()) mouse_pos.x = gfx_screenwidth();

View File

@@ -245,8 +245,13 @@ void GAMECLIENT::dispatch_input()
{
// handle mouse movement
int x=0, y=0;
#ifdef ANDROID
// No relative mouse here, we've got touchscreen
inp_mouse_absolute(&x, &y);
#else
inp_mouse_relative(&x, &y);
if(x || y)
#endif
{
for(int h = 0; h < input.num; h++)
{

View File

@@ -2698,6 +2698,14 @@ extern "C" void editor_update_and_render()
float mx, my, mwx, mwy;
int rx, ry;
{
#ifdef ANDROID
// No relative mouse here, we've got touchscreen
inp_mouse_absolute(&rx, &ry);
editor.mouse_delta_x = rx - mouse_x;
editor.mouse_delta_y = ry - mouse_y;
mouse_x = rx;
mouse_y = ry;
#else
inp_mouse_relative(&rx, &ry);
editor.mouse_delta_x = rx;
editor.mouse_delta_y = ry;
@@ -2707,6 +2715,7 @@ extern "C" void editor_update_and_render()
mouse_x += rx;
mouse_y += ry;
}
#endif
if(mouse_x < 0) mouse_x = 0;
if(mouse_y < 0) mouse_y = 0;