Thread: [Moeng-cvs] BBRpg/src canvas.cpp, 1.5, 1.6 canvas.h, 1.4, 1.5 rpg.h, 1.7, 1.8 script.cpp, 1.17, 1.1
Status: Alpha
Brought to you by:
b_lindeijer
From: Bjørn L. <b_l...@us...> - 2007-02-07 17:50:50
|
Update of /cvsroot/moeng/BBRpg/src In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9875/src Modified Files: canvas.cpp canvas.h rpg.h script.cpp sound.cpp sound.h Log Message: Converted files to use UNIX newlines and added Code::Blocks project file. Index: canvas.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/canvas.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** canvas.h 23 Oct 2004 11:54:17 -0000 1.4 --- canvas.h 7 Feb 2007 17:50:31 -0000 1.5 *************** *** 1,50 **** ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #ifndef _INCLUDED_CANVAS_H_ ! #define _INCLUDED_CANVAS_H_ ! ! #include <allegro.h> ! #include "shared/tiled_map.h" ! ! class Canvas ! { ! public: ! void init(); ! void getCursor(int *x, int *y); ! void setCursor(int x, int y); ! void getClip(int *x1, int *y1, int *x2, int *y2); ! void setClip(int x1, int y1, int x2, int y2); ! void setColor(int color); ! void setDrawMode(int drawMode); ! int getDrawMode() {return drawMode;} ! void setAlpha(int alpha); ! int getAlpha() {return alpha;} ! void setFont(FONT* font); ! void textSize(const char *text, int *width, int *height); ! void bitmapSize(BITMAP *bmp, int *width, int *height); ! void drawText(const char *text); ! void drawBitmap(BITMAP *bmp,int dw,int dh,int sx,int sy,int sw,int sh); ! void drawViewport(int x,int y,int w,int h,int tx,int ty,TiledMap* map); ! ! private: ! int curX, curY; // The current cursor position ! int drawColor; // The currently used draw color ! int alpha; // The currently used opacity ! FONT* myFont; // The currently used font ! int drawMode; // The currently used drawmode ! }; ! ! ! extern Canvas canvas; ! ! ! #endif --- 1,50 ---- ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #ifndef _INCLUDED_CANVAS_H_ ! #define _INCLUDED_CANVAS_H_ ! ! #include <allegro.h> ! #include "shared/tiled_map.h" ! ! class Canvas ! { ! public: ! void init(); ! void getCursor(int *x, int *y); ! void setCursor(int x, int y); ! void getClip(int *x1, int *y1, int *x2, int *y2); ! void setClip(int x1, int y1, int x2, int y2); ! void setColor(int color); ! void setDrawMode(int drawMode); ! int getDrawMode() {return drawMode;} ! void setAlpha(int alpha); ! int getAlpha() {return alpha;} ! void setFont(FONT* font); ! void textSize(const char *text, int *width, int *height); ! void bitmapSize(BITMAP *bmp, int *width, int *height); ! void drawText(const char *text); ! void drawBitmap(BITMAP *bmp,int dw,int dh,int sx,int sy,int sw,int sh); ! void drawViewport(int x,int y,int w,int h,int tx,int ty,TiledMap* map); ! ! private: ! int curX, curY; // The current cursor position ! int drawColor; // The currently used draw color ! int alpha; // The currently used opacity ! FONT* myFont; // The currently used font ! int drawMode; // The currently used drawmode ! }; ! ! ! extern Canvas canvas; ! ! ! #endif Index: canvas.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/canvas.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** canvas.cpp 23 Oct 2004 11:54:09 -0000 1.5 --- canvas.cpp 7 Feb 2007 17:50:31 -0000 1.6 *************** *** 1,194 **** ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #include <allegro.h> ! #include "common.h" ! #include "rpg.h" ! #include "canvas.h" ! ! ! //=================== The canvas =======================================/ ! ! Canvas canvas; ! ! ! ! //=================== The canvas methods ===============================/ ! ! void Canvas::init() ! { ! curX = 0; ! curY = 0; ! set_clip_rect(buffer, 0, 0, SCREEN_W - 1, SCREEN_H - 1); ! myFont = font; ! drawColor = makecol(255,255,255); ! alpha = 255; ! drawMode = DM_MASKED; ! } ! ! void Canvas::getCursor(int *x, int *y) ! { ! ASSERT(x && y); ! *x = curX; ! *y = curY; ! } ! ! void Canvas::setCursor(int x, int y) ! { ! curX = x; ! curY = y; ! } ! ! void Canvas::getClip(int *x1, int *y1, int *x2, int *y2) ! { ! ASSERT(x1 && y1 && x2 && y2); ! *x1 = buffer->cl; ! *y1 = buffer->ct; ! *x2 = buffer->cr; ! *y2 = buffer->cb; ! } ! ! void Canvas::setClip(int x1, int y1, int x2, int y2) ! { ! set_clip_rect(buffer, x1, y1, x2, y2); ! } ! ! void Canvas::setColor(int color) ! { ! drawColor = color; ! } ! ! void Canvas::setDrawMode(int drawMode) ! { ! this->drawMode = drawMode; ! } ! ! void Canvas::setAlpha(int alpha) ! { ! this->alpha = alpha; ! } ! ! void Canvas::setFont(FONT *font) ! { ! if (font) myFont = font; ! } ! ! void Canvas::textSize(const char *text, int *w, int *h) ! { ! ASSERT(w && h); ! *w = text_length(myFont, text); ! *h = text_height(myFont); ! } ! ! void Canvas::drawText(const char *text) ! { ! ASSERT(text); ! textout_ex(buffer, myFont, text, curX, curY, drawColor, -1); ! curX += text_length(myFont, text); ! } ! ! void Canvas::drawBitmap(BITMAP *bmp, int dw, int dh, int sx, int sy, int sw, int sh) ! { ! /* ! console.log( ! CON_LOG | CON_CONSOLE, ! CON_DEBUG, ! "Processing draw_bitmap(bmp, %d, %d, %d, %d, %d, %d)", ! dw, dh, sx, sy, sw, sh ! ); ! */ ! ASSERT(bitmap); ! BITMAP *src = NULL; ! ! // Don't try to process invalid surfaces ! if (dw < 0 || dh < 0) return; ! ! if (sx != 0 || sy != 0 || sw != bmp->w || sh != bmp->h) ! { ! // The source bitmap needs to be adapted first ! src = create_bitmap(sw, sh); ! ASSERT(src); ! ! // Determine the point where we should start drawing ! int start_x = -sx % bmp->w; ! int start_y = -sy % bmp->h; ! if (start_x > 0) start_x -= bmp->w; ! if (start_y > 0) start_y -= bmp->h; ! int x = start_x; ! int y = start_y; ! ! // Create tiled pattern ! while (y < sh) { ! while (x < sw) { ! blit(bmp, src, 0, 0, x, y, bmp->w, bmp->h); ! x += bmp->w; ! } ! x = start_x; ! y += bmp->h; ! } ! ! bmp = src; ! } ! ! // Now we'll put this sprite on the screen ! switch (drawMode) { ! case DM_ALPHA: ! set_alpha_blender(); ! break; ! case DM_TRANS: ! set_trans_blender(0,0,0,alpha); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! break; ! } ! if ((drawMode == DM_TRANS && alpha < 255) || drawMode == DM_ALPHA || drawMode == DM_ADD) { ! if (sw == dw && sh == dh) { ! draw_trans_sprite(buffer, bmp, curX, curY); ! } ! else { ! BITMAP *stretch = create_bitmap(dw, dh); ! if (stretch) { ! stretch_sprite(stretch, bmp, 0, 0, dw, dh); ! draw_trans_sprite(buffer, stretch, curX, curY); ! destroy_bitmap(stretch); ! } ! } ! } ! else ! { ! if (sw == dw && sh == dh) { ! draw_sprite(buffer, bmp, curX, curY); ! } ! else { ! stretch_sprite(buffer, bmp, curX, curY, dw, dh); ! } ! } ! switch (drawMode) { ! case DM_TRANS: ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! break; ! } ! ! if (src) destroy_bitmap(src); ! ! // And don't forget to move that cursor ! curX += dw; ! } ! ! void Canvas::drawViewport(int x, int y, int w, int h, int tx, int ty, TiledMap* map) ! { ! map->setCamera( ! Point(tx, ty), ! Rectangle(x, y, w, h), ! true, true ! ); ! ! map->draw(buffer, debug_mode); ! } --- 1,194 ---- ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #include <allegro.h> ! #include "common.h" ! #include "rpg.h" ! #include "canvas.h" ! ! ! //=================== The canvas =======================================/ ! ! Canvas canvas; ! ! ! ! //=================== The canvas methods ===============================/ ! ! void Canvas::init() ! { ! curX = 0; ! curY = 0; ! set_clip_rect(buffer, 0, 0, SCREEN_W - 1, SCREEN_H - 1); ! myFont = font; ! drawColor = makecol(255,255,255); ! alpha = 255; ! drawMode = DM_MASKED; ! } ! ! void Canvas::getCursor(int *x, int *y) ! { ! ASSERT(x && y); ! *x = curX; ! *y = curY; ! } ! ! void Canvas::setCursor(int x, int y) ! { ! curX = x; ! curY = y; ! } ! ! void Canvas::getClip(int *x1, int *y1, int *x2, int *y2) ! { ! ASSERT(x1 && y1 && x2 && y2); ! *x1 = buffer->cl; ! *y1 = buffer->ct; ! *x2 = buffer->cr; ! *y2 = buffer->cb; ! } ! ! void Canvas::setClip(int x1, int y1, int x2, int y2) ! { ! set_clip_rect(buffer, x1, y1, x2, y2); ! } ! ! void Canvas::setColor(int color) ! { ! drawColor = color; ! } ! ! void Canvas::setDrawMode(int drawMode) ! { ! this->drawMode = drawMode; ! } ! ! void Canvas::setAlpha(int alpha) ! { ! this->alpha = alpha; ! } ! ! void Canvas::setFont(FONT *font) ! { ! if (font) myFont = font; ! } ! ! void Canvas::textSize(const char *text, int *w, int *h) ! { ! ASSERT(w && h); ! *w = text_length(myFont, text); ! *h = text_height(myFont); ! } ! ! void Canvas::drawText(const char *text) ! { ! ASSERT(text); ! textout_ex(buffer, myFont, text, curX, curY, drawColor, -1); ! curX += text_length(myFont, text); ! } ! ! void Canvas::drawBitmap(BITMAP *bmp, int dw, int dh, int sx, int sy, int sw, int sh) ! { ! /* ! console.log( ! CON_LOG | CON_CONSOLE, ! CON_DEBUG, ! "Processing draw_bitmap(bmp, %d, %d, %d, %d, %d, %d)", ! dw, dh, sx, sy, sw, sh ! ); ! */ ! ASSERT(bitmap); ! BITMAP *src = NULL; ! ! // Don't try to process invalid surfaces ! if (dw < 0 || dh < 0) return; ! ! if (sx != 0 || sy != 0 || sw != bmp->w || sh != bmp->h) ! { ! // The source bitmap needs to be adapted first ! src = create_bitmap(sw, sh); ! ASSERT(src); ! ! // Determine the point where we should start drawing ! int start_x = -sx % bmp->w; ! int start_y = -sy % bmp->h; ! if (start_x > 0) start_x -= bmp->w; ! if (start_y > 0) start_y -= bmp->h; ! int x = start_x; ! int y = start_y; ! ! // Create tiled pattern ! while (y < sh) { ! while (x < sw) { ! blit(bmp, src, 0, 0, x, y, bmp->w, bmp->h); ! x += bmp->w; ! } ! x = start_x; ! y += bmp->h; ! } ! ! bmp = src; ! } ! ! // Now we'll put this sprite on the screen ! switch (drawMode) { ! case DM_ALPHA: ! set_alpha_blender(); ! break; ! case DM_TRANS: ! set_trans_blender(0,0,0,alpha); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! break; ! } ! if ((drawMode == DM_TRANS && alpha < 255) || drawMode == DM_ALPHA || drawMode == DM_ADD) { ! if (sw == dw && sh == dh) { ! draw_trans_sprite(buffer, bmp, curX, curY); ! } ! else { ! BITMAP *stretch = create_bitmap(dw, dh); ! if (stretch) { ! stretch_sprite(stretch, bmp, 0, 0, dw, dh); ! draw_trans_sprite(buffer, stretch, curX, curY); ! destroy_bitmap(stretch); ! } ! } ! } ! else ! { ! if (sw == dw && sh == dh) { ! draw_sprite(buffer, bmp, curX, curY); ! } ! else { ! stretch_sprite(buffer, bmp, curX, curY, dw, dh); ! } ! } ! switch (drawMode) { ! case DM_TRANS: ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! break; ! } ! ! if (src) destroy_bitmap(src); ! ! // And don't forget to move that cursor ! curX += dw; ! } ! ! void Canvas::drawViewport(int x, int y, int w, int h, int tx, int ty, TiledMap* map) ! { ! map->setCamera( ! Point(tx, ty), ! Rectangle(x, y, w, h), ! true, true ! ); ! ! map->draw(buffer, debug_mode); ! } Index: sound.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/sound.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** sound.cpp 23 Oct 2004 11:54:18 -0000 1.11 --- sound.cpp 7 Feb 2007 17:50:31 -0000 1.12 *************** *** 1,272 **** ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! ! ! #include <allegro.h> ! #include "shared/console.h" ! #include "sound.h" ! #include "rpg.h" ! #include "script.h" ! #include "common.h" ! ! #ifdef ENABLE_MUSIC ! #include <alogg/alogg.h> ! #endif ! ! ! int sound_enabled = 1; ! int sfx_enabled = 1; ! int sfx_vol = 255; ! int music_vol = 255; ! int music_format = 0; ! ! ! // Currently playing OGG file ! struct { ! SAMPLE *sample; ! int voice; ! struct alogg_stream *stream; ! AUDIOSTREAM *ass; ! char filename[128]; ! } channels[CHANNELS]; ! ! char *error; ! ! ! ! void init_sound() { ! // To achieve the max possible volume ! set_volume_per_voice(0); ! ! // Initialize alogg ! ! int midi_driver = MIDI_NONE; ! int sound_driver = DIGI_NONE; ! ! if (sound_enabled && music_format == MUSIC_MIDI) { ! midi_driver = MIDI_AUTODETECT; ! } ! if (sfx_enabled || (sound_enabled && music_format != MUSIC_MIDI)) { ! #ifdef ENABLE_MUSIC ! alogg_init(); ! #endif ! sound_driver = DIGI_AUTODETECT; ! } ! ! // Install sound driver ! if (install_sound(sound_driver, midi_driver, NULL) != 0) { ! console.log(CON_LOG, CON_ALWAYS, "Error initialising sound system: %s", allegro_error); ! return; ! } ! ! #ifdef ENABLE_MUSIC ! // Initialize channels to NULL ! for (int i = 0; i < CHANNELS; i++) { ! channels[i].voice = 0; ! channels[i].sample = NULL; ! channels[i].stream = NULL; ! channels[i].ass = NULL; ! } ! #endif ! } ! ! ! ! /* play_music(filename, channel) ! */ ! int l_play_music(lua_State *L) ! { ! char* filename; ! int channel; ! getLuaArguments(L, "si", &filename, &channel); ! ! error = NULL; ! ! if (channel < 0 || channel > CHANNELS) {error = "invalid channel";} ! ! if (sound_enabled && error == NULL) { ! if (music_format == MUSIC_MIDI) { ! replace_extension(channels[channel].filename, get_filename(filename), "mid", 128); ! ! MIDI *midi = module->findMidi(channels[channel].filename); ! if (midi) { ! play_looped_midi(midi, 0, -1); ! } else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, ! "Could not find MIDI file in datafile (%s)", ! channels[channel].filename); ! } ! } else { ! #ifdef ENABLE_MUSIC ! // Stop currently playing music ! stop_music(channel); ! ! if (!exists(filename)) {error = "file does not exist";} ! ! strncpy(channels[channel].filename, filename, 128); ! ! channels[channel].stream = alogg_start_streaming(channels[channel].filename, BLOCK_SIZE); ! if (!channels[channel].stream) { ! fprintf(stderr,"Error opening %s\n", channels[channel].filename); ! alogg_exit(); ! exit(1); ! } ! channels[channel].ass = alogg_get_audio_stream(channels[channel].stream); ! voice_set_volume(channels[channel].ass->voice, music_vol); ! #endif ! } ! } ! ! if (error == NULL) { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Playing music file (%s)", filename); ! } ! else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Error playing music file \"%s\" (%s)", filename, error); ! } ! ! return 0; ! } ! ! ! #ifdef ENABLE_MUSIC ! ! /* adjust_channel(channel, volume, panning, speed) ! */ ! int l_adjust_channel(lua_State *L) ! { ! int channel, vol, pan, speed; ! getLuaArguments(L, "iiii", &channel, &vol, &pan, &speed); ! ! error = NULL; ! ! if (sound_enabled && music_format != MUSIC_MIDI) { ! if (channel < 0 || channel > CHANNELS) {error = "invalid channel";} ! else if (!channels[channel].ass) {error = "no music on this channel to adjust";} ! else if (vol < 0 || vol > 255) {error = "illegal volume value";} ! else if (pan < 0 || pan > 255) {error = "illegal panning value";} ! else if (speed < 0) {error = "illegal speed value";} ! ! if (error == NULL) { ! voice_set_volume(channels[channel].ass->voice, int(vol * (float(music_vol) / 255.0f))); ! //console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Adjusted channel parameters (%d, %d, %d, %d)", channel, vol, pan, speed); ! } else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Error adjusting channel parameters (%s)", error); ! } ! } ! ! return 0; ! } ! ! /* get_number_of_channels() ! */ ! int l_get_number_of_channels(lua_State *L) ! { ! return putLuaArguments(L, "i", CHANNELS); ! } ! ! ! void poll_sound() ! { ! if (music_format != MUSIC_MIDI) { ! for (int i = 0; i < CHANNELS; i++) { ! if (channels[i].stream) { ! int ret = alogg_update_streaming(channels[i].stream); ! if (ret == 0) { ! // Loop song ! stop_music(i); ! channels[i].stream = alogg_start_streaming(channels[i].filename, BLOCK_SIZE); ! if (!channels[i].stream) { ! fprintf(stderr,"Error opening %s\n", channels[i].filename); ! alogg_exit(); ! exit(1); ! } ! channels[i].ass = alogg_get_audio_stream(channels[i].stream); ! break; ! } ! } ! } ! } ! } ! ! void stop_music(int channel) ! { ! /* ! if (channels[channel].voice) { ! deallocate_voice(channels[channel].voice); ! destroy_sample(channels[channel].sample); ! channels[channel].voice = 0; ! channels[channel].sample = NULL; ! } ! */ ! if (music_format != MUSIC_MIDI && channels[channel].stream) { ! alogg_stop_streaming(channels[channel].stream); ! channels[channel].stream = NULL; ! channels[channel].ass = NULL; ! } ! } ! ! ! /* stop_music(channel) ! */ ! int l_stop_music(lua_State *L) ! { ! int channel; ! getLuaArguments(L, "i", &channel); ! ! error = NULL; ! if (channel < 0 || channel >= CHANNELS) {error = "invalid channel";} ! ! if (error == NULL) { ! stop_music(channel); ! } else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Error stopping music (%s)", error); ! } ! return 0; ! } ! ! #endif ! ! ! /* play_sample(filename) ! */ ! int l_play_sample(lua_State *L) ! { ! char* name; ! getLuaArguments(L, "s", &name); ! ! if (sfx_enabled) { ! SAMPLE *sample = module->findSample(name); ! ! if (sample) { ! console.log(CON_LOG, CON_ALWAYS, "Playing sample: %s", name); ! play_sample(sample, sfx_vol, 128, 1000, 0); ! } else { ! console.log(CON_LOG, CON_ALWAYS, ! "Error: Cannot find requested sample (%s)!", name); ! } ! } ! ! return 0; ! } ! ! void exit_sound() ! { ! #ifdef ENABLE_MUSIC ! for (int i = 0; i < CHANNELS; i++) { ! stop_music(i); ! } ! ! if (sound_enabled && music_format != MUSIC_MIDI) { ! alogg_exit(); ! } ! #endif ! } --- 1,270 ---- ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #include <allegro.h> ! #include "shared/console.h" ! #include "sound.h" ! #include "rpg.h" ! #include "script.h" ! #include "common.h" ! ! #ifdef ENABLE_MUSIC ! #include <alogg/alogg.h> ! #endif ! ! ! int sound_enabled = 1; ! int sfx_enabled = 1; ! int sfx_vol = 255; ! int music_vol = 255; ! int music_format = 0; ! ! ! // Currently playing OGG file ! struct { ! SAMPLE *sample; ! int voice; ! struct alogg_stream *stream; ! AUDIOSTREAM *ass; ! char filename[128]; ! } channels[CHANNELS]; ! ! char *error; ! ! ! ! void init_sound() { ! // To achieve the max possible volume ! set_volume_per_voice(0); ! ! // Initialize alogg ! ! int midi_driver = MIDI_NONE; ! int sound_driver = DIGI_NONE; ! ! if (sound_enabled && music_format == MUSIC_MIDI) { ! midi_driver = MIDI_AUTODETECT; ! } ! if (sfx_enabled || (sound_enabled && music_format != MUSIC_MIDI)) { ! #ifdef ENABLE_MUSIC ! alogg_init(); ! #endif ! sound_driver = DIGI_AUTODETECT; ! } ! ! // Install sound driver ! if (install_sound(sound_driver, midi_driver, NULL) != 0) { ! console.log(CON_LOG, CON_ALWAYS, "Error initialising sound system: %s", allegro_error); ! return; ! } ! ! #ifdef ENABLE_MUSIC ! // Initialize channels to NULL ! for (int i = 0; i < CHANNELS; i++) { ! channels[i].voice = 0; ! channels[i].sample = NULL; ! channels[i].stream = NULL; ! channels[i].ass = NULL; ! } ! #endif ! } ! ! ! ! /* play_music(filename, channel) ! */ ! int l_play_music(lua_State *L) ! { ! char* filename; ! int channel; ! getLuaArguments(L, "si", &filename, &channel); ! ! error = NULL; ! ! if (channel < 0 || channel > CHANNELS) {error = "invalid channel";} ! ! if (sound_enabled && error == NULL) { ! if (music_format == MUSIC_MIDI) { ! replace_extension(channels[channel].filename, get_filename(filename), "mid", 128); ! ! MIDI *midi = module->findMidi(channels[channel].filename); ! if (midi) { ! play_looped_midi(midi, 0, -1); ! } else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, ! "Could not find MIDI file in datafile (%s)", ! channels[channel].filename); ! } ! } else { ! #ifdef ENABLE_MUSIC ! // Stop currently playing music ! stop_music(channel); ! ! if (!exists(filename)) {error = "file does not exist";} ! ! strncpy(channels[channel].filename, filename, 128); ! ! channels[channel].stream = alogg_start_streaming(channels[channel].filename, BLOCK_SIZE); ! if (!channels[channel].stream) { ! fprintf(stderr,"Error opening %s\n", channels[channel].filename); ! alogg_exit(); ! exit(1); ! } ! channels[channel].ass = alogg_get_audio_stream(channels[channel].stream); ! voice_set_volume(channels[channel].ass->voice, music_vol); ! #endif ! } ! } ! ! if (error == NULL) { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Playing music file (%s)", filename); ! } ! else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Error playing music file \"%s\" (%s)", filename, error); ! } ! ! return 0; ! } ! ! ! #ifdef ENABLE_MUSIC ! ! /* adjust_channel(channel, volume, panning, speed) ! */ ! int l_adjust_channel(lua_State *L) ! { ! int channel, vol, pan, speed; ! getLuaArguments(L, "iiii", &channel, &vol, &pan, &speed); ! ! error = NULL; ! ! if (sound_enabled && music_format != MUSIC_MIDI) { ! if (channel < 0 || channel > CHANNELS) {error = "invalid channel";} ! else if (!channels[channel].ass) {error = "no music on this channel to adjust";} ! else if (vol < 0 || vol > 255) {error = "illegal volume value";} ! else if (pan < 0 || pan > 255) {error = "illegal panning value";} ! else if (speed < 0) {error = "illegal speed value";} ! ! if (error == NULL) { ! voice_set_volume(channels[channel].ass->voice, int(vol * (float(music_vol) / 255.0f))); ! //console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Adjusted channel parameters (%d, %d, %d, %d)", channel, vol, pan, speed); ! } else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Error adjusting channel parameters (%s)", error); ! } ! } ! ! return 0; ! } ! ! /* get_number_of_channels() ! */ ! int l_get_number_of_channels(lua_State *L) ! { ! return putLuaArguments(L, "i", CHANNELS); ! } ! ! ! void poll_sound() ! { ! if (music_format != MUSIC_MIDI) { ! for (int i = 0; i < CHANNELS; i++) { ! if (channels[i].stream) { ! int ret = alogg_update_streaming(channels[i].stream); ! if (ret == 0) { ! // Loop song ! stop_music(i); ! channels[i].stream = alogg_start_streaming(channels[i].filename, BLOCK_SIZE); ! if (!channels[i].stream) { ! fprintf(stderr,"Error opening %s\n", channels[i].filename); ! alogg_exit(); ! exit(1); ! } ! channels[i].ass = alogg_get_audio_stream(channels[i].stream); ! break; ! } ! } ! } ! } ! } ! ! void stop_music(int channel) ! { ! /* ! if (channels[channel].voice) { ! deallocate_voice(channels[channel].voice); ! destroy_sample(channels[channel].sample); ! channels[channel].voice = 0; ! channels[channel].sample = NULL; ! } ! */ ! if (music_format != MUSIC_MIDI && channels[channel].stream) { ! alogg_stop_streaming(channels[channel].stream); ! channels[channel].stream = NULL; ! channels[channel].ass = NULL; ! } ! } ! ! ! /* stop_music(channel) ! */ ! int l_stop_music(lua_State *L) ! { ! int channel; ! getLuaArguments(L, "i", &channel); ! ! error = NULL; ! if (channel < 0 || channel >= CHANNELS) {error = "invalid channel";} ! ! if (error == NULL) { ! stop_music(channel); ! } else { ! console.log(CON_LOG | CON_CONSOLE, CON_ALWAYS, "Error stopping music (%s)", error); ! } ! return 0; ! } ! ! #endif ! ! ! /* play_sample(filename) ! */ ! int l_play_sample(lua_State *L) ! { ! char* name; ! getLuaArguments(L, "s", &name); ! ! if (sfx_enabled) { ! SAMPLE *sample = module->findSample(name); ! ! if (sample) { ! console.log(CON_LOG, CON_ALWAYS, "Playing sample: %s", name); ! play_sample(sample, sfx_vol, 128, 1000, 0); ! } else { ! console.log(CON_LOG, CON_ALWAYS, ! "Error: Cannot find requested sample (%s)!", name); ! } ! } ! ! return 0; ! } ! ! void exit_sound() ! { ! #ifdef ENABLE_MUSIC ! for (int i = 0; i < CHANNELS; i++) { ! stop_music(i); ! } ! ! if (sound_enabled && music_format != MUSIC_MIDI) { ! alogg_exit(); ! } ! #endif ! } Index: sound.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/sound.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** sound.h 23 Oct 2004 11:54:18 -0000 1.8 --- sound.h 7 Feb 2007 17:50:31 -0000 1.9 *************** *** 1,53 **** ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #ifndef _INCLUDED_SOUND_H_ ! #define _INCLUDED_SOUND_H_ ! ! #include <allegro.h> ! #include "script.h" ! ! #ifdef ENABLE_MUSIC ! #include <alogg/alogg.h> ! #endif ! ! ! extern int sound_enabled; ! extern int sfx_enabled; ! extern int sfx_vol; ! extern int music_vol; ! extern int music_format; ! ! #define MUSIC_MIDI 0 ! #define MUSIC_OGG 1 ! ! ! #define CHANNELS (1 << 1) /* (2) number of channels */ ! #define BLOCK_SIZE 40960 ! ! void init_sound(); ! int l_play_sample(lua_State *L); ! void exit_sound(); ! ! void play_music(const char *filename); ! int l_play_music(lua_State *L); ! ! #ifdef ENABLE_MUSIC ! void stop_music(int channel); ! void poll_sound(); ! int l_get_number_of_channels(lua_State *L); ! int l_stop_music(lua_State *L); ! int l_adjust_channel(lua_State *L); ! #endif ! ! ! #endif // #ifndef _INCLUDED_SOUND_H_ ! --- 1,53 ---- ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #ifndef _INCLUDED_SOUND_H_ ! #define _INCLUDED_SOUND_H_ ! ! #include <allegro.h> ! #include "script.h" ! ! #ifdef ENABLE_MUSIC ! #include <alogg/alogg.h> ! #endif ! ! ! extern int sound_enabled; ! extern int sfx_enabled; ! extern int sfx_vol; ! extern int music_vol; ! extern int music_format; ! ! #define MUSIC_MIDI 0 ! #define MUSIC_OGG 1 ! ! ! #define CHANNELS (1 << 1) /* (2) number of channels */ ! #define BLOCK_SIZE 40960 ! ! void init_sound(); ! int l_play_sample(lua_State *L); ! void exit_sound(); ! ! void play_music(const char *filename); ! int l_play_music(lua_State *L); ! ! #ifdef ENABLE_MUSIC ! void stop_music(int channel); ! void poll_sound(); ! int l_get_number_of_channels(lua_State *L); ! int l_stop_music(lua_State *L); ! int l_adjust_channel(lua_State *L); ! #endif ! ! ! #endif // #ifndef _INCLUDED_SOUND_H_ ! Index: script.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/script.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** script.cpp 27 Jan 2007 02:14:47 -0000 1.17 --- script.cpp 7 Feb 2007 17:50:31 -0000 1.18 *************** *** 1,1190 **** ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ [...2351 lines suppressed...] ! } ! else if (strcmp(index, "in_air") == 0) { ! obj->in_air = (int)lua_tonumber(L, -1); ! } ! else if (strcmp(index, "bitmap") == 0) { ! obj->bitmap = (BITMAP*)lua_touserdata(L, -1); ! } ! else if (strcmp(index, "map") == 0) { ! TiledMap* newMap = (TiledMap*)lua_touserdata(L, -1); ! if (newMap != obj->getMap()) obj->setMap(newMap); ! } ! else { ! // Deal with the assigned value normally ! lua_rawset(L, -3); ! } ! } ! ! lua_settop(L, 0); ! return 0; ! } Index: rpg.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/rpg.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** rpg.h 23 Oct 2004 11:54:18 -0000 1.7 --- rpg.h 7 Feb 2007 17:50:31 -0000 1.8 *************** *** 1,48 **** ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #ifndef _INCLUDED_RPG_H_ ! #define _INCLUDED_RPG_H_ ! ! #include "shared/tiled_map.h" ! #include "shared/console.h" ! #include "shared/module.h" ! #include <map> ! #include <allegro.h> ! ! // Some engine settings ! #define PROGRAM_ID "Moonlight RPG engine" ! extern int lps; // Game loops per second - sets the game speed and possible frame rate ! ! ! extern volatile int frames_to_do; ! extern volatile int fps, fps_counter; ! ! extern int inkey; // Last pressed key ! ! extern DATAFILE *interface_graphics; ! extern int gameClassInstance; ! ! extern TileType *selectedTile; ! extern list<TiledMap*> maps; ! ! extern bool game_end; ! extern bool exclusive_mode; ! ! void init_engine(); ! void init_rpg(); ! void init_graphics(); ! void handle_input(); ! void update_screen(); ! void draw_screen(); ! void exit_program(); ! ! #endif --- 1,48 ---- ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #ifndef _INCLUDED_RPG_H_ ! #define _INCLUDED_RPG_H_ ! ! #include "shared/tiled_map.h" ! #include "shared/console.h" ! #include "shared/module.h" ! #include <map> ! #include <allegro.h> ! ! // Some engine settings ! #define PROGRAM_ID "Moonlight RPG engine" ! extern int lps; // Game loops per second - sets the game speed and possible frame rate ! ! ! extern volatile int frames_to_do; ! extern volatile int fps, fps_counter; ! ! extern int inkey; // Last pressed key ! ! extern DATAFILE *interface_graphics; ! extern int gameClassInstance; ! ! extern TileType *selectedTile; ! extern list<TiledMap*> maps; ! ! extern bool game_end; ! extern bool exclusive_mode; ! ! void init_engine(); ! void init_rpg(); ! void init_graphics(); ! void handle_input(); ! void update_screen(); ! void draw_screen(); ! void exit_program(); ! ! #endif |