Skip to content

Commit

Permalink
added audio capabilities (!) but not the actually functionality yet (…
Browse files Browse the repository at this point in the history
…most likely plays a playlist). Sound for NDS comes courtesy of Noda's ASLib, and PC versions use OpenAL and libmad for mp3 decoding. The streamer for PC version is still slightly buggy (when both buffers are done at the same time, OpenAL stops, so I have to restart it after decoding some samples, causing a slight pause). Also changed the loader slightly to accomodate for playlist loading (instead of using the current directory, l-echo looks for the directory of the executable directly; not available fo Mac and NDS right now).
  • Loading branch information
penguin673 committed Dec 5, 2008
1 parent a1bc6a5 commit aa3af9f
Show file tree
Hide file tree
Showing 52 changed files with 12,196 additions and 177 deletions.
26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
CXXFLAGS = -I./ -DSTRICT_MEM -DDEBUG -DTIXML_USE_STL -DUSE_IK -DUSE_PUGIXML -g3 -Wall
#ifeq( $() )
#endif
pugiXML_USE_STL := YES
LINUX_LDFLAGS = -lalut -lmad -lopenal -lGL -lGLU -lglut -lpthread
WINDOWS_LDFLAGS = -lalut -lmad -lopenal glut32.lib -lGL -lGLU
MACOSX_LDFLAGS = -framework OpenGL -framework GLUT -framework OpenAL -arch ppc libmadppc.a -arch i386 libmadi386.a

DEVELOPER_SDK_DIR := /opt/mac/SDKs

CFLAGS := -isysroot /opt/mac/SDKs/MacOSX10.5.sdk
pugiXML_USE_STL := YES
CPPFILES := $(wildcard *.cpp) $(wildcard pugixml/*.cpp)

OFILES := $(CPPFILES:.cpp=.o)
Expand All @@ -26,7 +25,7 @@ UPLOAD := python googlecode_upload.py -p 'l-echo' -s


all: $(OFILES)
gcc pugixml/*.o *.o -lGL -lGLU -lglut -lpthread -g3 -Wall -o l-echo
gcc pugixml/*.o *.o $(LINUX_LDFLAGS) -g3 -Wall -o l-echo

source-tarball:
zip -r $(PKGPREFIX)src.zip *.cpp *.h pugixml/ .svn/ gen/ *.xml* L_ECHO_README Makefile n-echo_template/
Expand All @@ -44,17 +43,22 @@ lab: $(OFILES)
i586-mingw32msvc-g++ $(CXXFLAGS) -c -o $@ $<

w32: $(OBJFILES)
i586-mingw32msvc-g++ pugixml/*.OBJ *.OBJ glut32.lib -lGL -lGLU -g3 -Wall -o l-echo.exe
i586-mingw32msvc-g++ pugixml/*.OBJ *.OBJ $(WINDOWS_LDFLAGS) -g3 -Wall -o l-echo.exe

echo_mp3.DO:
powerpc-apple-darwin8-g++ $(CXXFLAGS) -I /opt/mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenAL.framework/Headers/ -c echo_mp3.cpp -o macbuild/echo_mp3-macppc.DO
i686-apple-darwin8-g++ $(CXXFLAGS) -I /opt/mac/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/OpenAL.framework/Headers/ -c echo_mp3.cpp -o macbuild/echo_mp3-maci386.DO
powerpc-apple-darwin8-lipo -create -arch ppc macbuild/echo_mp3-macppc.DO -arch i386 macbuild/echo_mp3-maci386.DO -output echo_mp3-mac.DO

#%.DO: CXXFLAGS += -isysroot /opt/mac/SDKs/MacOSX10.5.sdk -I/opt/mac/SDKs/MacOSX10.5.sdk/usr/include
%.DO: %.cpp
powerpc-apple-darwin8-g++ -arch i386 -arch ppc $(CXXFLAGS) -c -o $@ $<

mac: $(DOFILES)
powerpc-apple-darwin8-g++ -arch i386 -arch ppc pugixml/*.DO *.DO -framework OpenGL -framework GLUT -g3 -Wall -o l-echo-mac
powerpc-apple-darwin8-g++ $(MACOSX_LDFLAGS) pugixml/*.DO *.DO -g3 -Wall -o l-echo-mac

clean:
rm *.o *.OBJ l-echo.exe l-echo l-echo-mac *.DO *.DOA *~ || echo
rm *.o *.OBJ l-echo.exe l-echo l-echo-mac *.DO *.DOA macbuild/* *~ || echo

clean-all: clean
rm pugixml/*.o pugixml/*.OBJ pugixml/*.DO pugixml/*.DOA || echo
Expand Down Expand Up @@ -83,8 +87,8 @@ package-mac: mac
setup-nds:
cp -r n-echo_template n-echo
cp -t n-echo A*.xml.real
cp -t n-echo/source *.cpp pugixml/*.cpp
cp -t n-echo/include *.h pugixml/*.hpp
cp -t n-echo/arm9/source *.cpp pugixml/*.cpp
cp -t n-echo/arm9/include *.h pugixml/*.hpp

nds:
make -C n-echo
Expand Down
137 changes: 129 additions & 8 deletions echo_ingame_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,149 @@
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_platform.h>
#include <echo_debug.h>
#include <echo_error.h>
#include <echo_stage.h>
#include <echo_loader.h>
#include <echo_ingame_loader.h>

#include <cstdlib>
#include <cstring>
#include <iostream>
#ifdef WIN32
#include <cmath>

#ifdef ECHO_WIN
#include <windows.h>
#endif
//POSIX
#ifdef ARM9
#ifdef ECHO_NDS
#include <sys/dir.h>
#else
#include <dirent.h>
#endif

#ifdef ECHO_PC
#include <libgen.h>
#endif
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <echo_debug.h>
#include <echo_error.h>
#include <echo_stage.h>
#include <echo_loader.h>
#include <echo_ingame_loader.h>
STATUS genroot(char** save)
{
if(save != NULL)
{
*save = new char[2];
CHKPTR(*save);
(*save)[0] = '/';
(*save)[1] = '\0';
return(WIN);
}
return(FAIL);
}

STATUS echo_execdir(char** save)
{
if(save != NULL)
{
#ifdef ECHO_NDS
return(genroot(save));
#elif ECHO_WIN
char exe[MAX_PATH];
GetModuleFileName(NULL, exe, MAX_PATH);
return(echo_parentdir(exe, save));
#elif ECHO_OSX
#else
//copied from l-portable

//step 1: get the directory of this binary
//you can do that on the command line by: readlink /proc/$PID/exe
pid_t pid = getpid();
/*
print it into a string
since pid is an int (in gcc):
length = strlen("/proc//exe") (the other stuff)
+ log(2^(sizeof(int) * 8)) (the number of digits)
+ 1 (for null char)
length = 10 + sizeof(int) * 8 * log(2) + 1
length = 11 + 2.408 * sizeof(int)
ceiling function it just to be sure...
*/
//just curious...
ECHO_PRINT("sizeof int: %i\n", sizeof(int));
//debug print out
const int pid_str_len = (int)ceil(11 + (int)ceil(2.408 * sizeof(int)));
ECHO_PRINT("sizeof pid_str: %i\n", pid_str_len);
char pid_str[pid_str_len];
//and finally print it into the string
sprintf(pid_str, "/proc/%d/exe", pid);
//print out your results
ECHO_PRINT("PID_STR: %s\n", pid_str);
//copied from: https://www.securecoding.cert.org/confluence/display/seccode/POS30-C.+Use+the+readlink()+function+properly
char buf[FILENAME_MAX];
//actually do the readlink, and return the length
ssize_t len = readlink(pid_str, buf, sizeof(buf) - 1);
//if it actully followed the link
if(len != -1)
{
//insert the null char
buf[len] = '\0';
//debug print
ECHO_PRINT("BINARY LOCATION: %s\n", buf);
//return the directory the program is in
return(echo_parentdir(buf, save));
}
else
{
//get the current directory anyways
char* pwd = getenv("PWD");
*save = new char[strlen(pwd) + 1];
CHKPTR(*save);
strcpy(*save, pwd);
return(WIN);
}
#endif
}
return(FAIL);
}

STATUS echo_parentdir(const char* path, char** save)
{
if(path != NULL && save != NULL)
{
#ifdef ECHO_NDS
//if not root
if(strcmp(path, "/"))
{
//index of last '/' character
const int len = strrchr(path, '/') - path;
//not root
if(len > 0)
{
*save = new char[len + 1];
CHKPTR(*save);
//cut off last '/' and after
strncpy(*save, path, len);
return(WIN);
}
}
//if going to root (len == 0), is at root (!strcmp(path, "/")), or error (len < 0), write root anyways
return(genroot(save));
#else
const char* dir = dirname(const_cast<char*>(path));
*save = new char[strlen(dir) + 1];
CHKPTR(*save);
strcpy(*save, dir);
//ECHO_PRINT("save: %s\n", *save);
return(WIN);
#endif
}
return(FAIL);
}

int delete_echo_files(echo_files* files)
STATUS delete_echo_files(echo_files* files)
{
if(files != NULL)
{
Expand All @@ -58,6 +177,8 @@ int delete_echo_files(echo_files* files)
}
delete[] files->file_names;
}
if(files->current_dir != NULL)
delete files->current_dir;
delete files;
return(WIN);
}
Expand Down
7 changes: 6 additions & 1 deletion echo_ingame_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct
} echo_files;
#endif

int delete_echo_files(echo_files* files);
STATUS delete_echo_files(echo_files* files);

#ifndef ARM9
int is_dir(const char* dir, const char* fname);
Expand All @@ -44,3 +44,8 @@ char* echo_merge(const char* arg1, const char* arg2);
int is_dir(echo_files* files, int file_index);
echo_files* get_files(const char* dirname);
void dump_files(echo_files* files);

//get the previous directory
STATUS echo_parentdir(const char* path, char** save);
//get the directory of the executable
STATUS echo_execdir(char** save);
29 changes: 18 additions & 11 deletions echo_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@
*/

#if defined(ARM9) || defined(ARM7)
#define ECHO_NDS 1
#define ECHO_NDS 1
#elif defined(HW_RVL)
#define ECHO_WII 1
#define ECHO_WII 1
#elif defined(HW_DOL)
#define ECHO_GCN 1
#define ECHO_GCN 1
#else
#define ECHO_PC 1
#ifdef __MACH__
#define ECHO_OSX 1
#elif defined(WIN32)
#define ECHO_WIN 1
#else
#define ECHO_UNIX 1
#endif
#define ECHO_PC 1
#ifdef __MACH__
#define ECHO_OSX 1
#ifdef __POWERPC__
#define ECHO_OSX_PPC 1
#elif __i386__
#define ECHO_OSX_I386 1
#else
#error "L-Echo DOES NOT compile on PPC64 or Intel 64! Remove this line in echo_platform.h at your own risk..."
#endif
#elif defined(WIN32)
#define ECHO_WIN 1
#else
#define ECHO_UNIX 1
#endif
#endif

2 changes: 1 addition & 1 deletion echo_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

//void echo_sleep(int millis);
#include <echo_platform.h>

#define FPS 60

Expand Down
Loading

0 comments on commit aa3af9f

Please sign in to comment.