diff options
| author | jacksonmj <jacksonmj@jacksonmj.none> | 2011-02-03 18:45:56 (GMT) |
|---|---|---|
| committer | jacksonmj <jacksonmj@jacksonmj.none> | 2011-02-03 18:47:23 (GMT) |
| commit | d21d1f7ba58d1fc2f1b6ccbfc945e440e16a06b7 (patch) | |
| tree | 186b21250c8f731887de996156d845e064722a47 /src | |
| parent | 54caad7a69c424b6bcb78374aa0d0785a8a5ac93 (diff) | |
| parent | 525a59e28011cf26993c8e3f040a36ba7b7bf5e2 (diff) | |
| download | powder-d21d1f7ba58d1fc2f1b6ccbfc945e440e16a06b7.zip powder-d21d1f7ba58d1fc2f1b6ccbfc945e440e16a06b7.tar.gz | |
Merge branch 'upstream' into dev
Diffstat (limited to 'src')
| -rw-r--r-- | src/graphics.c | 2 | ||||
| -rw-r--r-- | src/interface.c | 31 | ||||
| -rw-r--r-- | src/main.c | 193 | ||||
| -rw-r--r-- | src/powder.c | 6 |
4 files changed, 196 insertions, 36 deletions
diff --git a/src/graphics.c b/src/graphics.c index 786bdca..2d9989f 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -2907,7 +2907,7 @@ void render_signs(pixel *vid_buf) sprintf(buff, "Temp: 0.00"); //...tempirature drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255); } - + if(sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0) { int sldr, startm; diff --git a/src/interface.c b/src/interface.c index 1c2c59a..570755d 100644 --- a/src/interface.c +++ b/src/interface.c @@ -96,7 +96,7 @@ void get_sign_pos(int i, int *x0, int *y0, int *w, int *h) memset(buff, 0, sizeof(buff)); for(sldr=3; signs[i].text[sldr-1] != '|'; sldr++) startm = sldr + 1; - + sldr = startm; while(signs[i].text[sldr] != '}') { @@ -105,7 +105,7 @@ void get_sign_pos(int i, int *x0, int *y0, int *w, int *h) } *w = textwidth(buff) + 5; } - + //Ususal width if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$")) *w = textwidth(signs[i].text) + 5; @@ -874,13 +874,13 @@ void login_ui(pixel *vid_buf) *(s_id++) = 0; u_e = strchr(s_id, ' '); - if (!u_e){ + if (!u_e) { u_e = malloc(1); memset(u_e, 0, 1); } else *(u_e++) = 0; - + strcpy(svf_user_id, res+3); strcpy(svf_session_id, s_id); nres = mystrdup(u_e); @@ -3866,17 +3866,18 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent? draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE); drawtext(vid_buf, 100, 15, "Welcome to The Powder Toy console v.2 (by cracker64)\n" - "Current commands are quit, set, reset, load, create, file, kill\n" - "You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n" - "You can also use 'all' instead of a particle number to do it to everything.\n" - "You can now use particle names (ex. set type all deut)\n" - "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n" - "To load a save use load saveID (ex. load 1337)\n" - "Create particles with 'create deut x,y' where x and y are the coords\n" - "Run scripts from file 'file filename'\n" - "You can delete/kill a particle with 'kill x,y'" - ,255, 187, 187, 255); - + "Current commands are quit, set, reset, load, create, file, kill, sound\n" + "You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n" + "You can also use 'all' instead of a particle number to do it to everything.\n" + "You can now use particle names (ex. set type all deut)\n" + "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n" + "To load a save use load saveID (ex. load 1337)\n" + "Create particles with 'create deut x,y' where x and y are the coords\n" + "Run scripts from file 'file filename'\n" + "You can delete/kill a particle with 'kill x,y'" + "Play a sound with (sound blah.wav)" + ,255, 187, 187, 255); + cc = 0; currentcommand = last_command; while(cc < 10) @@ -28,6 +28,7 @@ #include <string.h> #include <math.h> #include <SDL/SDL.h> +#include <SDL/SDL_audio.h> #include <bzlib.h> #include <time.h> @@ -51,6 +52,69 @@ #include <air.h> #include <icon.h> +#define NUM_SOUNDS 2 +struct sample { + Uint8 *data; + Uint32 dpos; + Uint32 dlen; +} sounds[NUM_SOUNDS]; + +void mixaudio(void *unused, Uint8 *stream, int len) +{ + int i; + Uint32 amount; + + for ( i=0; i<NUM_SOUNDS; ++i ) { + amount = (sounds[i].dlen-sounds[i].dpos); + if ( amount > len ) { + amount = len; + } + SDL_MixAudio(stream, &sounds[i].data[sounds[i].dpos], amount, SDL_MIX_MAXVOLUME); + sounds[i].dpos += amount; + } +} + +void play_sound(char *file) +{ + int index; + SDL_AudioSpec wave; + Uint8 *data; + Uint32 dlen; + SDL_AudioCVT cvt; + + /* Look for an empty (or finished) sound slot */ + for ( index=0; index<NUM_SOUNDS; ++index ) { + if ( sounds[index].dpos == sounds[index].dlen ) { + break; + } + } + if ( index == NUM_SOUNDS ) + return; + + /* Load the sound file and convert it to 16-bit stereo at 22kHz */ + if ( SDL_LoadWAV(file, &wave, &data, &dlen) == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); + return; + } + SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq, + AUDIO_S16, 2, 22050); + cvt.buf = malloc(dlen*cvt.len_mult); + memcpy(cvt.buf, data, dlen); + cvt.len = dlen; + SDL_ConvertAudio(&cvt); + SDL_FreeWAV(data); + + /* Put the sound data in the slot (it starts playing immediately) */ + if ( sounds[index].data ) { + free(sounds[index].data); + } + SDL_LockAudio(); + sounds[index].data = cvt.buf; + sounds[index].dlen = cvt.len_cvt; + sounds[index].dpos = 0; + SDL_UnlockAudio(); +} + static const char *it_msg = "\brThe Powder Toy - http://powdertoy.co.uk/\n" "\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\n" @@ -479,10 +543,6 @@ int parse_save(void *save, int size, int replace, int x0, int y0) if (replace) { gravityMode = 1; - memset(photons, 0, sizeof(photons)); - memset(wireless, 0, sizeof(wireless)); - memset(gol2, 0, sizeof(gol2)); - memset(portal, 0, sizeof(portal)); memset(bmap, 0, sizeof(bmap)); memset(emap, 0, sizeof(emap)); @@ -1136,6 +1196,21 @@ int main(int argc, char *argv[]) int save_mode=0, save_x=0, save_y=0, save_w=0, save_h=0, copy_mode=0; GSPEED = 1; + SDL_AudioSpec fmt; + /* Set 16-bit stereo audio at 22Khz */ + fmt.freq = 22050; + fmt.format = AUDIO_S16; + fmt.channels = 2; + fmt.samples = 512; + fmt.callback = mixaudio; + fmt.userdata = NULL; + /* Open the audio device and start playing sound! */ + if ( SDL_OpenAudio(&fmt, NULL) < 0 ) + { + fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); + exit(1); + } + SDL_PauseAudio(0); #ifdef MT numCores = core_count(); #endif @@ -2164,10 +2239,10 @@ int main(int argc, char *argv[]) else if (y<YRES) { int signi; - + c = (b&1) ? sl : sr; su = c; - + if(c!=WL_SIGN+100) { if(!bq) @@ -2180,12 +2255,12 @@ int main(int argc, char *argv[]) { char buff[256]; int sldr; - + memset(buff, 0, sizeof(buff)); - + for(sldr=3; signs[signi].text[sldr] != '|'; sldr++) buff[sldr-3] = signs[signi].text[sldr]; - + char buff2[sldr-2]; //TODO: Fix this for Visual Studio memset(buff2, 0, sizeof(buff2)); memcpy(&buff2, &buff, sldr-3); @@ -2193,7 +2268,7 @@ int main(int argc, char *argv[]) } } } - + if (c==WL_SIGN+100) { if (!bq) @@ -2303,7 +2378,6 @@ int main(int argc, char *argv[]) cb_bmap[cby][cbx] = bmap[cby][cbx]; cb_emap[cby][cbx] = emap[cby][cbx]; } - create_parts(x, y, bsx, bsy, c); lx = x; ly = y; @@ -2522,7 +2596,7 @@ int main(int argc, char *argv[]) if(DEBUG_MODE) { fillrect(vid_buf, XRES-20-textwidth(coordtext), 26, textwidth(coordtext)+8, 11, 0, 0, 0, 140); - drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, 200); + drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, 200); } } fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, 140); @@ -2547,12 +2621,12 @@ int main(int argc, char *argv[]) } } - + SDL_CloseAudio(); http_done(); return 0; } int process_command(pixel *vid_buf,char *console,char *console_error) { - int nx,ny,i,j; + int nx,ny,i,j,k; char *console2; char *console3; char *console4; @@ -2594,6 +2668,10 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { else sprintf(console_error, "%s does not exist", console3); } + else if(strcmp(console2, "sound")==0 && console3) + { + play_sound(console3); + } else if(strcmp(console2, "load")==0 && console3) { j = atoi(console3); @@ -2606,7 +2684,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { else if (strcmp(console2, "create")==0 && console3 && console4) { if (console_parse_type(console3, &j, console_error) - && console_parse_coords(console4, &nx, &ny, console_error)) + && console_parse_coords(console4, &nx, &ny, console_error)) { if (!j) strcpy(console_error, "Cannot create particle with type NONE"); @@ -2673,6 +2751,15 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].life = j; } } + else if (console_parse_type(console4, &j, console_error)) + { + k = atoi(console5); + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].life = k; + } + } else { if (console_parse_partref(console4, &i, console_error)) @@ -2693,10 +2780,19 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].type = j; } } + else if (console_parse_type(console4, &j, console_error) + && console_parse_type(console5, &k, console_error)) + { + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].type = k; + } + } else { if (console_parse_partref(console4, &i, console_error) - && console_parse_type(console5, &j, console_error)) + && console_parse_type(console5, &j, console_error)) { parts[i].type = j; } @@ -2713,6 +2809,15 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].temp = j; } } + else if (console_parse_type(console4, &j, console_error)) + { + k = atoi(console5); + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].temp= k; + } + } else { if (console_parse_partref(console4, &i, console_error)) @@ -2733,6 +2838,15 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].tmp = j; } } + else if (console_parse_type(console4, &j, console_error)) + { + k = atoi(console5); + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].tmp = k; + } + } else { if (console_parse_partref(console4, &i, console_error)) @@ -2753,6 +2867,15 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].x = j; } } + else if (console_parse_type(console4, &j, console_error)) + { + k = atoi(console5); + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].x = k; + } + } else { if (console_parse_partref(console4, &i, console_error)) @@ -2773,6 +2896,15 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].y = j; } } + else if (console_parse_type(console4, &j, console_error)) + { + k = atoi(console5); + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].y = k; + } + } else { if (console_parse_partref(console4, &i, console_error)) @@ -2793,10 +2925,19 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].ctype = j; } } + else if (console_parse_type(console4, &j, console_error) + && console_parse_type(console5, &k, console_error)) + { + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].ctype = k; + } + } else { if (console_parse_partref(console4, &i, console_error) - && console_parse_type(console5, &j, console_error)) + && console_parse_type(console5, &j, console_error)) { parts[i].ctype = j; } @@ -2813,6 +2954,15 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].vx = j; } } + else if (console_parse_type(console4, &j, console_error)) + { + k = atoi(console5); + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].vx = k; + } + } else { if (console_parse_partref(console4, &i, console_error)) @@ -2833,6 +2983,15 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { parts[i].vy = j; } } + else if (console_parse_type(console4, &j, console_error)) + { + k = atoi(console5); + for(i=0; i<NPART; i++) + { + if(parts[i].type == j) + parts[i].vy = k; + } + } else { if (console_parse_partref(console4, &i, console_error)) diff --git a/src/powder.c b/src/powder.c index 3c85167..4d8ba45 100644 --- a/src/powder.c +++ b/src/powder.c @@ -577,7 +577,7 @@ inline int create_part(int p, int x, int y, int t) if (t==PT_SPRK) { - if (!((pmap[y][x]&0xFF)==PT_INST||(ptypes[pmap[y][x]&0xFF].properties&PROP_CONDUCTS))) + if ((pmap[y][x]>>8)>=NPART || !((pmap[y][x]&0xFF)==PT_INST||(ptypes[pmap[y][x]&0xFF].properties&PROP_CONDUCTS))) return -1; if (parts[pmap[y][x]>>8].life!=0) return -1; @@ -1525,10 +1525,10 @@ void update_particles_i(pixel *vid, int start, int inc) ctemph = ctempl = pt; // change boiling point with pressure if ((ptypes[t].state==ST_LIQUID && ptransitions[t].tht>-1 && ptransitions[t].tht<PT_NUM && ptypes[ptransitions[t].tht].state==ST_GAS) - || t==PT_LNTG || t==PT_SLTW) + || t==PT_LNTG || t==PT_SLTW) ctemph -= 2.0f*pv[y/CELL][x/CELL]; else if ((ptypes[t].state==ST_GAS && ptransitions[t].tlt>-1 && ptransitions[t].tlt<PT_NUM && ptypes[ptransitions[t].tlt].state==ST_LIQUID) - || t==PT_WTRV) + || t==PT_WTRV) ctempl -= 2.0f*pv[y/CELL][x/CELL]; s = 1; if (ctemph>ptransitions[t].thv&&ptransitions[t].tht>-1) { |
