amoeba-1.1.orig/0040755000000000000000000000000007557051243012250 5ustar rootrootamoeba-1.1.orig/test-demolib.cpp0100644000000000000000000000701107502417176015341 0ustar rootroot/* * Can hardly be called a "test program for the demolib" anymore, * as it's been used as the main system for two productions already ;-) */ #define CINTERFACE 1 #include #include #include #include #include #ifdef WIN32 #include #endif #include #ifdef __GNUC__ #include #endif #ifndef M_PI #define M_PI 3.141592653589793238462643383279502 #endif #include "demolib_prefs.h" #include "math/vector.h" #include "main/mainloop.h" #include "main/event.h" #include "main/demohandler.h" #include "main/imagehandler.h" #include "main/fpshandler.h" #include "main/timerhandler.h" #include "main/shadowhandler.h" #include "main/shadowrecthandler.h" #include "main/lighthandler.h" #include "main/fovhandler.h" #include "main/foghandler.h" #include "main/heightmaptunnelhandler.h" #include "main/twisthandler.h" #include "main/particlepathhandler.h" #include "main/camerahandler.h" #include "main/inverthandler.h" #include "main/overlayanimhandler.h" #include "main/backgroundhandler.h" #include "main/uquadshandler.h" #include "main/interferenceheightmaphandler.h" #include "main/fonthandler.h" #include "audio/musichandler.h" #include "image/image.h" #include "opengl/texture.h" //#include "opengl/fpscount.h" #include "exception.h" int main(int argc, char **argv) { #if DEMOLIB_SCREENSAVER /* scan through and check that we do not preview ;-) */ for (int i = 0; i < argc; i++) { if (strcmp(argv[i], "/p") == 0) { exit(0); } } #endif #if !DEMOLIB_SILENT printf("Loading and precalculating...\n"); #endif srand(time(NULL)); try { MainLoop *demo = new MainLoop(argc, argv); File *demoscript = load_file("demo.xml"); demo->add_handler(new HandlerFactory("demo")); demo->add_handler(new HandlerFactory("music")); // demo->add_handler(new HandlerFactory("fpscounter")); // demo->add_handler(new HandlerFactory("timer")); demo->add_handler(new HandlerFactory("image")); demo->add_handler(new HandlerFactory("objmodel")); demo->add_handler(new HandlerFactory("shadow")); demo->add_handler(new HandlerFactory("shadowrect")); demo->add_handler(new HandlerFactory("light")); demo->add_handler(new HandlerFactory("poslight")); demo->add_handler(new HandlerFactory("fov")); demo->add_handler(new HandlerFactory("fog")); demo->add_handler(new HandlerFactory("heightmaptunnel")); demo->add_handler(new HandlerFactory("twist")); demo->add_handler(new HandlerFactory("particlepath")); demo->add_handler(new HandlerFactory("camera")); demo->add_handler(new HandlerFactory("invert")); demo->add_handler(new HandlerFactory("overlayanim")); demo->add_handler(new HandlerFactory("background")); // demo->add_handler(new HandlerFactory("blobs")); demo->add_handler(new HandlerFactory("uquads")); demo->add_handler(new HandlerFactory("interferenceheightmap")); demo->add_handler(new HandlerFactory("text")); demo->parse(demoscript); delete demoscript; demo->run(); delete demo; } catch (Exception *e) { #if __linux__ fprintf(stderr, "Unhandled exception: %s\n", e->get_error()); #else MessageBox(NULL, e->get_error(), "Unhandled exception!", 0); #endif } return 0; } amoeba-1.1.orig/main/0040755000000000000000000000000007557051141013171 5ustar rootrootamoeba-1.1.orig/main/shadowhandler.h0100644000000000000000000000132407474772120016167 0ustar rootroot#ifndef _SHADOWHANDLER_H #define _SHADOWHANDLER_H 1 #include "main/event.h" #include "math/vector.h" #include "main/mainloop.h" #include "packer/file.h" #include "math/array.h" #include "main/objhandler.h" class ShadowHandler : public ObjHandler { public: ShadowHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~ShadowHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: struct extravertexinfo { float a, b, c, d; int neighbours[3]; bool visible; }; GLfloat *shadowvol; Array evi; int do_shadow_pass(const float lx, const float ly, const float lz, GLfloat *shadowvol); }; #endif /* !defined(_SHADOWHANDLER_H) */ amoeba-1.1.orig/main/twisthandler.h0100644000000000000000000000114507470550416016053 0ustar rootroot#ifndef _TWISTHANDLER_H #define _TWISTHANDLER_H 1 #include "main/event.h" #include "main/mainloop.h" #include "main/objhandler.h" #include "math/array.h" class TwistHandler : public ObjHandler { protected: Array orig_vertices; vertex *atan_cache; int *vertex_alias; bool normalspike; struct vertex *spike_vert; struct texcoord *spike_tc; Texture *normalspiketex; public: TwistHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~TwistHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); }; #endif /* !defined(_TWISTHANDLER_H) */ amoeba-1.1.orig/main/fovhandler.cpp0100644000000000000000000000172107407525174016031 0ustar rootroot#include #include #include #ifdef WIN32 #include #endif #include #include "main/fovhandler.h" #include "exception.h" #include "demolib_prefs.h" #ifndef M_PI #define M_PI 3.141592653589793238462643383279502 #endif #if DEMOLIB_MAINLOOP FOVHandler::FOVHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "fov") { this->layer = -900.0f; } FOVHandler::~FOVHandler() { } void FOVHandler::start_effect() {} void FOVHandler::draw_scene(float progress) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(this->get_val("fov", progress), DEMOLIB_XASPECT / DEMOLIB_YASPECT, 1.0f, 500.0f); glMatrixMode(GL_MODELVIEW); } /* reset FOV at end */ void FOVHandler::end_effect() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(53.0f, DEMOLIB_XASPECT / DEMOLIB_YASPECT, 1.0f, 500.0f); glMatrixMode(GL_MODELVIEW); } #endif amoeba-1.1.orig/main/uquadshandler.cpp0100644000000000000000000000712207470307302016531 0ustar rootroot#include #include #ifdef WIN32 #include #endif #include #include #include "math/vector.h" #include "exception.h" #include "uquadshandler.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP UQuadsHandler::UQuadsHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Object(ml, title, elem, attr) { this->xnum = attr->get_int("xnum"); if (this->xnum <= 0) throw new FatalException(elem, "xnum= must be a positive integer!"); this->ynum = attr->get_int("ynum"); if (this->ynum <= 0) throw new FatalException(elem, "ynum= must be a positive integer!"); this->znum = attr->get_int("znum"); if (this->znum <= 0) throw new FatalException(elem, "znum= must be a positive integer!"); this->xspace = attr->get_float("xspace"); this->yspace = attr->get_float("yspace"); this->zspace = attr->get_float("zspace"); this->xstrength = attr->get_float("xstrength"); this->ystrength = attr->get_float("ystrength"); this->zstrength = attr->get_float("zstrength"); this->no_zbuffer = true; for (int i = 0; i < xnum * ynum * znum; i++) { struct vertex v; v.x = v.y = v.z = 0.0f; this->vertices.add_end(v); this->vertices.add_end(v); this->vertices.add_end(v); this->vertices.add_end(v); struct texcoord tc; tc.u = 0.0f; tc.v = 0.0f; this->texcoords.add_end(tc); tc.u = 1.0f; tc.v = 0.0f; this->texcoords.add_end(tc); tc.u = 1.0f; tc.v = 1.0f; this->texcoords.add_end(tc); tc.u = 0.0f; tc.v = 1.0f; this->texcoords.add_end(tc); struct normal n; n.nx = 0.0f; n.ny = 1.0f; n.nz = 0.0f; this->normals.add_end(n); this->normals.add_end(n); this->normals.add_end(n); this->normals.add_end(n); this->faces.add_end(i * 4); this->faces.add_end(i * 4 + 1); this->faces.add_end(i * 4 + 2); this->faces.add_end(i * 4 + 3); } this->vertices_per_face = 4; this->pure_indices = true; } UQuadsHandler::~UQuadsHandler() { } void UQuadsHandler::start_effect() { Object::start_effect(); } void UQuadsHandler::draw_scene(float progress) { float xfreq = this->get_val("user1", progress); float yfreq = this->get_val("user2", progress); float zfreq = this->get_val("user3", progress); float prog = this->get_val("user4", progress); this->unlock_object(); for (int i = 0; i < this->xnum; i++) { int ci = i - xnum/2; const float x = (xspace + sin((float)ci * xfreq + prog) * xstrength) * ci; for (int j = 0; j < this->ynum; j++) { int cj = j - ynum/2; const float y = (yspace + sin((float)cj * yfreq + prog) * ystrength) * cj; for (int k = 0; k < this->znum; k++) { int ck = k - znum/2; const float z = (zspace + sin((float)ck * zfreq + prog) * zstrength) * ck; this->vertices[(k + (j + i * ynum) * znum) * 4 ].x = x - 0.5f; this->vertices[(k + (j + i * ynum) * znum) * 4 ].y = y; this->vertices[(k + (j + i * ynum) * znum) * 4 ].z = z + 0.5f; this->vertices[(k + (j + i * ynum) * znum) * 4 + 1].x = x + 0.5f; this->vertices[(k + (j + i * ynum) * znum) * 4 + 1].y = y; this->vertices[(k + (j + i * ynum) * znum) * 4 + 1].z = z + 0.5f; this->vertices[(k + (j + i * ynum) * znum) * 4 + 2].x = x + 0.5f; this->vertices[(k + (j + i * ynum) * znum) * 4 + 2].y = y; this->vertices[(k + (j + i * ynum) * znum) * 4 + 2].z = z - 0.5f; this->vertices[(k + (j + i * ynum) * znum) * 4 + 3].x = x - 0.5f; this->vertices[(k + (j + i * ynum) * znum) * 4 + 3].y = y; this->vertices[(k + (j + i * ynum) * znum) * 4 + 3].z = z - 0.5f; } } } Object::draw_scene(progress); } void UQuadsHandler::end_effect() { Object::end_effect(); } #endif amoeba-1.1.orig/main/foghandler.h0100644000000000000000000000057307407525174015463 0ustar rootroot#ifndef _FOGHANDLER_H #define _FOGHANDLER_H #include "main/event.h" #include "math/vector.h" #include "opengl/texture.h" class FogHandler : public Event { public: FogHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~FogHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); }; #endif /* defined(_FOGHANDLER_H) */ amoeba-1.1.orig/main/Makefile0100644000000000000000000000221207502417124014620 0ustar rootroot# Main loop MAIN_OBJS = main/mainloop.o main/demohandler.o \ main/event.o main/factory.o \ main/curve.o main/linearcurve.o main/autosplinecurve.o main/linecurve.o main/piprecalc.o # Misc. 2D "effects" MAIN_OBJS += main/imagehandler.o main/inverthandler.o main/overlayanimhandler.o main/backgroundhandler.o main/fonthandler.o # Loaded 3D models MAIN_OBJS += main/object.o main/objhandler.o # 3D model deformations MAIN_OBJS += main/shadowhandler.o main/shadowrecthandler.o \ main/twisthandler.o main/uquadshandler.o # 3D-effects and -handlers MAIN_OBJS += main/lighthandler.o \ main/fovhandler.o \ main/foghandler.o \ main/camerahandler.o \ main/heightmaptunnelhandler.o \ main/particlepathhandler.o \ main/interferenceheightmaphandler.o # Debugging stuff MAIN_OBJS += main/fpshandler.o main/timerhandler.o ifeq ($(DESTPLATFORM),linux) MAIN_OBJS += main/linux-config/linux-config.o else # the resource file is included in the top-level Makefile MAIN_OBJS += main/win32-config/win32-config.o endif # --- OBJS += $(MAIN_OBJS) SUBLIBS += main/main.a main/main.a: $(MAIN_OBJS) $(AR) rc main/main.a $(MAIN_OBJS) $(RANLIB) main/main.a amoeba-1.1.orig/main/fonthandler.cpp0100644000000000000000000000413407477516562016216 0ustar rootroot#include #include #include #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP && DEMOLIB_OPENGL_FONT_TTF #include "main/fonthandler.h" #include "opengl/fontttf.h" #include "exception.h" FontHandler::FontHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "xpos:ypos:red:green:blue:alpha") { int size; if (attr->exists("size")) { size = attr->get_int("size"); } else { size = 24; } if (attr->exists("linedistance")) { this->linedistance = attr->get_float("linedistance"); } else { this->linedistance = 0.15f; } this->fontfile = load_file(attr->get_str("font")); this->additive_blend = false; if (attr->exists("blend")) { char *str = attr->get_str("blend"); if (strcmp(str, "blend") == 0) { this->additive_blend = false; } else if (strcmp(str, "add") == 0) { this->additive_blend = true; } else { throw new FatalException(elem, "blend= must be `blend' or `add'!"); } } this->num_lines = 0; /* parse into nice parts ;-) */ char *text = strdup(attr->get_str("text")); char *ptr = strtok(text, "|"); while (ptr) { this->font[this->num_lines++] = new FontTTF(fontfile, ptr, size); ptr = strtok(NULL, "|"); } free(text); } FontHandler::~FontHandler() { for (int i = 0; i < this->num_lines; i++) { delete this->font[i]; this->font[i] = NULL; } delete this->fontfile; this->fontfile = NULL; } void FontHandler::start_effect() {} void FontHandler::draw_scene(float progress) { for (int i = 0; i < this->num_lines; i++) { font[i]->draw_object(this->get_val("xpos", progress), this->get_val("ypos", progress) + this->linedistance * i, this->get_val("red", progress), this->get_val("green", progress), this->get_val("blue", progress), this->get_val("alpha", progress), this->additive_blend); } } void FontHandler::end_effect() {} #endif /* DEMOLIB_MAINLOOP && DEMOLIB_OPENGL_FONT_TTF */ amoeba-1.1.orig/main/demohandler.cpp0100644000000000000000000000523307476421062016162 0ustar rootroot#include #include #include #ifdef __linux__ #include #endif #include "main/demohandler.h" #include "opengl/glwindow.h" #include "../exception.h" #include "../demolib_prefs.h" #if DEMOLIB_MAINLOOP DemoHandler::DemoHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, NULL) { this->ml = ml; this->layer = -1000.0f; bool fullscreen = attr->get_bool("fullscreen"); /* * It's extremely important that this comes HERE and not in * start_effect()! Otherwise, other constructors doing OpenGL * commands (textures, for instance) would fail and mess * everything up quite badly... */ int xres = attr->get_int("xres"); int yres = attr->get_int("yres"); if (attr->exists("visual_id")) { this->win = new GLWindow(this->title, xres, yres, -1, fullscreen, -1, attr->get_int("visual_id")); return; } int bpp = attr->get_int("depth"); int zbpp = attr->get_int("zbuffer"); this->win = new GLWindow(this->title, xres, yres, bpp, fullscreen, zbpp, -1); } DemoHandler::~DemoHandler() { delete this->win; this->win = NULL; } void DemoHandler::start_effect() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glDepthFunc(GL_LESS); while (this->active) { #ifdef __linux__ /* * Linux doesn't use a message queue like Win32, so we'll * handle X events here :-) */ while (XPending(this->win->dpy) > 0) { XEvent event; XNextEvent(this->win->dpy, &event); switch (event.type) { case ConfigureNotify: if ((event.xconfigure.width != (signed int)this->win->width) || (event.xconfigure.height != (signed int)this->win->height)) { this->win->width = event.xconfigure.width; this->win->height = event.xconfigure.height; this->win->resize(0, 0, this->win->width, this->win->height); } break; case ButtonPress: this->win->done = true; break; case KeyPress: if (XLookupKeysym(&event.xkey, 0) == XK_Escape) { this->win->done = true; } break; } } #endif this->ml->run(false); this->win->flip(); if (this->win->is_done()) { this->end_effect(); } } } void DemoHandler::draw_scene(float progress) { } void DemoHandler::end_effect() { this->active = false; /* end everything, MainLoop will clean it up */ for (int i = 0; i < this->ml->num_events; i++) { Event *e = this->ml->events[i]; if (e && e->active && e != this) { #if !DEMOLIB_SILENT printf("Exiting: %s\n", e->title); #endif e->end_effect(); e->active = false; } } } #endif amoeba-1.1.orig/main/camerahandler.h0100644000000000000000000000057007411741746016135 0ustar rootroot#ifndef _CAMERAHANDLER_H #define _CAMERAHANDLER_H 1 #include "main/event.h" class CameraHandler : public Event { protected: float gravity; public: CameraHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~CameraHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); }; #endif /* !defined(_CAMERAHANDLER_H) */ amoeba-1.1.orig/main/curve.h0100644000000000000000000000106207441453746014473 0ustar rootroot#ifndef _CURVE_H #define _CURVE_H #define CURVE_NONE -1 #define CURVE_LINEAR 1 #define CURVE_AUTOSPLINE 3 #define CURVE_LINE 4 #define MAX_POINTS 4096 class CurveDebugger; class Curve { public: Curve(); virtual ~Curve(); virtual void add_curvepoint(float x, float y) = 0; virtual void end_curvepoints(float start, float length) = 0; virtual float get_value(float x) = 0; virtual int get_curvetype() = 0; friend class CurveDebugger; protected: float x[MAX_POINTS], y[MAX_POINTS]; int num_points; }; #endif /* !defined(_CURVE_H) */ amoeba-1.1.orig/main/particlepathhandler.cpp0100644000000000000000000002566707474453602017736 0ustar rootroot#include #include #include #include #ifdef WIN32 #include #endif #include #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 #endif #include #include "main/curve.h" #include "main/linecurve.h" #include "math/matrix.h" #include "opengl/extensions.h" #include "exception.h" #include "particlepathhandler.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP class z_compare { public: bool operator() (const struct particle_sort &a, const struct particle_sort &b) { return (a.z < b.z); } }; ParticlePathHandler::ParticlePathHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "x:y:z:alpha") { this->size = attr->get_float("size"); this->speed = attr->get_float("speed"); this->radius = attr->get_float("radius"); this->headstart = 1.0f; if (attr->exists("headstart")) { this->headstart = attr->get_float("headstart"); if (this->headstart < 0.0f || this->headstart > 1.0f) { throw new FatalException(elem, "headstart= must be between 0 and 1!"); } } this->uniform = false; if (attr->exists("uniform")) { this->uniform = attr->get_bool("uniform"); } this->streamlength = -1.0f; if (attr->exists("streamlength")) { this->streamlength = attr->get_float("streamlength"); } this->tex = texture::load(attr->get_str("texture")); this->num_particles = attr->get_int("numparticles"); this->particles = new particle[num_particles]; this->vert = new vertex[num_particles * 4]; this->tc = new texcoord[num_particles * 4]; this->particle_sortdata = new particle_sort[num_particles]; if (this->uniform) { float step = 1.0f / (float)(num_particles - 1); float t = 0.0f; for (int i = 0; i < num_particles; i++, t += step) { this->spawn_particle(i, t - 1.0f + headstart); this->tc[i * 4 ].u = 0.0f; this->tc[i * 4 ].v = 0.0f; this->tc[i * 4 + 1].u = 1.0f; this->tc[i * 4 + 1].v = 0.0f; this->tc[i * 4 + 2].u = 1.0f; this->tc[i * 4 + 2].v = 1.0f; this->tc[i * 4 + 3].u = 0.0f; this->tc[i * 4 + 3].v = 1.0f; /* make sure the stream is of right length */ if (t < 1.0f - this->streamlength && this->streamlength != -1.0f) { particles[i].progress = -1000.0f; } } } else { srand(time(NULL)); for (int i = 0; i < num_particles; i++) { this->spawn_particle(i, 1.0f*rand()/(RAND_MAX+1.0) - 1.0f + headstart); this->tc[i * 4 ].u = 0.0f; this->tc[i * 4 ].v = 0.0f; this->tc[i * 4 + 1].u = 1.0f; this->tc[i * 4 + 1].v = 0.0f; this->tc[i * 4 + 2].u = 1.0f; this->tc[i * 4 + 2].v = 1.0f; this->tc[i * 4 + 3].u = 0.0f; this->tc[i * 4 + 3].v = 1.0f; } } this->last_progress = 0.0f; if (GLExtensions::has_ext("GL_EXT_compiled_vertex_array")) { this->has_compiled_vertex_array = true; this->glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC) GLExtensions::func_ptr("glLockArraysEXT"); this->glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC) GLExtensions::func_ptr("glUnlockArraysEXT"); } else { this->has_compiled_vertex_array = false; } } ParticlePathHandler::~ParticlePathHandler() { texture::free(this->tex); this->tex = NULL; delete[] this->particles; this->particles = NULL; delete[] this->particle_sortdata; this->particle_sortdata = NULL; delete[] this->vert; this->vert = NULL; delete[] this->tc; this->tc = NULL; } void ParticlePathHandler::start_effect() { } void ParticlePathHandler::draw_scene(float progress) { /* * move all particles, spawn new ones if needed */ int i; for (i = 0; i < num_particles; i++) { particles[i].progress += (progress - last_progress) * speed; if (particles[i].progress > 1.0f) { if (progress > this->streamlength && this->streamlength != -1.0f) { /* never again a particle here :-) */ particles[i].progress = -1000.0f; } else { this->spawn_particle(i, fmod(particles[i].progress, 1.0f)); } } } this->last_progress = progress; /* * set OpenGL state and find the matrix, use it to create an opposite * billboarding matrix */ glMatrixMode(GL_MODELVIEW); glPushMatrix(); glEnable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glEnable(GL_CULL_FACE); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glColor4f(1.0f, 1.0f, 1.0f, this->get_val("alpha", progress)); glEnable(GL_TEXTURE_2D); tex->bind(); GLfloat mat[16]; glGetFloatv(GL_MODELVIEW_MATRIX, mat); Matrix tmat(mat); /* * since we're going to have a LOT of curve lookups, we "cache" * so we don't have to query the hashtable every time */ Curve *x = (Curve *)this->curves->lookup("x"); Curve *y = (Curve *)this->curves->lookup("y"); Curve *z = (Curve *)this->curves->lookup("z"); /* generate the billboarding */ struct vertex ul, ll, lr, ur; ul.x = (-tmat.matrix[0][0] - tmat.matrix[1][0]) * size; ul.y = (-tmat.matrix[0][1] - tmat.matrix[1][1]) * size; ul.z = (-tmat.matrix[0][2] - tmat.matrix[1][2]) * size; ll.x = ( tmat.matrix[0][0] - tmat.matrix[1][0]) * size; ll.y = ( tmat.matrix[0][1] - tmat.matrix[1][1]) * size; ll.z = ( tmat.matrix[0][2] - tmat.matrix[1][2]) * size; lr.x = ( tmat.matrix[0][0] + tmat.matrix[1][0]) * size; lr.y = ( tmat.matrix[0][1] + tmat.matrix[1][1]) * size; lr.z = ( tmat.matrix[0][2] + tmat.matrix[1][2]) * size; ur.x = (-tmat.matrix[0][0] + tmat.matrix[1][0]) * size; ur.y = (-tmat.matrix[0][1] + tmat.matrix[1][1]) * size; ur.z = (-tmat.matrix[0][2] + tmat.matrix[1][2]) * size; /* whatever you do, DON'T use this direction ;-) */ Vector up(0.2538f, 0.19f, -0.38f); /* * do a very specific optimization trick (ie. drop curve overhead * altogether and reduce the CPU load a LOT) if we deal with simple * line curves (curve="line") */ if (x->get_curvetype() == CURVE_LINE && y->get_curvetype() == CURVE_LINE && z->get_curvetype() == CURVE_LINE) { const float xb = ((LineCurve *)x)->base; const float yb = ((LineCurve *)y)->base; const float zb = ((LineCurve *)z)->base; const float xs = ((LineCurve *)x)->step; const float ys = ((LineCurve *)y)->step; const float zs = ((LineCurve *)z)->step; Vector deriv(xs, ys, zs); /* whatever you do, DON'T use this direction ;-) */ Vector up(0.2538f, 0.19f, -0.38f); Vector local_right = up.cross_product(deriv).normalize(); Vector local_up = local_right.cross_product(deriv).normalize(); for (i = 0; i < num_particles; i++) { /* * a massively simplified version of find_rot_from_deriv * from tunnelhandler.cpp ;-) */ const float t = particles[i].progress; if (t < 0.0f) { this->particle_sortdata[i].z = 0.0f; // invalid z value continue; } const float rot_sin = particles[i].angle_sin; const float rot_cos = particles[i].angle_cos; const float x = xb + xs * t + local_right.x * rot_cos + local_up.x * rot_sin; const float y = yb + ys * t + local_right.y * rot_cos + local_up.y * rot_sin; const float z = zb + zs * t + local_right.z * rot_cos + local_up.z * rot_sin; /* generate a Z index */ this->particle_sortdata[i].num = i; this->particle_sortdata[i].z = x * tmat.matrix[2][0] + y * tmat.matrix[2][1] + z * tmat.matrix[2][2]; vert[i * 4 ].x = x + ul.x; vert[i * 4 ].y = y + ul.y; vert[i * 4 ].z = z + ul.z; vert[i * 4 + 1].x = x + ll.x; vert[i * 4 + 1].y = y + ll.y; vert[i * 4 + 1].z = z + ll.z; vert[i * 4 + 2].x = x + lr.x; vert[i * 4 + 2].y = y + lr.y; vert[i * 4 + 2].z = z + lr.z; vert[i * 4 + 3].x = x + ur.x; vert[i * 4 + 3].y = y + ur.y; vert[i * 4 + 3].z = z + ur.z; } } else { /* okay, slow way... calculate the particles one by one */ for (i = 0; i < num_particles; i++) { /* * a massively simplified version of find_rot_from_deriv * from tunnelhandler.cpp ;-) */ const float t = particles[i].progress; if (t < 0.0f) { this->particle_sortdata[i].z = 0.0f; // invalid z value continue; } const float xn = x->get_value(t); const float yn = y->get_value(t); const float zn = z->get_value(t); const float xd = x->get_value(t + 0.0001f) - xn; const float yd = y->get_value(t + 0.0001f) - yn; const float zd = z->get_value(t + 0.0001f) - zn; Vector deriv(xd, yd, zd); Vector local_right = up.cross_product(deriv).normalize(); Vector local_up = local_right.cross_product(deriv).normalize(); /* * would be a faster version of sin(atan2(xd, zd))... but what * about the minus? ;-) */ /* const float hyp = 1.0f / hypot(xd, zd); const float sin_atan_ry = xd * hyp; const float cos_atan_ry = zd * hyp; */ const float rot_sin = particles[i].angle_sin; const float rot_cos = particles[i].angle_cos; const float x = xn + local_right.x * rot_cos + local_up.x * rot_sin; const float y = yn + local_right.y * rot_cos + local_up.y * rot_sin; const float z = zn + local_right.z * rot_cos + local_up.z * rot_sin; /* generate a Z index */ this->particle_sortdata[i].num = i; this->particle_sortdata[i].z = x * tmat.matrix[2][0] + y * tmat.matrix[2][1] + z * tmat.matrix[2][2]; vert[i * 4 ].x = x + ul.x; vert[i * 4 ].y = y + ul.y; vert[i * 4 ].z = z + ul.z; vert[i * 4 + 1].x = x + ll.x; vert[i * 4 + 1].y = y + ll.y; vert[i * 4 + 1].z = z + ll.z; vert[i * 4 + 2].x = x + lr.x; vert[i * 4 + 2].y = y + lr.y; vert[i * 4 + 2].z = z + lr.z; vert[i * 4 + 3].x = x + ur.x; vert[i * 4 + 3].y = y + ur.y; vert[i * 4 + 3].z = z + ur.z; } } /* Z sort */ std::sort(&this->particle_sortdata[0], &this->particle_sortdata[num_particles - 1], z_compare()); /* qsort(this->particle_sortdata, num_particles, sizeof(struct particle_sort), z_compare); */ glVertexPointer(3, GL_FLOAT, 0, vert); glTexCoordPointer(2, GL_FLOAT, 0, tc); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); if (this->has_compiled_vertex_array) (*this->glLockArraysEXT)(0, num_particles * 4); /* probably better than messing about with a new temp array */ glBegin(GL_QUADS); for (i = 0; i < num_particles; i++) { if (this->particle_sortdata[i].z == 0.0f) continue; for (int j = 0; j < 4; j++) { glArrayElement(this->particle_sortdata[i].num * 4 + j); } } glEnd(); if (this->has_compiled_vertex_array) (*this->glUnlockArraysEXT)(); glEnable(GL_LIGHTING); glDepthMask(GL_TRUE); glPopMatrix(); } void ParticlePathHandler::end_effect() {} void ParticlePathHandler::spawn_particle(int i, float progress) { const float angle = 2.0f * M_PI * rand() / (RAND_MAX+1.0); const float radius = this->radius * M_PI * rand() / (RAND_MAX+1.0); particles[i].progress = progress; particles[i].angle_sin = sin(angle) * radius; particles[i].angle_cos = cos(angle) * radius; } #endif amoeba-1.1.orig/main/factory.h0100644000000000000000000000314307407525174015015 0ustar rootroot#ifndef _FACTORY_H #define _FACTORY_H #include #include "main/mainloop.h" #include "util/hashtable.h" class Event; class MainLoop; class Factory { public: Factory(); virtual ~Factory(); virtual bool can_handle(const char *el) = 0; virtual Event *instantiate(MainLoop *ml, const char *title, const char *el, Hashtable *attr) = 0; virtual char *get_short_effectname() = 0; virtual char *get_long_effectname() = 0; virtual char *get_display_parameter() = 0; }; template class HandlerFactory : public Factory { private: char *elem, *longdesc, *mainparm; public: HandlerFactory(char *element) { this->elem = strdup(element); this->longdesc = NULL; this->mainparm = NULL; } HandlerFactory(char *element, char *longdesc) { this->elem = strdup(element); this->longdesc = strdup(longdesc); this->mainparm = NULL; } HandlerFactory(char *element, char *longdesc, char *mainparm) { this->elem = strdup(element); this->longdesc = strdup(longdesc); this->mainparm = strdup(mainparm); } ~HandlerFactory() { free(this->elem); this->elem = NULL; free(this->longdesc); this->longdesc = NULL; free(this->mainparm); this->mainparm = NULL; } bool can_handle(const char *el) { return (strcmp(this->elem, el) == 0); } Event *instantiate(MainLoop *ml, const char *title, const char *el, Hashtable *attr) { return new E(ml, title, el, attr); } char *get_short_effectname() { return this->elem; } char *get_long_effectname() { return this->longdesc; } char *get_display_parameter() { return this->mainparm; } }; #endif /* !defined(_FACTORY_H) */ amoeba-1.1.orig/main/heightmaptunnelhandler.cpp0100644000000000000000000001016307471744720020434 0ustar rootroot/* * More or less equal to the interference heightmap, except that it's wrapped around * a circle instead of on a plane. :-) */ #include #include #include #include #ifdef WIN32 #include #endif #include #ifndef M_PI #define M_PI 3.14159265358979323846264 #endif #include "main/heightmaptunnelhandler.h" #include "math/vector.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP HeightmapTunnelHandler::HeightmapTunnelHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Object(ml, title, elem, attr) { this->xlod = attr->get_int("xlod"); this->ylod = attr->get_int("ylod"); this->speedlin = attr->get_float("speedlin"); this->freqlinx = attr->get_float("freqlinx"); this->freqliny = attr->get_float("freqliny"); this->ampllin = attr->get_float("ampllin"); this->speedcirc = attr->get_float("speedcirc"); this->freqcirc = attr->get_float("freqcirc"); this->amplcirc = attr->get_float("amplcirc"); this->pure_indices = true; this->vertices_per_face = 4; float xradscale = 2.0f * M_PI / (float)(xlod); float xscale = 1.0f / (float)xlod; float yscale = 1.0f / (float)ylod; int x, y; float xf, xrf, yf; for (y = 0, yf = -0.5f; y < ylod; y++, yf += yscale) { for (x = 0, xrf = 0.0f, xf = 0.0f; x < xlod; x++, xf += xscale, xrf += xradscale) { struct vertex v = { cos(xrf) * 10.0f, sin(xrf) * 10.0f, yf * 100.0f }; struct texcoord t = { xf, yf + 0.5f }; struct normal n = { 0.0f, 1.0f, 0.0f }; this->vertices.add_end(v); this->texcoords.add_end(t); this->normals.add_end(n); } } for (y = 0; y < ylod-1; y++) { for (x = 0; x < xlod-1; x++) { this->faces.add_end(y*xlod + x); this->faces.add_end((y+1)*xlod + x); this->faces.add_end((y+1)*xlod + ((x+1)%xlod)); this->faces.add_end(y*ylod + ((x+1)%xlod)); } } } HeightmapTunnelHandler::~HeightmapTunnelHandler() { } void HeightmapTunnelHandler::start_effect() { Object::start_effect(); } void HeightmapTunnelHandler::draw_scene(float progress) { this->unlock_object(); float u1 = this->get_val("user1", progress); float u2 = this->get_val("user2", progress); float u3 = this->get_val("user3", progress); float u4 = this->get_val("user4", progress); float xscale = 1.0f / (float)(xlod-1); float yscale = 1.0f / (float)ylod; float xscale2 = freqlinx * xscale; float yscale2 = freqliny * yscale; const float p_sl = progress * speedlin; const float flx_al = freqlinx * ampllin; const float fly_al = freqliny * ampllin; float xf = -u3, xfs = 0.0f; for (int x = 0; x < xlod; x++, xf += xscale, xfs += xscale2) { const float xxf = xf * 2.0f * M_PI; const float xwrap = sin(xxf); const float xwrap2 = sin(xfs * 2.0f * M_PI); const float cosrot = cos(xxf); const float sinrot = sin(xxf); float yf = -u4, yfs = 0.0f; for (int y = 0; y < ylod; y++, yf += yscale, yfs += yscale2) { /* copied more or less directly from interferenceheightmaphandler.cpp :-) */ const float dist = hypot(xwrap, yf); #if __GNUC__ float sin_v, cos_v; __asm__("fsincos" : "=t" (cos_v), "=u" (sin_v) : "0" (dist * freqcirc + progress * speedcirc)); #else const float temp = dist * freqcirc + progress * speedcirc; const float sin_v = sin(temp); const float cos_v = cos(temp); #endif const float divval = freqcirc * amplcirc / dist; const float z = sin_v * amplcirc + (sin(xwrap2 + p_sl + u1) + sin(yfs + p_sl + u2)) * ampllin; const float dx = cos_v * xwrap * divval + flx_al * cos(xwrap2 + p_sl + u1); const float dy = cos_v * yf * divval + fly_al * cos(yfs + p_sl + u2); Vector normal(dx * -0.2f, dy * -0.2f, 1.0f); normal.normalize(); vertices[y * xlod + x].x = cosrot * (10.0f - z * 2.0f); vertices[y * xlod + x].y = sinrot * (10.0f - z * 2.0f); /* also rotate the normal */ normals[y * xlod + x].nx = normal.x * cosrot + normal.y * sinrot; normals[y * xlod + x].ny = normal.x * -sinrot + normal.y * cosrot; normals[y * xlod + x].nz = normal.z; } } Object::draw_scene(progress); } void HeightmapTunnelHandler::end_effect() { Object::end_effect(); } #endif /* DEMOLIB_MAINLOOP */ amoeba-1.1.orig/main/shadowrecthandler.h0100644000000000000000000000061707443745036017053 0ustar rootroot#ifndef _SHADOWRECTHANDLER_H #define _SHADOWRECTHANDLER_H 1 #include "main/event.h" #include "main/mainloop.h" class ShadowRectHandler : public Event { public: ShadowRectHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~ShadowRectHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); }; #endif /* !defined(_SHADOWRECTHANDLER_H) */ amoeba-1.1.orig/main/mainloop.h0100644000000000000000000000224207477153072015164 0ustar rootroot#ifndef _MAINLOOP_H #define _MAINLOOP_H #if WIN32 #include #endif #include #include "main/event.h" #include "main/factory.h" #include "main/piprecalc.h" #include "packer/file.h" #include "opengl/glwindow.h" #include "util/hashtable.h" class Factory; class MusicHandler; class DirectSoundAudioDriver; class MainLoop { public: int next_evnum; MainLoop(int argc, char **argv); ~MainLoop(); void parse(File *demoscript); void add_handler(Factory *handler_factory); void process_element(const char *el, const char **attr); float get_time(); void run(); void run(bool infloop); /* ick */ Event **events; int num_events; Event *curr_event; Event *evlist[256]; int num_play_events; XML_Parser p; friend class MusicHandler; friend class DirectSoundAudioDriver; protected: void parse_commandline(int argc, char **argv, Hashtable *attr_hash); Factory **factories; int num_factories; Hashtable *markers; MusicHandler *timer; int argc; char **argv; GLWindow *win; bool sound; PiPrecalc *precalc; #ifdef WIN32 LARGE_INTEGER tmstart, tmfreq; #else struct timeval tmstart; #endif }; #endif /* defined(_MAINLOOP_H) */ amoeba-1.1.orig/main/backgroundhandler.h0100644000000000000000000000113007477163766017031 0ustar rootroot#ifndef _BACKGROUNDHANDLER_H #define _BACKGROUNDHANDLER_H #define GL_TEXTURE_RECTANGLE_NV 0x84F5 #include "main/event.h" #include "image/image.h" class BackgroundHandler : public Event { public: BackgroundHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~BackgroundHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: GLuint *textures; int xres, yres; int xpartbits[30], ypartbits[30]; int xparts, yparts; int xoffs, yoffs; int screenwidth, screenheight; }; #endif /* defined(_BACKGROUNDHANDLER_H) */ amoeba-1.1.orig/main/uquadshandler.h0100644000000000000000000000103307470272462016201 0ustar rootroot#ifndef _UPLANESHANDLER_H #define _UPLANESHANDLER_H 1 #include "main/event.h" #include "main/mainloop.h" #include "main/objhandler.h" #include "math/array.h" class UQuadsHandler : public Object { protected: int xnum, ynum, znum; float xspace, yspace, zspace; float xstrength, ystrength, zstrength; public: UQuadsHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~UQuadsHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); }; #endif /* !defined(_UPLANESHANDLER_H) */ amoeba-1.1.orig/main/objhandler.h0100644000000000000000000000132307407525174015454 0ustar rootroot#ifndef _OBJHANDLER_H #define _OBJHANDLER_H 1 #include "main/event.h" #include "main/mainloop.h" #include "packer/file.h" #include "main/object.h" #include "math/array.h" class ObjHandler : public Object { protected: void split_lines(char *data); void parse_line(char *data); void parse_vertex(char *data); void parse_texcoords(char *data); void parse_normals(char *data); void parse_faces(char *data); Array temp_texcoords; Array temp_normals; public: ObjHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~ObjHandler(); virtual void start_effect(); virtual void draw_scene(float progress); virtual void end_effect(); }; #endif /* !defined(_OBJHANDLER_H) */ amoeba-1.1.orig/main/imagehandler.h0100644000000000000000000000061107407525174015763 0ustar rootroot#ifndef _IMAGEHANDLER_H #define _IMAGEHANDLER_H #include "main/event.h" #include "opengl/texture.h" class ImageHandler : public Event { public: ImageHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~ImageHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: Texture *tex; }; #endif /* defined(_IMAGEHANDLER_H) */ amoeba-1.1.orig/main/mainloop.cpp0100644000000000000000000004215707502372020015511 0ustar rootroot#include #include #include #ifdef __GNUC__ #include #endif #include #ifdef WIN32 #include #include "main/win32-config/win32-config.h" #else #include #include "main/linux-config/linux-config.h" #endif #include "main/mainloop.h" #include "main/factory.h" #include "main/demohandler.h" #include "audio/musichandler.h" #include "exception.h" #include "demolib_prefs.h" #include #if DEMOLIB_MAINLOOP void start_ml(void *data, const char *el, const char **attr) { MainLoop *ml = (MainLoop *)data; ml->process_element(el, attr); } void end_ml(void *data, const char *el) { MainLoop *ml = (MainLoop *)data; /* this is a brief hack, but it's OK */ if (strcmp(el, "demo") == 0) { if (ml->events[0]->stop == -1.0f) ml->events[0]->stop = ml->events[ml->num_events - 1]->stop; return; } if (strcmp(el, "start") == 0 || strcmp(el, "point") == 0 || strcmp(el, "end") == 0 || strcmp(el, "demo") == 0 || strcmp(el, "music") == 0 || strcmp(el, "marker") == 0 || strcmp(el, "lpp") == 0) return; try { ml->curr_event->end_curvedata(); ml->curr_event = NULL; } catch (FatalException *e) { char buf[256]; sprintf(buf, "Error at line %d of demo script: %s", XML_GetCurrentLineNumber(ml->p), e->get_error()); throw new FatalException(buf); } } MainLoop::MainLoop(int argc, char **argv) { this->next_evnum = 0; this->events = (Event **)(malloc(sizeof(Event *) * 256)); this->num_events = 0; this->factories = (Factory **)(malloc(sizeof(Factory *) * 256)); this->num_factories = 0; this->markers = new Hashtable(); this->timer = NULL; this->argc = argc; this->argv = argv; this->sound = true; this->precalc = NULL; } void MainLoop::parse(File *demoscript) { this->p = XML_ParserCreate(NULL); XML_SetUserData(p, this); XML_SetElementHandler(p, start_ml, end_ml); bool status; try { status = XML_Parse(p, demoscript->get_data(), demoscript->data_length(), 1); } catch (ValueNotSpecifiedException *nve) { char buf[256]; sprintf(buf, "Error at line %d of demo script: Parameter `%s=' missing", XML_GetCurrentLineNumber(p), nve->get_error()); throw new FatalException(buf); } if (!status) { char buf[512]; sprintf(buf, "Parse error at line %d of demo script: %s", XML_GetCurrentLineNumber(p), XML_ErrorString(XML_GetErrorCode(p))); throw new FatalException(buf); } XML_ParserFree(p); if (this->precalc != NULL) delete this->precalc; } MainLoop::~MainLoop() { int i; for (i = 0; i < this->num_events; i++) { if (this->events[i] == NULL) continue; #if !DEMOLIB_SILENT char *buf = strdup(this->events[i]->title); #endif delete this->events[i]; #if !DEMOLIB_SILENT int err = glGetError(); if (err != 0) { printf("Warning: Effect `%s' has OpenGL error 0x%x in exit code\n", buf, err); } free(buf); #endif this->events[i] = NULL; } free(this->events); this->events = NULL; for (i = 0; i < this->num_factories; i++) { delete this->factories[i]; this->factories[i] = NULL; } free(this->factories); this->factories = NULL; this->markers->destroy_values(); delete this->markers; this->markers = NULL; } void MainLoop::add_handler(Factory *handler_factory) { this->factories[num_factories++] = handler_factory; } void MainLoop::process_element(const char *el, const char **attr) { char title[256] = "[No title]"; /* check if this is a music marker */ if (strcmp(el, "marker") == 0) { const char *name = NULL; float t = -1.0f; int i = 0; while (attr[i]) { if (strcmp(attr[i], "name") == 0) { name = attr[i + 1]; } if (strcmp(attr[i], "time") == 0) { t = atof(attr[i + 1]); } i += 2; } if (name == NULL) throw new FatalException(el, "No name= attribute!"); if (t == -1.0f) throw new FatalException(el, "No time= attribute!"); /* sigh */ float *tp = (float *)(malloc(sizeof(float))); if (tp == NULL) throw new FatalException("Out of memory!"); *tp = t; this->markers->insert(name, (void *)tp); return; } /* check if this is an effect marker (start/end/point) */ if (strcmp(el, "start") == 0 || strcmp(el, "point") == 0 || strcmp(el, "end") == 0) { if (this->curr_event == NULL) { throw new FatalException(el, "Time element outside effect elements!"); } else { this->curr_event->add_curvepoint(this->markers, el, attr); return; } } /* * Check if this is a loader progress point (lpp). * This is used for two purposes: * * 1) Show a simple progress bar while loading. (For the * Underscore demo, this is replaced by a fancy Pi * display ;-) ) * 2) Timing loader parts, to be outputted and possibly * made into more exact p= values later. (This is * disabled by setting DEMOLIB_SILENT.) */ if (strcmp(el, "lpp") == 0) { float p = -1.0f; int i = 0; #if !DEMOLIB_SILENT static bool init_timer = false; #if __linux__ static struct timeval first_lpp, now; #else static DWORD first_lpp, now; #endif if (!init_timer) { #if __linux__ gettimeofday(&first_lpp, NULL); #else first_lpp = GetTickCount(); #endif init_timer = true; } #if __linux__ gettimeofday(&now, NULL); printf("LPP: [%6.3f]\n", (now.tv_sec - first_lpp.tv_sec) + (float)(now.tv_usec - first_lpp.tv_usec) * 0.000001f); #else now = GetTickCount(); printf("LPP: [%6.3f]\n", (float)(now - first_lpp) * 0.001f); #endif #endif /* !DEMOLIB_SILENT */ while (attr[i]) { if (strcmp(attr[i], "p") == 0) { p = atof(attr[i + 1]); break; } i += 2; } if (p == -1.0f) return; #if 0 /* do we want this in a separate class? */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f); glDisable(GL_BLEND); glDisable(GL_LIGHTING); glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glVertex2f(0.0f, 0.9f); glVertex2f(p, 0.9f); glVertex2f(p, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); this->win->flip(); #else if (this->precalc != NULL) this->precalc->update(p); #endif return; } /* * If this is the music and we have -nosound, discard it. */ #if WIN32 if (strcmp(el, "music") == 0 && (!this->sound || Win32Config::instance()->get_sound() == (LPGUID)-1)) { return; } #else if (strcmp(el, "music") == 0 && !this->sound) { return; } #endif /* * Find the title, and make a temporary hash table to hold all * the attributes. * * C++ is very picky about const (which is good) -- we KNOW that the * attribute strings will never be edited, but it's very hard to prove * that to the computer programmatically :-) */ Hashtable *attr_hash = new Hashtable(); int i = 0; while (attr[i]) { attr_hash->insert(attr[i], (char *)attr[i + 1]); if (strcmp(attr[i], "title") == 0) { strcpy(title, attr[i + 1]); } i += 2; } /* find a factory that can instantiate this type of event classes */ Event *ev = NULL; for (i = 0; i < num_factories; i++) { Factory *f = this->factories[i]; if (!f->can_handle(el)) continue; /* * If this is the first event, it's a DemoHandler, and we want * to set window stuff etc. -- this isn't particularily clean, * and should be rewritten someday. */ if (this->num_events == 0) { #if __linux__ /* attempt to use the colorful GTK+ interface first =) */ try { /* * don't use the interface if there are command line * options */ if (argc != 1) throw new NonFatalException("disabling because of command line options"); LinuxConfig *lc = new LinuxConfig(); lc->show(&argc, &argv, attr_hash); if (strcmp(attr_hash->get_str("sound"), "no") == 0) { this->sound = false; } } catch (NonFatalException *e) { fprintf(stderr, "Couldn't open GTK+ interface (%s), reverting to command line.\n", e->get_error()); /* use the generic code, since GTK+ failed for some reason */ this->parse_commandline(argc, argv, attr_hash); } #else /* Win32 */ if (argc != 1) { this->parse_commandline(argc, argv, attr_hash); } else { char buf[256]; Win32Config *c = Win32Config::instance(); c->dialog(); if (c->get_fullscreen()) { attr_hash->insert("fullscreen", "yes"); } else { attr_hash->insert("fullscreen", "no"); } attr_hash->insert("xres", "0"); attr_hash->insert("yres", "0"); sprintf(buf, "%u", c->get_zbuffer()); attr_hash->insert("zbuffer", buf); sprintf(buf, "%u", c->get_mode()); attr_hash->insert("visual_id", buf); } #endif } ev = f->instantiate(this, title, el, attr_hash); #if !DEMOLIB_SILENT int err = glGetError(); if (err != 0) { printf("Warning: Initialization of `%s' has OpenGL error 0x%x\n", title, err); } #endif if (this->num_events == 0) { this->win = ((DemoHandler *)ev)->win; /* now that we have an OpenGL window, we can start the loader screen */ if (!attr_hash->exists("noprecalcscreen")) this->precalc = new PiPrecalc(this->win); } break; } delete attr_hash; if (ev == NULL) { throw new FatalException(el, "No usable handler found!"); } /* * the only special tags ATM are and -- they don't need end time */ if (strcmp(el, "demo") == 0 || strcmp(el, "music") == 0) { this->curr_event = NULL; ev->start = 0.0f; ev->stop = -1.0f; if (strcmp(el, "music") == 0) { /* music _can_ have a start time :-) */ int i = 0; while (attr[i]) { if (strcmp(attr[i], "start") == 0) { ev->start = atof(attr[i + 1]); break; } i += 2; } } } else { if (this->curr_event != NULL) { throw new FatalException(el, "Nested effect elements aren't allowed."); } this->curr_event = ev; } /* * ...and add the actual element (we could strip away start= etc., but we * don't care -- it isn't worth it) */ this->events[this->num_events++] = ev; } void MainLoop::run() { #ifdef WIN32 QueryPerformanceCounter(&this->tmstart); QueryPerformanceFrequency(&this->tmfreq); #else gettimeofday(&tmstart, NULL); #endif this->run(true); } #if !defined(__GNUC__) && !defined(__ICC__) extern int layer_event_sort(const void *a, const void *b); #else int layer_event_sort(const void *a, const void *b) { float la = (*((Event **)a))->layer; float lb = (*((Event **)b))->layer; if (la < lb) return -1; if (la > lb) return 1; return 0; } #endif float MainLoop::get_time() { if (this->timer == NULL) { #if WIN32 LARGE_INTEGER now; QueryPerformanceCounter(&now); return (float)(now.QuadPart - tmstart.QuadPart) / (float)(tmfreq.QuadPart); #else struct timeval now; gettimeofday(&now, NULL); return (now.tv_sec - tmstart.tv_sec) + (float)(now.tv_usec - tmstart.tv_usec) * 0.000001f; #endif } else { return this->timer->get_time() + 0.010; } } /* * This serves both as a main loop and a GLUT callback point. It has to work * this way because really is special -- most likely, will _never_ * return (and that's good, because then we won't need to check which effects * have passed long time ago ;-) ) but will just keep on calling run() back... */ void MainLoop::run(bool infloop) { #if !DEMOLIB_SILENT int err = glGetError(); if (err != 0) { printf("Warning: Some part of initialization has OpenGL error 0x%x\n", err); } #endif do { this->num_play_events = 0; float timer = this->get_time(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* * go through any active handlers and see if they should be ended * (could perhaps be in reverse order? at least and * SHOULD come last) */ for (int i = 0; i < this->next_evnum; i++) { Event *e = this->events[i]; if (e && e->active) { if (timer > e->stop && e->stop != -1.0f) { #if !DEMOLIB_SILENT printf("Exiting: %s\n", e->title); #endif e->end_effect(); #if !DEMOLIB_SILENT int err = glGetError(); if (err != 0) { printf("Warning: Effect `%s' has OpenGL error 0x%x in destroy code\n", e->title, err); } #endif if (i == 0 || i == 1) { e->active = false; } else { #if !DEMOLIB_SILENT char *buf = strdup(e->title); #endif delete e; #if !DEMOLIB_SILENT int err = glGetError(); if (err != 0) { printf("Warning: Effect `%s' has OpenGL error 0x%x in destroy code\n", buf, err); } free(buf); #endif this->events[i] = NULL; } #endif } else { evlist[num_play_events++] = e; } } } /* fire off any new events */ while (this->next_evnum < this->num_events && timer >= this->events[this->next_evnum]->start) { Event *e = this->events[this->next_evnum]; this->next_evnum++; if (timer > e->stop && e->stop != -1.0f) { /* we missed it completely! */ } else { #if !DEMOLIB_SILENT printf("Entering: %s\n", e->title); #endif e->active = true; e->start_effect(); evlist[num_play_events++] = e; #if !DEMOLIB_SILENT int err = glGetError(); if (err != 0 && this->next_evnum != 1) { printf("Warning: Effect `%s' has OpenGL error 0x%x in init code\n", e->title, err); } #endif } } /* now sort the effects by layer (lower/negative ones come first) */ if (num_play_events > 0) { qsort(evlist, num_play_events, sizeof(Event *), layer_event_sort); for (int i = 0; i < num_play_events; i++) { Event *e = evlist[i]; e->draw_scene((timer - e->start) / (e->stop - e->start)); #if !DEMOLIB_SILENT int err = glGetError(); if (err != 0 && i != 0) { printf("Warning: Effect `%s' has OpenGL error 0x%x\n", e->title, err); } #endif } glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(53.0f, DEMOLIB_XASPECT / DEMOLIB_YASPECT, 1.0f, 500.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } } while (infloop && this->events[0] && this->events[0]->active); } void MainLoop::parse_commandline(int argc, char **argv, Hashtable *attr_hash) { /* defaults :-) */ attr_hash->insert("fullscreen", "yes"); attr_hash->insert("xres", "640"); attr_hash->insert("yres", "480"); attr_hash->insert("depth", "32"); attr_hash->insert("zbuffer", "16"); for (int j = 1; j < argc; j++) { if (strcmp(argv[j], "-fullscreen") == 0) { attr_hash->insert("fullscreen", "yes"); continue; } if (strcmp(argv[j], "-windowed") == 0) { attr_hash->insert("fullscreen", "no"); continue; } if (strcmp(argv[j], "-noprecalc") == 0) { attr_hash->insert("noprecalcscreen", "yes"); continue; } /* hidden modes, not very supported ;-) */ if (strcmp(argv[j], "-320x200") == 0) { attr_hash->insert("xres", "320"); attr_hash->insert("yres", "200"); continue; } if (strcmp(argv[j], "-320x240") == 0) { attr_hash->insert("xres", "320"); attr_hash->insert("yres", "240"); continue; } if (strcmp(argv[j], "-512x384") == 0) { attr_hash->insert("xres", "512"); attr_hash->insert("yres", "384"); continue; } if (strcmp(argv[j], "-640x480") == 0) { attr_hash->insert("xres", "640"); attr_hash->insert("yres", "480"); continue; } if (strcmp(argv[j], "-800x600") == 0) { attr_hash->insert("xres", "800"); attr_hash->insert("yres", "600"); continue; } if (strcmp(argv[j], "-1024x768") == 0) { attr_hash->insert("xres", "1024"); attr_hash->insert("yres", "768"); continue; } if (strcmp(argv[j], "-1280x960") == 0) { attr_hash->insert("xres", "1280"); attr_hash->insert("yres", "960"); continue; } if (strcmp(argv[j], "-1280x1024") == 0) { attr_hash->insert("xres", "1280"); attr_hash->insert("yres", "1024"); continue; } if (strcmp(argv[j], "-1400x1050") == 0) { attr_hash->insert("xres", "1400"); attr_hash->insert("yres", "1050"); continue; } if (strcmp(argv[j], "-1600x1200") == 0) { attr_hash->insert("xres", "1600"); attr_hash->insert("yres", "1200"); continue; } if (strcmp(argv[j], "-16") == 0) { attr_hash->insert("depth", "16"); continue; } if (strcmp(argv[j], "-32") == 0) { attr_hash->insert("depth", "32"); continue; } if (strcmp(argv[j], "-z16") == 0) { attr_hash->insert("zbuffer", "16"); continue; } if (strcmp(argv[j], "-z24") == 0) { attr_hash->insert("zbuffer", "24"); continue; } if (strcmp(argv[j], "-z32") == 0) { attr_hash->insert("zbuffer", "32"); continue; } if (strcmp(argv[j], "-nosound") == 0) { this->sound = false; continue; } throw new FatalException( "Allowed switches:\n\n" "-fullscreen\tRun in fullscreen (default)\n" "-windowed\tRun in a window (NOT SUPPORTED)\n" "-640x480\tRun in 640x480 (default)\n" "-800x600\tRun in 800x600\n" "-1024x768\tRun in 1024x768\n" "-1280x960\tRun in 1280x960\n" "-1280x1024\tRun in 1280x1024\n" "-1400x1050\tRun in 1400x1050 (yes, it exists)\n" "-1600x1200\tRun in 1600x1200 (good luck)\n" "-16\t\tRun in 16bpp (worse quality, but might work better)\n" "-32\t\tRun in 32bpp (default)\n" "-z16\t\t16bpp Z-buffer (default)\n" "-z24\t\t24bpp Z-buffer (better quality if it works)\n" "-z32\t\t32bpp Z-buffer (even better quality if it works)\n" "-nosound\tRun silently\n" ); } } amoeba-1.1.orig/main/interferenceheightmaphandler.cpp0100644000000000000000000000720707471737544021613 0ustar rootroot#include #include #include #include #ifdef WIN32 #include #endif #include #ifndef M_PI #define M_PI 3.14159265358979323846264 #endif #include "main/interferenceheightmaphandler.h" #include "math/vector.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP InterferenceHeightmapHandler::InterferenceHeightmapHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Object(ml, title, elem, attr) { this->xlod = attr->get_int("xlod"); this->ylod = attr->get_int("ylod"); this->speedlin = attr->get_float("speedlin"); this->freqlinx = attr->get_float("freqlinx"); this->freqliny = attr->get_float("freqliny"); this->ampllin = attr->get_float("ampllin"); this->speedcirc = attr->get_float("speedcirc"); this->freqcirc = attr->get_float("freqcirc"); this->amplcirc = attr->get_float("amplcirc"); this->pure_indices = true; this->vertices_per_face = 4; float xscale = 1.0f / (float)xlod; float yscale = 1.0f / (float)ylod; int x, y; float xf, yf; for (y = 0, yf = -0.5f; y < ylod; y++, yf += yscale) { for (x = 0, xf = -0.5f; x < xlod; x++, xf += xscale) { struct vertex v = { xf * 10.0f, yf * 10.0f, 0.0f }; struct texcoord t = { xf + 0.5f, yf + 0.5f }; struct normal n = { 0.0f, 1.0f, 0.0f }; this->vertices.add_end(v); this->texcoords.add_end(t); this->normals.add_end(n); } } for (y = 0; y < ylod-1; y++) { for (x = 0; x < xlod-1; x++) { this->faces.add_end(y*ylod + x); this->faces.add_end((y+1)*ylod + x); this->faces.add_end((y+1)*ylod + x+1); this->faces.add_end(y*ylod + x+1); } } } InterferenceHeightmapHandler::~InterferenceHeightmapHandler() { } void InterferenceHeightmapHandler::start_effect() { Object::start_effect(); } void InterferenceHeightmapHandler::draw_scene(float progress) { this->unlock_object(); float u1 = this->get_val("user1", progress); float u2 = this->get_val("user2", progress); float u3 = this->get_val("user3", progress); float u4 = this->get_val("user4", progress); float xscale = 1.0f / (float)xlod; float yscale = 1.0f / (float)ylod; float xscale2 = freqlinx * xscale; float yscale2 = freqliny * yscale; float yf = -u4; float yfs = 0.0f; const float p_sl = progress * speedlin; const float flx_al = freqlinx * ampllin; const float fly_al = freqliny * ampllin; for (int y = 0; y < ylod; y++, yf += yscale, yfs += yscale2) { float xf = -u3, xfs = 0.0f; for (int x = 0; x < xlod; x++, xf += xscale, xfs += xscale2) { /* calculate the height */ /* * calculate H, dH/dx and dH/dy... this code is unreadable, sorry, * it's for the sake of speed :-) */ const float dist = hypot(xf, yf); #if __GNUC__ float sin_v, cos_v; __asm__("fsincos" : "=t" (cos_v), "=u" (sin_v) : "0" (dist * freqcirc + progress * speedcirc)); #else const float temp = dist * freqcirc + progress * speedcirc; const float sin_v = sin(temp); const float cos_v = cos(temp); #endif const float divval = freqcirc * amplcirc / dist; const float z = sin_v * amplcirc + (sin(xfs + p_sl + u1) + sin(yfs + p_sl + u2)) * ampllin; const float dx = cos_v * xf * divval + flx_al * cos(xfs + p_sl + u1); const float dy = cos_v * yf * divval + fly_al * cos(yfs + p_sl + u2); Vector normal(dx * -0.2f, dy * -0.2f, 1.0f); normal.normalize(); vertices[y * xlod + x].z = z; normals[y * xlod + x].nx = normal.x; normals[y * xlod + x].ny = normal.y; normals[y * xlod + x].nz = normal.z; } } Object::draw_scene(progress); } void InterferenceHeightmapHandler::end_effect() { Object::end_effect(); } #endif /* DEMOLIB_MAINLOOP */ amoeba-1.1.orig/main/linearcurve.h0100644000000000000000000000057507457113224015665 0ustar rootroot#ifndef _LINEARCURVE_H #define _LINEARCURVE_H #include "main/curve.h" class LinearCurve : public Curve { private: int pos_hint; public: LinearCurve(); ~LinearCurve(); void add_curvepoint(float x, float y); void end_curvepoints(float start, float length); float get_value(float x); int get_curvetype() { return CURVE_LINEAR; } }; #endif /* !defined(_LINEARCURVE_H) */ amoeba-1.1.orig/main/backgroundhandler.cpp0100644000000000000000000001521307502113564017347 0ustar rootroot/* * backgroundhandler.cpp: Static backgrounds, split into multiple * textures so we don't have to scale them (if * they match the screen resolution, that is). * * This class really isn't just about backgrounds anymore, * since it can be put on different layers and become * offsetted. Should rename it and possibly integrate * with some day. :-) */ #include #include #ifdef WIN32 #include #endif #include #include "main/backgroundhandler.h" #include "opengl/texture.h" #include "opengl/extensions.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP BackgroundHandler::BackgroundHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "alpha") { if (attr->exists("layer")) { this->layer = attr->get_float("layer"); } else { this->layer = -50.0f; } Image *baseimg = load_image(attr->get_str("file")); this->xres = baseimg->get_width(); this->yres = baseimg->get_height(); this->xoffs = 0; this->yoffs = 0; if (attr->exists("xoffs")) { this->xoffs = attr->get_int("xoffs"); } if (attr->exists("yoffs")) { this->yoffs = attr->get_int("yoffs"); } if (attr->exists("screenwidth")) { this->screenwidth = attr->get_int("screenwidth"); if (this->screenwidth < this->xoffs + this->xres) { throw new FatalException(elem, "screenwidth= would make the image go outside the screen!"); } } else { this->screenwidth = this->xoffs + this->xres; } if (attr->exists("screenheight")) { this->screenheight = attr->get_int("screenheight"); if (this->screenheight < this->yoffs + this->yres) { throw new FatalException(elem, "screenheight= would make the image go outside the screen!"); } } else { this->screenheight = this->yoffs + this->yres; } GLenum fmt = texture::get_opengl_format(baseimg->get_bpp()); GLenum ifmt = texture::get_opengl_internal_format(baseimg->get_bpp()); /* * Find how many parts we need to split in :-) * * In order to support crappy cards that can't handle resolutions * bigger than 256x256 (read: Voodoo1/2/3), we have to do it a * bit weird: First build up an array containing the bits of the * image resolution, then propagate down so e.g. 512x256 is split * into two 256x256 images, finally count the number of x- and * y-parts and split it. */ GLint maxsize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize); int i; this->xparts = 0; this->yparts = 0; for (i = 0; i < 30; i++) { if (xres & (1<= 0; i--) { if ((1< maxsize) { xpartbits[i - 1] += (xpartbits[i]) * 2; xpartbits[i] = 0; ypartbits[i - 1] += (ypartbits[i]) * 2; ypartbits[i] = 0; } else { this->xparts += xpartbits[i]; this->yparts += ypartbits[i]; } } this->textures = new GLuint[xparts * yparts]; glGenTextures(xparts * yparts, this->textures); const int psize = baseimg->get_bpp() / 8; /* * now split the image in individual power-of-two-sized parts * (ugly because of the texture max limit stuff) */ int yoffs = 0, texnum = 0; for (int ybit = 0; ybit < 30; ybit++) { const int h = 1 << ybit; for (int j = 0; j < ypartbits[ybit]; j++) { int xoffs = 0; for (int xbit = 0; xbit < 30; xbit++) { const int w = 1 << xbit; for (int k = 0; k < xpartbits[xbit]; k++) { /* * generate a memory area to store the things in * (simplest, we don't have to mess around with * strides etc. */ unsigned char *tmpbuf = new unsigned char[w * h * psize]; for (int y = 0; y < h; y++) { memcpy(tmpbuf + y * w * psize, baseimg->get_pixel_data() + ((y+yoffs) * xres + xoffs) * psize, w * psize); } /* no mipmapping -- save texture memory :-) */ glBindTexture(GL_TEXTURE_2D, this->textures[texnum++]); glTexImage2D(GL_TEXTURE_2D, 0, ifmt, w, h, 0, fmt, GL_UNSIGNED_BYTE, tmpbuf); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); delete[] tmpbuf; xoffs += w; } } yoffs += h; } } delete baseimg; } BackgroundHandler::~BackgroundHandler() { glDeleteTextures(xparts * yparts, this->textures); } void BackgroundHandler::start_effect() { } void BackgroundHandler::draw_scene(float progress) { float alpha = this->get_val("alpha", progress); if (alpha < 0.0f) return; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, (float)(this->screenwidth), (float)(this->screenheight), 0.0f, 0.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, alpha); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); /* regenerate picture from the parts */ int yoffs = this->yoffs, texnum = 0; for (int ybit = 0; ybit < 30; ybit++) { const int h = 1 << ybit; for (int j = 0; j < ypartbits[ybit]; j++) { int xoffs = this->xoffs; for (int xbit = 0; xbit < 30; xbit++) { const int w = 1 << xbit; for (int k = 0; k < xpartbits[xbit]; k++) { glBindTexture(GL_TEXTURE_2D, this->textures[texnum++]); /* * the +0.01 part is to fix some cracks on broken * (e.g. Matrox G450/G550 -- ATI Rage128 has the * same problem but this fix doesn't help) OpenGL * drivers -- hopefully it shouldn't matter for * properly behaving drivers :-) */ glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f((float)(xoffs ), (float)(yoffs ), 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f((float)(xoffs ), (float)(yoffs + h) + 0.01f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f((float)(xoffs + w) + 0.01f, (float)(yoffs + h) + 0.01f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f((float)(xoffs + w) + 0.01f, (float)(yoffs ), 0.0f); glEnd(); xoffs += w; } } yoffs += h; } } glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void BackgroundHandler::end_effect() {} #endif amoeba-1.1.orig/main/inverthandler.cpp0100644000000000000000000000244107477160556016554 0ustar rootroot#include #include #ifdef WIN32 #include #endif #include #include "main/inverthandler.h" #include "exception.h" #include "demolib_prefs.h" #include "opengl/texture.h" #if DEMOLIB_MAINLOOP InvertHandler::InvertHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "alpha") { } InvertHandler::~InvertHandler() { } void InvertHandler::start_effect() { } void InvertHandler::draw_scene(float progress) { float alpha = this->get_val("alpha", progress); if (alpha <= 0.0f) return; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR); glColor4f(alpha, alpha, alpha, 1.0f); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void InvertHandler::end_effect() {} #endif amoeba-1.1.orig/main/twisthandler.cpp0100644000000000000000000002545107502111156016402 0ustar rootroot/* * A twisting object deformation. * * Quite close to the deadline now, we're trying to do interesting stuff, so we're * combining the twister and the normalspike -- this results to code duplication * (and forced fixation of the wave parameter), but that's how it has to be when * you don't have time to make better generic "object filters" or something :-) */ #include #include #ifdef WIN32 #include #endif #include #include #include "math/vector.h" #include "exception.h" #include "twisthandler.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP TwistHandler::TwistHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : ObjHandler(ml, title, elem, attr) { float wave = attr->get_float("wave"); if (!this->pure_indices) throw new FatalException(elem, "Needs optimized .obj files!"); if (this->normals.num_elems() != this->vertices.num_elems()) throw new FatalException(elem, "Needs .obj files with normals!"); if (this->vertices_per_face != 3) throw new FatalException(elem, "Needs triangulated .obj files!"); /* take a backup of the original vertices */ this->orig_vertices = this->vertices; /* * make an atan2() cache, for speedup (not strictly a vertex, but * the xyz mapping makes sense) */ this->atan_cache = new vertex[vertices.num_elems()]; int i; for (i = 0; i < this->vertices.num_elems(); i++) { struct vertex v; v.x = atan2(vertices[i].z, vertices[i].y) * wave; v.y = atan2(vertices[i].x, vertices[i].z) * wave; v.z = atan2(vertices[i].y, vertices[i].x) * wave; this->atan_cache[i] = v; } if (attr->exists("normalspike") && attr->get_bool("normalspike")) { this->normalspike = true; this->normalspiketex = texture::load(attr->get_str("normalspiketexture")); this->spike_vert = new vertex[this->vertices.num_elems() * 4]; this->spike_tc = new texcoord[this->vertices.num_elems() * 4]; for (int i = 0; i < this->vertices.num_elems(); i++) { spike_tc[i * 4 ].u = 0.0f; spike_tc[i * 4 ].v = 1.0f; spike_tc[i * 4 + 1].u = 1.0f; spike_tc[i * 4 + 1].v = 1.0f; spike_tc[i * 4 + 2].u = 1.0f; spike_tc[i * 4 + 2].v = 0.0f; spike_tc[i * 4 + 3].u = 0.0f; spike_tc[i * 4 + 3].v = 0.0f; } } else { this->normalspike = false; this->normalspiketex = NULL; this->spike_vert = NULL; this->spike_tc = NULL; } /* * For the normal mapping, we need an accurate index of what points * are connected to each other (so we can average their face normals). * When no points are duplicated, this is a simple matter, and the * .obj files we get from Maya are usually that way. However, separate * vertex/texcoord/normal indices isn't good when we want to use * vertex arrays (or really, _anything_ :-P), so the optimized .obj * files we use "group" points by the vertex/texcoord/normal combination. * However, this causes `seams' in points where positions are equal * but texture coordinates are not (typical example is a sphere where * (0.0,0.0) != (1.0,0.0) for texcoords), so we need to regroup the * information here somehow. * * The solution is to make a list of duplicate points. For each and * every point, we have a singly linked list. Every int in this list * is an index to another point in the group, and the list is looped * so that we can start the traversal wherever we want. A point * with no duplicates simply points to its own index. * * The critera for "duplicate" involves equal position and normals, * so texcoords aren't counted -- they really shouldn't either when * it comes to object structure. However, points not sharing the * same normal shouldn't usually be averaged either (think sharp * edges here), so we don't want to _just_ consider the positions. * Thus the (position,normal) combination. */ this->vertex_alias = new int[this->vertices.num_elems()]; for (int i = 0; i < this->vertices.num_elems(); i++) { struct vertex *v = &(this->vertices[i]); struct normal *n = &(this->normals[i]); this->vertex_alias[i] = i; for (int j = 0; j < i; j++) { if (fabs(this->vertices[j].x - v->x) < 0.0001f && fabs(this->vertices[j].y - v->y) < 0.0001f && fabs(this->vertices[j].z - v->z) < 0.0001f && fabs(this->normals[j].nx - n->nx) < 0.0001f && fabs(this->normals[j].ny - n->ny) < 0.0001f && fabs(this->normals[j].nz - n->nz) < 0.0001f) { /* * find the _last_ point in the chain (ie. * the one pointing back at j) */ int lp = j; while (this->vertex_alias[lp] != j) lp = this->vertex_alias[lp]; /* insert i in this chain */ this->vertex_alias[lp] = i; this->vertex_alias[i] = j; break; } } } } TwistHandler::~TwistHandler() { delete[] this->atan_cache; this->atan_cache = NULL; delete[] this->vertex_alias; this->vertex_alias = NULL; delete[] this->spike_vert; this->spike_vert = NULL; delete[] this->spike_tc; this->spike_tc = NULL; delete this->normalspiketex; this->normalspiketex = NULL; } void TwistHandler::start_effect() { Object::start_effect(); } void TwistHandler::draw_scene(float progress) { int i; float wobble = this->get_val("user1", progress); float power = this->get_val("user2", progress); this->unlock_object(); for (i = 0; i < this->vertices.num_elems(); i++){ float xrot = 1.0f + (float)sin( wobble + atan_cache[i].x) * power; float yrot = 1.0f + (float)sin( wobble - atan_cache[i].y) * power; float zrot = 1.0f + (float)sin(-wobble + atan_cache[i].z) * power; this->vertices[i].x = this->orig_vertices[i].x * yrot * zrot; this->vertices[i].y = this->orig_vertices[i].y * zrot * xrot; this->vertices[i].z = this->orig_vertices[i].z * xrot * yrot; } /* * now regenerate the normals -- this isn't particularily quick or pretty, * but it works */ for (i = 0; i < this->normals.num_elems(); i++) { this->normals[i].nx = 0.0f; this->normals[i].ny = 0.0f; this->normals[i].nz = 0.0f; } for (i = 0; i < this->faces.num_elems(); i += 3) { vertex v[3]; v[0] = this->vertices[this->faces[i ]]; v[1] = this->vertices[this->faces[i + 1]]; v[2] = this->vertices[this->faces[i + 2]]; Vector up (v[2].x - v[0].x, v[2].y - v[0].y, v[2].z - v[0].z); Vector right(v[1].x - v[0].x, v[1].y - v[0].y, v[1].z - v[0].z); Vector normal = right.cross_product(up); for (int j = 0; j < 3; j++) { int start_ind = this->faces[i + j]; int ind = start_ind; do { this->normals[ind].nx += normal.x; this->normals[ind].ny += normal.y; this->normals[ind].nz += normal.z; ind = this->vertex_alias[ind]; } while (ind != start_ind); } } /* normalize */ for (i = 0; i < this->normals.num_elems(); i++) { const float mulfac = 1.0f / sqrt( this->normals[i].nx * this->normals[i].nx + this->normals[i].ny * this->normals[i].ny + this->normals[i].nz * this->normals[i].nz); this->normals[i].nx *= mulfac; this->normals[i].ny *= mulfac; this->normals[i].nz *= mulfac; } Object::draw_scene(progress); if (this->normalspike && this->get_val("user3", progress) != 0.0f) { /* * set up a fake viewport we can map to an orthographic projection * later */ GLint viewport[4] = { 0, 0, 1, 1 }; GLdouble modelview[16]; GLdouble projection[16]; const float length = this->get_val("user3", progress); const float base = this->get_val("user4", progress); glMatrixMode(GL_MODELVIEW); glPushMatrix(); float x = this->get_val("xpos", progress); float y = this->get_val("ypos", progress); float z = this->get_val("zpos", progress); float xr = this->get_val("xrot", progress); float yr = this->get_val("yrot", progress); float zr = this->get_val("zrot", progress); glTranslatef(x,y,z); if (this->inverse_rotorder) { glRotatef(zr, 0.0f, 0.0f, 1.0f); glRotatef(yr, 0.0f, 1.0f, 0.0f); glRotatef(xr, 1.0f, 0.0f, 0.0f); } else { glRotatef(xr, 1.0f, 0.0f, 0.0f); glRotatef(yr, 0.0f, 1.0f, 0.0f); glRotatef(zr, 0.0f, 0.0f, 1.0f); } float scale = this->get_val("scale", progress); glScalef(scale, scale, scale); glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f); glMatrixMode(GL_MODELVIEW); glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glEnable(GL_TEXTURE_2D); normalspiketex->bind(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); for (int i = 0; i < vertices.num_elems(); i++) { /* transform first the base point */ double bwx, bwy, bwz; gluProject((double)(vertices[i].x), (double)(vertices[i].y), (double)(vertices[i].z), modelview, projection, viewport, &bwx, &bwy, &bwz); /* then the tip of the spike */ double ox = (double)(vertices[i].x + normals[i].nx * length); double oy = (double)(vertices[i].y + normals[i].ny * length); double oz = (double)(vertices[i].z + normals[i].nz * length); double wx, wy, wz; gluProject(ox, oy, oz, modelview, projection, viewport, &wx, &wy, &wz); /* now make a left and a right base */ float lbx = bwx - (wy-bwy) * base; float lby = bwy + (wx-bwx) * base; float rbx = bwx + (wy-bwy) * base; float rby = bwy - (wx-bwx) * base; /* now make the triangle */ spike_vert[i * 4 ].x = lbx; spike_vert[i * 4 ].y = lby; spike_vert[i * 4 ].z = (float)bwz; spike_vert[i * 4 + 1].x = rbx; spike_vert[i * 4 + 1].y = rby; spike_vert[i * 4 + 1].z = (float)bwz; spike_vert[i * 4 + 2].x = (float)wx; spike_vert[i * 4 + 2].y = (float)wy; spike_vert[i * 4 + 2].z = (float)wz; spike_vert[i * 4 + 3].x = (float)wx; spike_vert[i * 4 + 3].y = (float)wy; spike_vert[i * 4 + 3].z = (float)wz; } glVertexPointer(3, GL_FLOAT, 0, spike_vert); glTexCoordPointer(2, GL_FLOAT, 0, spike_tc); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); if (this->has_compiled_vertex_array) (*this->glLockArraysEXT)(0, this->vertices.num_elems() * 4); glDrawArrays(GL_QUADS, 0, this->vertices.num_elems() * 4); if (this->has_compiled_vertex_array) (*this->glUnlockArraysEXT)(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glEnable(GL_LIGHTING); glDepthMask(GL_TRUE); glPopMatrix(); } } void TwistHandler::end_effect() { Object::end_effect(); } #endif amoeba-1.1.orig/main/imagehandler.cpp0100644000000000000000000000443307465252266016327 0ustar rootroot#include #ifdef WIN32 #include #endif #include #include "main/imagehandler.h" #include "../exception.h" #include "../demolib_prefs.h" #include "opengl/texture.h" #if DEMOLIB_MAINLOOP ImageHandler::ImageHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "xcsize:ycsize:xpos:ypos:xsize:ysize:alpha") { this->tex = texture::load(attr->get_str("file")); } ImageHandler::~ImageHandler() { texture::free(this->tex); this->tex = NULL; } void ImageHandler::start_effect() { } void ImageHandler::draw_scene(float progress) { float alpha = this->get_val("alpha", progress); if (alpha <= 0.0f) return; float xcsize = this->get_val("xcsize", progress); float ycsize = this->get_val("ycsize", progress); float xpos = this->get_val("xpos", progress) - xcsize * 0.5f; float ypos = this->get_val("ypos", progress) - ycsize * 0.5f; float xsize = this->get_val("xsize", progress) + xcsize; float ysize = this->get_val("ysize", progress) + ycsize; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glScalef(DEMOLIB_YASPECT / DEMOLIB_XASPECT, 1.0f, 1.0f); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_STENCIL_TEST); this->tex->bind(); glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, alpha); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(xpos, ypos, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(xpos, ypos + ysize, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(xpos + xsize, ypos + ysize, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(xpos + xsize, ypos, 0.0f); glEnd(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void ImageHandler::end_effect() {} #endif amoeba-1.1.orig/main/event.h0100644000000000000000000000174007467061402014463 0ustar rootroot#ifndef _EVENT_H #define _EVENT_H #include "main/mainloop.h" #include "util/hashtable.h" class MainLoop; class DemoHandler; class DOFHandler; class TimewalkHandler; class Event { public: Event(MainLoop *ml, const char *title, const char *elem, Hashtable *attr, char *curvenames); virtual ~Event(); /* these are typically provided by the base class */ void add_curvepoint(Hashtable *markers, const char *element, const char **attr); void end_curvedata(); float get_val(char *attr_name, float progress); /* these are typically overloaded */ virtual void start_effect(); virtual void draw_scene(float progress); virtual void end_effect(); static float parse_time(Hashtable *markers, const char *timestr); friend class MainLoop; friend class DemoHandler; friend class DOFHandler; friend class TimewalkHandler; /* sigh */ float start, stop; float layer; protected: Hashtable *curves; char *title; bool active; MainLoop *ml; }; #endif /* defined(_EVENT_H) */ amoeba-1.1.orig/main/object.cpp0100644000000000000000000004437607502113652015152 0ustar rootroot/* * Generic object class -- not to be used directly, but to be subclassed * by actual loaders. (For this reason, it's called Object, even though * one might call it an ObjectHandler.) It handles texture loading, but * not anything else related to files. */ #include #include #include #include #ifdef WIN32 #include #endif #include #include #include "math/array.h" #include "math/matrix.h" #include "math/vector.h" #include "main/object.h" #include "opengl/texture.h" #include "opengl/extensions.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 #endif Object::Object(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "xrot:yrot:zrot:xpos:ypos:zpos:scale:red:green:blue:alpha:user1:user2:user3:user4") { if (attr->exists("stencilmask")) { this->stencil_mask = attr->get_int("stencilmask"); } else { this->stencil_mask = 0x0; } if (attr->exists("halo") && attr->get_bool("halo")) { this->draw_halo = true; this->halo_length = attr->get_float("halolength"); /* ensure there is a stencil mask ;-) */ this->stencil_mask = attr->get_int("stencilmask"); } else { this->draw_halo = false; } this->halo_vert = NULL; this->inverse_rotorder = false; if (attr->exists("invrot")) { this->inverse_rotorder = attr->get_bool("invrot"); } this->additive_blend = false; if (attr->exists("blend")) { char *str = attr->get_str("blend"); if (strcmp(str, "blend") == 0) { this->additive_blend = false; } else if (strcmp(str, "add") == 0) { this->additive_blend = true; } else { throw new FatalException(elem, "blend= must be `blend' or `add'!"); } } /* this code got a bit ickier with hashes :-( */ this->vertices_per_face = 0; this->tex[0] = this->tex[1] = NULL; this->texgen[0] = this->texgen[1] = none; if (attr->exists("texstr0")) { this->texstr0 = attr->get_float("texstr0"); } else { this->texstr0 = 1.0f; } int num_texunit0 = 0; int num_texunit1 = 0; num_texunit0 += (attr->exists("texture")) ? 1 : 0; num_texunit0 += (attr->exists("texture0")) ? 1 : 0; num_texunit0 += (attr->exists("envmap")) ? 1 : 0; num_texunit0 += (attr->exists("envmap0")) ? 1 : 0; num_texunit0 += (attr->exists("linmap")) ? 1 : 0; num_texunit0 += (attr->exists("linmap0")) ? 1 : 0; num_texunit1 += (attr->exists("texture1")) ? 1 : 0; num_texunit1 += (attr->exists("envmap1")) ? 1 : 0; num_texunit1 += (attr->exists("linmap1")) ? 1 : 0; if (num_texunit0 > 1) throw new FatalException("Must have only one of texture/texture0, envmap/envmap0 and linmap/linmap0!"); if (num_texunit1 > 1) throw new FatalException("Must have only one of texture1, envmap1 and linmap1!"); if (attr->exists("texture")) this->tex[0] = texture::load(attr->get_str("texture")); if (attr->exists("texture0")) this->tex[0] = texture::load(attr->get_str("texture0")); if (attr->exists("envmap")) { this->tex[0] = texture::load(attr->get_str("envmap")); this->texgen[0] = envmap; } if (attr->exists("envmap0")) { this->tex[0] = texture::load(attr->get_str("envmap0")); this->texgen[0] = envmap; } if (attr->exists("linmap")) { this->tex[0] = texture::load(attr->get_str("linmap")); this->texgen[0] = linmap; } if (attr->exists("linmap0")) { this->tex[0] = texture::load(attr->get_str("linmap0")); this->texgen[0] = linmap; } if (attr->exists("texture1")) this->tex[1] = texture::load(attr->get_str("texture1")); if (attr->exists("envmap1")) { this->tex[1] = texture::load(attr->get_str("envmap1")); this->texgen[1] = envmap; } if (attr->exists("linmap1")) { this->tex[1] = texture::load(attr->get_str("linmap1")); this->texgen[1] = linmap; } if (this->tex[1] && !this->tex[0]) throw new FatalException(elem, "texture1/envmap1/linmap1 specified, but not texture0/envmap0/linmap0!"); if (GLExtensions::has_ext("GL_ARB_multitexture") && GLExtensions::has_ext("GL_ARB_texture_env_combine")) { this->has_multitexture = true; this->glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) GLExtensions::func_ptr("glActiveTextureARB"); this->glClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC) GLExtensions::func_ptr("glClientActiveTextureARB"); this->glMultiTexCoord2fvARB = (PFNGLMULTITEXCOORD2FVARBPROC) GLExtensions::func_ptr("glMultiTexCoord2fvARB"); } else { this->has_multitexture = false; } if (GLExtensions::has_ext("GL_EXT_compiled_vertex_array")) { this->has_compiled_vertex_array = true; this->glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC) GLExtensions::func_ptr("glLockArraysEXT"); this->glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC) GLExtensions::func_ptr("glUnlockArraysEXT"); } else { this->has_compiled_vertex_array = false; } if (GLExtensions::has_ext("GL_EXT_draw_range_elements")) { this->has_draw_range_elements = true; this->glDrawRangeElementsEXT = (PFNGLDRAWRANGEELEMENTSEXTPROC) GLExtensions::func_ptr("glDrawRangeElementsEXT"); } else { this->has_draw_range_elements = false; } this->has_rescale_normal = GLExtensions::has_ext("GL_EXT_rescale_normal"); bool interpolate_tex = true; if (attr->exists("mode")) { char *str = attr->get_str("mode"); if (strcmp(str, "interpolate") == 0) { interpolate_tex = true; } else if (strcmp(str, "add") == 0) { interpolate_tex = false; } else { throw new FatalException(elem, "mode= must be `interpolate' or `add'!"); } } if (interpolate_tex) { this->tu1combine = GL_INTERPOLATE_EXT; this->tu1s2 = GL_PRIMARY_COLOR_EXT; this->tu1o2 = GL_SRC_ALPHA; this->p2sf = GL_SRC_ALPHA; this->p2df = GL_ONE_MINUS_SRC_ALPHA; } else { this->tu1combine = GL_ADD; /* doesn't matter, but set to something so we won't generate errors */ this->tu1s2 = GL_PRIMARY_COLOR_EXT; this->tu1o2 = GL_SRC_ALPHA; this->p2sf = GL_ONE; this->p2df = GL_ONE; } this->tu1s0 = GL_PREVIOUS_EXT; this->tu1s1 = GL_TEXTURE; this->tu1o0 = GL_SRC_COLOR; this->tu1o1 = GL_SRC_COLOR; this->p2light = false; this->no_zbuffer = false; this->tv = NULL; this->pure_indices = false; this->precolor = false; this->pretrans = false; this->ctexcoords[0] = NULL; this->ctexcoords[1] = NULL; } Object::~Object() { texture::free(this->tex[0]); this->tex[0] = NULL; texture::free(this->tex[1]); this->tex[1] = NULL; delete this->ctexcoords[0]; this->ctexcoords[0] = NULL; delete this->ctexcoords[1]; this->ctexcoords[1] = NULL; } void Object::add_vertex(const struct vertex v) { this->vertices.add_end(v); } void Object::add_normal(const struct normal n) { this->normals.add_end(n); } void Object::add_texcoord(const struct texcoord tc) { this->texcoords.add_end(tc); } void Object::add_face(const int a, const int b, const int c) { this->faces.add_end(a); this->faces.add_end(b); this->faces.add_end(c); } void Object::add_face(const int a, const int b, const int c, const int d) { this->faces.add_end(a); this->faces.add_end(b); this->faces.add_end(c); this->faces.add_end(d); } void Object::unlock_object() { if (this->tv || this->pure_indices) { delete this->tv; this->tv = NULL; delete[] this->halo_vert; this->halo_vert = NULL; } } void Object::setup_vertex_arrays(bool textures, bool normals) { if (this->pure_indices) { glVertexPointer(3, GL_FLOAT, 0, this->vertices.get_array()); } else { glVertexPointer(3, GL_FLOAT, 0, tv->get_array()); } glEnableClientState(GL_VERTEX_ARRAY); if (textures) { if (this->has_multitexture && this->tex[1]) { (*this->glClientActiveTextureARB)(GL_TEXTURE1_ARB); if (this->texgen[1] == none) { glTexCoordPointer(2, GL_FLOAT, 0, this->texcoords.get_array()); glEnableClientState(GL_TEXTURE_COORD_ARRAY); } else { glDisableClientState(GL_TEXTURE_COORD_ARRAY); } (*this->glClientActiveTextureARB)(GL_TEXTURE0_ARB); } if (this->tex[0] && (this->texgen[0] == none)) { glTexCoordPointer(2, GL_FLOAT, 0, this->texcoords.get_array()); glEnableClientState(GL_TEXTURE_COORD_ARRAY); } else { glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } if (normals) { glNormalPointer(GL_FLOAT, 0, this->normals.get_array()); glEnableClientState(GL_NORMAL_ARRAY); } else { glDisableClientState(GL_NORMAL_ARRAY); } } void Object::draw_object() { this->draw_object((this->texcoords.num_elems() > 0 && this->tex[0]), (this->normals.num_elems() > 0)); } void Object::draw_object(bool textures, bool normals) { if (stencil_mask != 0x0) { glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, stencil_mask, stencil_mask); glStencilMask(stencil_mask); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); } glMatrixMode(GL_MODELVIEW); glPushMatrix(); if (this->has_multitexture && textures && this->tex[1]) { /* unit 0 */ (*this->glActiveTextureARB)(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); this->tex[0]->bind(); /* the texgen0 checking is done a bit later */ /* unit 1 */ (*this->glActiveTextureARB)(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, this->tu1combine); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, this->tu1s0); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, this->tu1s1); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, this->tu1s2); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, this->tu1o0); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, this->tu1o1); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, this->tu1o2); this->tex[1]->bind(); if (this->texgen[1] != none) { GLenum mode = (this->texgen[1] == envmap) ? GL_SPHERE_MAP : GL_OBJECT_LINEAR; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, mode); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, mode); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); } else { glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } (*this->glActiveTextureARB)(GL_TEXTURE0_ARB); /* we don't blend with multitexturing */ glDisable(GL_BLEND); /* set the relative texture strengths */ glColor4f(1.0f, 1.0f, 1.0f, this->texstr0); } else { /* okay, no single-pass multitexturing */ if (textures && this->tex[0]) { glEnable(GL_TEXTURE_2D); this->tex[0]->bind(); } else { glDisable(GL_TEXTURE_2D); } } if (textures) { if (this->texgen[0] != none) { GLenum mode = (this->texgen[0] == envmap) ? GL_SPHERE_MAP : GL_OBJECT_LINEAR; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, mode); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, mode); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); } else { glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } } if (normals) { glEnable(GL_LIGHTING); } else { glDisable(GL_LIGHTING); } GLenum primitive; switch (this->vertices_per_face) { case 1: primitive = GL_POINTS; break; case 2: primitive = GL_LINES; break; case 3: primitive = GL_TRIANGLES; break; case 4: primitive = GL_QUADS; break; default: primitive = GL_TRIANGLE_STRIP; } /* * one might collapse these into fewer ifs, but this * is better for speed... this `main' code branch is done in * three cases: * * 1. no texturing at all * 2. only texmap0/envmap0/linmap0 * 3. envmap1/linmap1 and GL_ARB_multitexture */ const int f = this->faces.num_elems(); /* * If the vertex array hasn't been made yet (or has been * invalidated by unlock_object()), make it now :-) */ if (this->tv == NULL && !this->pure_indices) { this->tv = new Array; for (int i = 0; i < f; i++) { tv->add_end(this->vertices[this->faces[i]].x); tv->add_end(this->vertices[this->faces[i]].y); tv->add_end(this->vertices[this->faces[i]].z); } } this->setup_vertex_arrays(textures, normals); if (this->has_compiled_vertex_array) { if (this->pure_indices) { (*this->glLockArraysEXT)(0, this->vertices.num_elems()); } else { (*this->glLockArraysEXT)(0, tv->num_elems()); } } if (!textures || !this->tex[1] || this->has_multitexture) { if (this->pure_indices) { if (this->has_draw_range_elements) { (*this->glDrawRangeElementsEXT)(primitive, 0, this->vertices.num_elems() - 1, this->faces.num_elems(), GL_UNSIGNED_INT, this->faces.get_array()); } else { glDrawElements(primitive, this->faces.num_elems(), GL_UNSIGNED_INT, this->faces.get_array()); } } else { glDrawArrays(primitive, 0, this->faces.num_elems()); } } else { /* * texmap1/envmap1/linmap1, and we don't have GL_ARB_multitexture. Multipass * rendering to the rescue! */ glDisable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glDepthMask(GL_TRUE); glDepthFunc(GL_LESS); for (int p = 0; p < 2; p++) { this->tex[p]->bind(); if (this->texgen[p] != none) { GLenum mode = (this->texgen[p] == envmap) ? GL_SPHERE_MAP : GL_OBJECT_LINEAR; glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, mode); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, mode); /* causes problems on broken Matrox cards */ //glDisableClientState(GL_TEXTURE_COORD_ARRAY); } else { glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glEnableClientState(GL_TEXTURE_COORD_ARRAY); } if (p == 1) { glBlendFunc(this->p2sf, this->p2df); glEnable(GL_BLEND); glEnable(GL_COLOR_MATERIAL); if (!this->p2light) glDisable(GL_LIGHTING); glColor4f(1.0f, 1.0f, 1.0f, 1.0f - this->texstr0); glDepthMask(GL_FALSE); glDepthFunc(GL_EQUAL); } if (this->pure_indices) { if (this->has_draw_range_elements) { (*this->glDrawRangeElementsEXT)(primitive, 0, this->vertices.num_elems() - 1, this->faces.num_elems(), GL_UNSIGNED_INT, this->faces.get_array()); } else { glDrawElements(primitive, this->faces.num_elems(), GL_UNSIGNED_INT, this->faces.get_array()); } } else { glDrawArrays(primitive, 0, this->faces.num_elems()); } } glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); glEnable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } if (this->has_multitexture && textures && this->tex[1]) { (*this->glActiveTextureARB)(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); (*this->glActiveTextureARB)(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); (*this->glActiveTextureARB)(GL_TEXTURE0_ARB); } glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); /* okay, it _is_ ugly, but still the best place to have it */ if (this->draw_halo) { if (!this->pure_indices) throw new FatalException("Halo needs presorted objects!"); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glDisable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_EQUAL, 0x0, this->stencil_mask); glStencilMask(this->stencil_mask); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glColor4f(0.0f, 0.0f, 0.0f, 1.0f); const float hl = this->halo_length; if (this->halo_vert == NULL) { this->halo_vert = new vertex[vertices.num_elems()]; for (int i = 0; i < vertices.num_elems(); i++) { halo_vert[i].x = vertices[i].x + this->normals[i].nx * hl; halo_vert[i].y = vertices[i].y + this->normals[i].ny * hl; halo_vert[i].z = vertices[i].z + this->normals[i].nz * hl; } } if (this->has_compiled_vertex_array) { (*this->glUnlockArraysEXT)(); } glVertexPointer(3, GL_FLOAT, 0, (GLfloat *)halo_vert); glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); if (this->has_draw_range_elements) { (*this->glDrawRangeElementsEXT)(primitive, 0, this->vertices.num_elems() - 1, this->faces.num_elems(), GL_UNSIGNED_INT, this->faces.get_array()); } else { glDrawElements(primitive, this->faces.num_elems(), GL_UNSIGNED_INT, this->faces.get_array()); } glDisable(GL_STENCIL_TEST); glStencilMask(0xFFFFFFFF); } glPopMatrix(); if (this->has_compiled_vertex_array) { (*this->glUnlockArraysEXT)(); } } void Object::start_effect() { glShadeModel(GL_SMOOTH); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); } void Object::setup_drawing(float progress) { /* * add Z sorting later, perhaps? */ if (!this->no_zbuffer) { glEnable(GL_DEPTH_TEST); } glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_BLEND); if (this->has_rescale_normal) { glEnable(GL_RESCALE_NORMAL); } else { glEnable(GL_NORMALIZE); } if (this->additive_blend) { glBlendFunc(GL_SRC_ALPHA, GL_ONE); } else { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } // glDisable(GL_COLOR_MATERIAL); if (!this->precolor) { float r = this->get_val("red", progress); float g = this->get_val("green", progress); float b = this->get_val("blue", progress); float alpha = this->get_val("alpha", progress); GLfloat material[] = { r, g, b, alpha }; glColor4f(r, g, b, alpha); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, material); } if (!this->pretrans) { float x = this->get_val("xpos", progress); float y = this->get_val("ypos", progress); float z = this->get_val("zpos", progress); float xr = this->get_val("xrot", progress); float yr = this->get_val("yrot", progress); float zr = this->get_val("zrot", progress); glTranslatef(x,y,z); if (this->inverse_rotorder) { glRotatef(zr, 0.0f, 0.0f, 1.0f); glRotatef(yr, 0.0f, 1.0f, 0.0f); glRotatef(xr, 1.0f, 0.0f, 0.0f); } else { glRotatef(xr, 1.0f, 0.0f, 0.0f); glRotatef(yr, 0.0f, 1.0f, 0.0f); glRotatef(zr, 0.0f, 0.0f, 1.0f); } float scale = this->get_val("scale", progress); glScalef(scale, scale, scale); } } void Object::draw_scene(float progress) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); this->setup_drawing(progress); this->draw_object(); glPopMatrix(); } void Object::end_effect() { } #endif /* DEMOLIB_MAINLOOP */ amoeba-1.1.orig/main/fonthandler.h0100644000000000000000000000110507477516504015652 0ustar rootroot#ifndef _FONTHANDLER_H #define _FONTHANDLER_H #include "demolib_prefs.h" #if DEMOLIB_OPENGL_FONT_TTF #include "main/event.h" #include "opengl/fontttf.h" #include "packer/file.h" class FontHandler : public Event { public: FontHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~FontHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: File *fontfile; FontTTF *font[128]; float linedistance; int num_lines; bool additive_blend; }; #endif /* DEMOLIB_FONT_TTF */ #endif /* defined(_FONTHANDLER_H) */ amoeba-1.1.orig/main/timerhandler.h0100644000000000000000000000064707440255132016021 0ustar rootroot#ifndef _TIMERHANDLER_H #define _TIMERHANDLER_H #include "main/event.h" #include "main/mainloop.h" #include "opengl/texture.h" class TimerHandler : public Event { public: TimerHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~TimerHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: Texture *digits; }; #endif /* defined(_TIMERHANDLER_H) */ amoeba-1.1.orig/main/linecurve.cpp0100644000000000000000000000145607441453410015671 0ustar rootroot/* * Intended to be a _fast_ and simple curve type. :-) */ #include "main/linecurve.h" #include "demolib_prefs.h" #include "exception.h" #include #if DEMOLIB_MAINLOOP LineCurve::LineCurve() { this->num_points = 0; } LineCurve::~LineCurve() {} void LineCurve::add_curvepoint(float x, float y) { this->x[this->num_points] = x; this->y[this->num_points] = y; this->num_points++; } void LineCurve::end_curvepoints(float start, float length) { if (this->num_points < 1 || this->num_points > 2) throw new FatalException("Need exactly two points for line movement!"); /* just trust that they come in order ;-) */ this->base = this->y[0]; this->step = (this->num_points == 1) ? 0.0f : (this->y[1] - base); } float LineCurve::get_value(float x) { return this->base + this->step * x; } #endif amoeba-1.1.orig/main/event.cpp0100644000000000000000000001035607467012004015013 0ustar rootroot#include #include #include #include "event.h" #include "main/curve.h" #include "main/linearcurve.h" #include "main/autosplinecurve.h" #include "main/linecurve.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP Event::Event(MainLoop *ml, const char *title, const char *elem, Hashtable *attr, char *curvenames) { int curve_type = CURVE_NONE; this->start = -1.0f; this->stop = -1.0f; this->active = false; this->title = strdup(title); if (attr->exists("layer")) { this->layer = attr->get_float("layer"); } else { this->layer = 0.0f; } this->curves = NULL; if (attr->exists("curve")) { const char * const ctstr = (const char * const)(attr->lookup("curve")); if (strcmp(ctstr, "linear") == 0) { curve_type = CURVE_LINEAR; } if (strcmp(ctstr, "autospline") == 0) { curve_type = CURVE_AUTOSPLINE; } if (strcmp(ctstr, "line") == 0) { curve_type = CURVE_LINE; } if (curve_type == CURVE_NONE) { throw new FatalException(ctstr, "Invalid curve type."); } } if (curvenames == NULL || strcmp(curvenames, "") == 0) return; if (curve_type == CURVE_NONE) { throw new FatalException(elem, "No curve type specified."); } this->curves = new Hashtable(); /* now create a set of attribute curves */ char *cn = strdup(curvenames); char *curve = strtok(cn, ":"); do { Curve *c = NULL; switch (curve_type) { case CURVE_LINEAR: c = new LinearCurve(); break; case CURVE_AUTOSPLINE: c = new AutoSplineCurve(); break; case CURVE_LINE: c = new LineCurve(); break; } this->curves->insert(curve, c); } while ((curve = strtok(NULL, ":")) != NULL); free(cn); this->ml = ml; } Event::~Event() { free(this->title); /* free the hash tables for the curves */ if (this->curves != NULL) { this->curves->destroy_values(); delete this->curves; this->curves = NULL; } } void Event::add_curvepoint(Hashtable *markers, const char *element, const char **attr) { float timeval = -1.0f; /* first we need to grab the time */ int i = 0; while (attr[i]) { if (strcmp(attr[i], "time") == 0) { timeval = parse_time(markers, attr[i + 1]); break; } i += 2; } if (timeval == -1.0f) { throw new FatalException(element, "Missing time= attribute"); } if (strcmp(element, "start") == 0) { if (this->start != -1.0f) { throw new FatalException(element, "Multiple tags"); } this->start = timeval; } if (strcmp(element, "end") == 0) { if (this->stop != -1.0f) { throw new FatalException(element, "Multiple tags"); } this->stop = timeval; } i = 0; while (attr[i]) { if (strcmp(attr[i], "time") == 0) { i += 2; continue; } if (this->curves == NULL) { throw new FatalException(attr[i], "No such curve!"); } Curve *c = (Curve *)this->curves->lookup(attr[i]); if (c == NULL) { throw new FatalException(attr[i], "No such curve!"); } c->add_curvepoint(timeval, atof(attr[i + 1])); i += 2; } } void Event::end_curvedata() { if (this->start == -1.0f) { throw new FatalException("Missing tag!"); } if (this->stop == -1.0f) { throw new FatalException("Missing tag!"); } if (this->curves != NULL) { this->curves->finish_curvedata(this->start, this->stop); } } void Event::start_effect() {} void Event::draw_scene(float progress) {} void Event::end_effect() {} float Event::get_val(char *attr_name, float progress) { if (this->curves == NULL) { throw new FatalException(attr_name, "No curves defined in effect!"); } Curve *c = (Curve *)this->curves->lookup(attr_name); if (c == NULL) { throw new FatalException(attr_name, "No such curve defined!"); } return c->get_value(progress); } float Event::parse_time(Hashtable *markers, const char *timestr) { if (timestr[0] < '0' || timestr[0] > '9') { /* a marker name -- does it contain a '-' or '+'? */ char buf[256]; float adj; strcpy(buf, timestr); unsigned int p = strcspn(buf, "-+"); if (p == strlen(buf)) { adj = 0.0f; } else { if (buf[p] == '+') { adj = atof(buf + p + 1); } else { adj = atof(buf + p); } buf[p] = '\0'; } void *f = markers->lookup(buf); if (f == NULL) { throw new FatalException(buf, "No such marker."); } return *((float *)f) + adj; } else { return atof(timestr); } } #endif amoeba-1.1.orig/main/shadowrecthandler.cpp0100644000000000000000000000276407474453112017406 0ustar rootroot#include #include #include #include #ifdef WIN32 #include #endif #include #ifndef M_PI #define M_PI 3.14159265358979323846264 #endif #include "main/shadowrecthandler.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP ShadowRectHandler::ShadowRectHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "alpha") { } ShadowRectHandler::~ShadowRectHandler() { } void ShadowRectHandler::start_effect() { } void ShadowRectHandler::draw_scene(float progress) { const float alpha = this->get_val("alpha", progress); if (alpha == 1.0f) { glDisable(GL_BLEND); } else { glColor4f(0.0f, 0.0f, 0.0f, alpha); glEnable(GL_BLEND); glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); } glEnable(GL_STENCIL_TEST); glStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFFL); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 10.0f); glBegin(GL_QUADS); glVertex3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glDisable(GL_STENCIL_TEST); } void ShadowRectHandler::end_effect() { } #endif amoeba-1.1.orig/main/piprecalc.h0100644000000000000000000000046307467044422015310 0ustar rootroot#ifndef _PIPRECALC_H #define _PIPRECALC_H 1 #include "opengl/texture.h" #include "opengl/glwindow.h" class PiPrecalc { public: PiPrecalc(GLWindow *win); ~PiPrecalc(); void update(float progress); protected: int last_status; GLWindow *win; Texture *font; }; #endif /* !defined(_PIPRECALC_H) */ amoeba-1.1.orig/main/win32-config/0040755000000000000000000000000007557051141015376 5ustar rootrootamoeba-1.1.orig/main/win32-config/resource.h0100644000000000000000000000057007476443222017402 0ustar rootroot#define IDD_CONFIG 101 #define IDB_LOGO 103 #define IDC_OK 1001 #define IDC_CANCEL 1002 #define IDC_WINDOWMODE 1003 #define IDC_SOUND 1004 #define IDC_SCREENMODE 1006 #define IDC_ZBUFFER 1016 #define IDC_STATIC -1 amoeba-1.1.orig/main/win32-config/dialog.rc0100644000000000000000000000226107476506626017176 0ustar rootroot#include #include "resource.h" IDD_CONFIG DIALOG DISCARDABLE 0, 0, 265, 105 STYLE DS_SETFOREGROUND | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION CAPTION "Excess demo configuration (Win32)" FONT 8, "MS Sans Serif" BEGIN ICON 0,IDC_STATIC,10,10,20,20 // logo CONTROL IDB_LOGO,"Static",SS_BITMAP,3,3,84,99 // screen mode LTEXT "Screen mode:",IDC_STATIC,95,19,53,8 COMBOBOX IDC_SCREENMODE,150,16,110,80,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP // window mode LTEXT "Window mode:",IDC_STATIC,95,34,53,8 COMBOBOX IDC_WINDOWMODE,150,31,110,80,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP // z buffer LTEXT "Z-buffer:",IDC_STATIC,95,49,30,8 COMBOBOX IDC_ZBUFFER,150,46,110,80,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP // sound device LTEXT "Sound device:",IDC_STATIC,95,64,53,8 COMBOBOX IDC_SOUND,150,61,110,80,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP DEFPUSHBUTTON "Ninja!",IDC_OK,123,85,50,15 PUSHBUTTON "Samurai-wuss",IDC_CANCEL,183,85,50,15 END 0 ICON DISCARDABLE "main/win32-config/excess.ico" amoeba-1.1.orig/main/win32-config/excess.ico0100600000000000000000000000627607333607044017365 0ustar rootroot ¨ ( @ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿamoeba-1.1.orig/main/win32-config/win32-config.h0100644000000000000000000000160307477713346017766 0ustar rootroot#ifndef _WIN32_CONFIG #define _WIN32_CONFIG 1 #include #include "math/array.h" /* a singleton class, to fit well into Win32s stupidness ;-) */ class Win32Config { private: LPGUID sound; bool fullscreen; int mode; int zbuffer; Win32Config(); public: static Win32Config *instance(); //~Win32Config(); void dialog(); void set_fullscreen(bool fullscreen) { this->fullscreen = fullscreen; } bool get_fullscreen() { return fullscreen; } void set_sound(LPGUID sound) { this->sound = sound; } LPGUID get_sound() { return sound; } void set_mode(int mode) { this->mode = mode; } int get_mode() { return mode; } void set_zbuffer(int zbuffer) { this->zbuffer = zbuffer; } int get_zbuffer() { return zbuffer; } }; struct dsenum_pass_struct { HWND sound_list; Array *sound_guids; }; #endif /* !defined(_WIN32_CONFIG) */ amoeba-1.1.orig/main/win32-config/win32-config.cpp0100644000000000000000000001246107477713340020317 0ustar rootroot#include #include #include #include "resource.h" #include "win32-config.h" #include "image/image.h" #include typedef BOOL (CALLBACK *LPDSENUMCALLBACKA)(LPGUID, LPCSTR, LPCSTR, LPVOID); typedef HRESULT (WINAPI *DIRECTSOUNDENUMERATEA) (LPDSENUMCALLBACKA, LPVOID); LRESULT CALLBACK config_callback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); BOOL CALLBACK enum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) { struct dsenum_pass_struct *dps = (struct dsenum_pass_struct *)lpContext; SendMessage(dps->sound_list, CB_ADDSTRING, 0, (LPARAM)lpcstrDescription); dps->sound_guids->add_end(lpGuid); return true; } Win32Config *Win32Config::instance() { static Win32Config *instance = NULL; if (instance == NULL) { instance = new Win32Config(); } return instance; } Win32Config::Win32Config() { } void Win32Config::dialog() { HRESULT result = DialogBox(GetModuleHandle(NULL), (LPCTSTR)IDD_CONFIG, NULL, (DLGPROC)config_callback); if (result != IDC_OK) PostQuitMessage(1); } LRESULT CALLBACK config_callback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static int best_mode = 0; static Array modes; static Array sound_guids; int count = 0; int i; HWND screenmode_list; switch (message) { case WM_INITDIALOG: DEVMODE mode; screenmode_list = GetDlgItem(hDlg, IDC_SCREENMODE); while (EnumDisplaySettings(NULL, count, &mode)) { char buf[256]; if (mode.dmBitsPerPel <= 8) { count++; continue; } if (mode.dmDisplayFrequency == 0) { sprintf(buf, "%ldx%ldx%ldbpp", mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel); } else { sprintf(buf, "%ldx%ldx%ldbpp@%ldhz", mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel, mode.dmDisplayFrequency); } if ((mode.dmPelsWidth == 640) && (mode.dmPelsHeight == 480) && (mode.dmBitsPerPel > 8)) { best_mode = modes.num_elems(); } SendMessage(screenmode_list, CB_ADDSTRING, 0, (LPARAM)buf); modes.add_end(count++); } SendMessage(screenmode_list, CB_SETCURSEL, best_mode, 0); { HWND zbuffer_list = GetDlgItem(hDlg, IDC_ZBUFFER); SendMessage(zbuffer_list, CB_ADDSTRING, 0, (LPARAM)"16bpp"); SendMessage(zbuffer_list, CB_ADDSTRING, 0, (LPARAM)"24bpp"); SendMessage(zbuffer_list, CB_ADDSTRING, 0, (LPARAM)"32bpp"); SendMessage(zbuffer_list, CB_SETCURSEL, 2, 0); } { HWND windowmode_list = GetDlgItem(hDlg, IDC_WINDOWMODE); SendMessage(windowmode_list, CB_ADDSTRING, 0, (LPARAM)"Fullscreen"); SendMessage(windowmode_list, CB_ADDSTRING, 0, (LPARAM)"Windowed"); SendMessage(windowmode_list, CB_SETCURSEL, 0, 0); } { HWND sound_list = GetDlgItem(hDlg, IDC_SOUND); /* check that we can load DirectSound, and enumerate output devices */ HMODULE library = (HMODULE)LoadLibrary("dsound.dll"); if (library != NULL) { DIRECTSOUNDENUMERATEA dsEnum = (DIRECTSOUNDENUMERATEA)GetProcAddress(library, "DirectSoundEnumerateA"); if (dsEnum != NULL) { struct dsenum_pass_struct dps; dps.sound_list = sound_list; dps.sound_guids = &sound_guids; dsEnum(enum_callback, &dps); } } /* if the only output device is "Primary Output Device", nuke it :-) */ if (sound_guids.num_elems() == 1 && sound_guids[0] == NULL) { SendMessage(sound_list, CB_DELETESTRING, (WPARAM)0, 0); sound_guids[0] = (LPGUID)-1; } else { sound_guids.add_end((LPGUID)-1); } SendMessage(sound_list, CB_ADDSTRING, 0, (LPARAM)"No sound"); SendMessage(sound_list, CB_SETCURSEL, 0, 0); } /* load the logo */ { Image *logo = load_image("launcherlogo.png"); BITMAPINFOHEADER hdr = { sizeof(BITMAPINFOHEADER), logo->get_width(), -logo->get_height(), 1, logo->get_bpp(), BI_RGB, 0, 100, 100, 0, 0 }; BITMAPINFO bmi = { hdr, { 0, 0, 0, 0 } }; HWND logo_control = GetDlgItem(hDlg, IDB_LOGO); HDC logo_dc = GetDC(logo_control); HBITMAP bmp = CreateDIBitmap(logo_dc, &hdr, CBM_INIT, logo->get_pixel_data(), &bmi, DIB_RGB_COLORS); SendMessage(logo_control, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp); ReleaseDC(hDlg, logo_dc); delete logo; } break; case WM_COMMAND: if (LOWORD(wParam) == IDC_OK) { Win32Config *c = Win32Config::instance(); HWND windowmode_list = GetDlgItem(hDlg, IDC_WINDOWMODE); i = SendMessage(windowmode_list, CB_GETCURSEL, 0, 0); c->set_fullscreen((i < 0 || i == 0)); /* handle SOUND! :-P */ HWND sound_list = GetDlgItem(hDlg, IDC_SOUND); i = SendMessage(sound_list, CB_GETCURSEL, 0, 0); if (i < 0) { c->set_sound((LPGUID)-1); } else { c->set_sound(sound_guids[i]); } screenmode_list = GetDlgItem(hDlg, IDC_SCREENMODE); i = SendMessage(screenmode_list, CB_GETCURSEL, 0, 0); if (i < 0) i = best_mode; c->set_mode(modes[i]); HWND zbuf_list = GetDlgItem(hDlg, IDC_ZBUFFER); i = SendMessage(zbuf_list, CB_GETCURSEL, 0, 0); if (i < 0) i = 2; c->set_zbuffer(16 + i * 8); EndDialog(hDlg, LOWORD(wParam)); return TRUE; } if (LOWORD(wParam) == IDC_CANCEL) { EndDialog(hDlg, LOWORD(wParam)); ExitProcess(0); return TRUE; } break; case WM_CLOSE: EndDialog(hDlg, LOWORD(wParam)); ExitProcess(0); break; } return FALSE; } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/linecurve.h��������������������������������������������������������������������0100644�0000000�0000000�00000000665�07441454406�015345� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _LINECURVE_H #define _LINECURVE_H #include "main/curve.h" class ParticlePathHandler; class LineCurve : public Curve { public: LineCurve(); ~LineCurve(); void add_curvepoint(float x, float y); void end_curvepoints(float start, float length); float get_value(float x); int get_curvetype() { return CURVE_LINE; } friend class ParticlePathHandler; protected: float base, step; }; #endif /* !defined(_LINECURVE_H) */ ���������������������������������������������������������������������������amoeba-1.1.orig/main/autosplinecurve.cpp������������������������������������������������������������0100644�0000000�0000000�00000005244�07467204624�017135� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * "Automatic" (ie. you don't have to specify any extra control points) * splines, based on a standard Catmull-Rom spline, made "loopable" and * having f'''(x) = 0 all the way. */ #include "main/autosplinecurve.h" #include "demolib_prefs.h" #include "exception.h" #if DEMOLIB_MAINLOOP AutoSplineCurve::AutoSplineCurve() { this->num_points = 0; } AutoSplineCurve::~AutoSplineCurve() {} void AutoSplineCurve::add_curvepoint(float x, float y) { if (this->num_points == MAX_POINTS) throw new FatalException("Maximum number of points reached!"); /* check better for dupes later */ this->x[this->num_points] = x; this->y[this->num_points] = y; this->num_points++; } void AutoSplineCurve::end_curvepoints(float start, float length) { int i; if (this->num_points == 0) throw new FatalException("No points for auto spline!"); for (i = 0; i < this->num_points; i++) { this->x[i] -= start; this->x[i] /= length; } /* whee, O(n^2) bubblesort */ for (i = 0; i < this->num_points; i++) { for (int j = i; j < this->num_points; j++) { if (x[i] > x[j]) { float xt = x[j]; float yt = y[j]; x[j] = x[i]; y[j] = y[i]; x[i] = xt; y[i] = yt; } } } const int e = this->num_points - 1; /* now find the derivatives */ for (i = 1; i < e; i++) { const int p = i - 1, n = i + 1; deriv[i] = (y[n] - y[p]) / (x[n] - x[p]); } /* the edges are a bit special */ deriv[0] = deriv[e] = ((y[1] - y[e-1]) - (y[0] - y[e])) / ((x[e] - x[e-1]) + (x[1] - x[0])); } float AutoSplineCurve::get_value(float x) { if (this->num_points == 1) return this->y[0]; /* linear extrapolation to the left (uh-oh) */ if (x < this->x[0]) { return (this->x[0] - x) * (this->y[1] - this->y[0]) / (this->x[1] - this->x[0]); } /* just initialize these values so gcc won't complain ;-) */ float leftx = 0.0f, rightx = 0.1f, lefty = 0.0f, righty = 0.0f, leftd = 0.0f, rightd = 0.0f; /* interpolation, or extrapolation to the right */ const int e = this->num_points - 1; for (int i = 0; i < e; i++) { leftx = this->x[i]; rightx = this->x[i + 1]; if (leftx <= x && rightx >= x) { lefty = this->y[i]; righty = this->y[i + 1]; leftd = this->deriv[i]; rightd = this->deriv[i + 1]; const float len = rightx - leftx; leftd *= len; rightd *= len; break; } } const float t = (x - leftx) / (rightx - leftx); /* return (1.0f - 3.0f*t*t + 2*t*t*t) * lefty + (3.0f*t*t - 2.0f*t*t*t) * righty + (t - 2.0f*t*t + t*t*t) * leftd + (-t*t + t*t*t) * rightd; */ return (-righty - righty + rightd + leftd + lefty + lefty) * t*t*t + (-rightd + 3.0f * righty - 2.0f * leftd - 3.0f * lefty) * t*t + leftd * t + lefty; } #endif ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/factory.cpp��������������������������������������������������������������������0100644�0000000�0000000�00000000174�07407525176�015353� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include "factory.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP Factory::Factory() {} Factory::~Factory() {} #endif ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/piprecalc.cpp������������������������������������������������������������������0100644�0000000�0000000�00000007102�07502424226�015632� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * This "effect" is almost totally untimed (ie. it counts frames, not * seconds). Rationale: A faster machine will play the fades faster, * but it will also _load_ faster, so it's reasonable that it also * loads faster ;-) (If you want, do a s/rationale/excuse for being * lazy/ ;-) ) Unfortunately, vsync messes this up ;-) */ #include "main/piprecalc.h" #include #include #define PI_STRING "3.14159265358979323846264338327950288" /* ahem ;-) */ #ifndef __linux__ #define usleep(x) Sleep(x) #endif PiPrecalc::PiPrecalc(GLWindow *win) { this->win = win; this->font = texture::load("loaderfont.png"); this->font->bind(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); this->last_status = 0; } PiPrecalc::~PiPrecalc() { /* * simple fade to zero * (some drivers don't appear to like that we base ourselves * on the last frame, so we have to redraw every time here) */ for (int i = 0; i < 50; i++) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); this->font->bind(); glColor4f(1.0f, 1.0f, 1.0f, (float)(49-i) / 49.0f); glBegin(GL_QUADS); for (int j = 0; j < 37; j++) { char ch = PI_STRING[j]; int t = (ch == '.') ? 7 : (8 + (ch - '0')); glTexCoord2f((float)(t) / 32.0f, 0.0f); glVertex2f((float)(j+2) / 41.0f, 0.45f); glTexCoord2f((float)(t+1) / 32.0f, 0.0f); glVertex2f((float)(j+3) / 41.0f, 0.45f); glTexCoord2f((float)(t+1) / 32.0f, 0.9f); glVertex2f((float)(j+3) / 41.0f, 0.55f); glTexCoord2f((float)(t) / 32.0f, 0.9f); glVertex2f((float)(j+2) / 41.0f, 0.55f); } glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); this->win->flip(); usleep(1); } delete this->font; this->font = NULL; } void PiPrecalc::update(float p) { int target = (int)(p * 37.0f); for (int i = this->last_status; i < target; i++) { for (int fno = 0; fno < 7; fno++) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); this->font->bind(); /* first rewrite the text :-) */ glColor4f(1.0f, 1.0f, 1.0f, 1.0f); /* * then write every letter that we already wrote, * and last the new letter */ for (int j = 0; j <= i; j++) { char ch = PI_STRING[36 - j]; int t = (ch == '.') ? 7 : (8 + (ch - '0')); if (j == i) { glColor4f(1.0f, 1.0f, 1.0f, (float)(fno) / 6.0f); } glBegin(GL_QUADS); glTexCoord2f((float)(t) / 32.0f, 0.0f); glVertex2f((float)(38-j) / 41.0f, 0.45f); glTexCoord2f((float)(t+1) / 32.0f, 0.0f); glVertex2f((float)(38-j+1) / 41.0f, 0.45f); glTexCoord2f((float)(t+1) / 32.0f, 0.9f); glVertex2f((float)(38-j+1) / 41.0f, 0.55f); glTexCoord2f((float)(t) / 32.0f, 0.9f); glVertex2f((float)(38-j) / 41.0f, 0.55f); glEnd(); } glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); this->win->flip(); usleep(1); } } this->last_status = target; } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/inverthandler.h����������������������������������������������������������������0100644�0000000�0000000�00000000617�07442766432�016221� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _INVERTHANDLER_H #define _INVERTHANDLER_H #include "main/event.h" #include "opengl/texture.h" class InvertHandler : public Event { public: InvertHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~InvertHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: Texture *tex; }; #endif /* defined(_INVERTHANDLER_H) */ �����������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/objhandler.cpp�����������������������������������������������������������������0100644�0000000�0000000�00000010577�07502371162�016012� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Generic object class -- not to be used directly, but to be subclassed * by actual loaders. (For this reason, it's called ObjHandler, even though * one might call it an ObjHandlerHandler.) It handles texture loading, but * not anything else related to files. */ #include #include #include #include #ifdef WIN32 #include #endif #include #include "main/object.h" #include "main/objhandler.h" #include "math/array.h" #include "packer/file.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP ObjHandler::ObjHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Object(ml, title, elem, attr) { File *obj = load_file(attr->get_str("file")); /* * Now parse the object, line by line. Note that files are * NOT usually terminated, so for simplicity's sake, * we add a trailing ASCII 0 here. */ int length = obj->data_length(); char *data = new char[length + 1]; memcpy(data, obj->get_data(), length); data[length] = '\0'; this->split_lines(data); delete[] data; delete obj; } ObjHandler::~ObjHandler() { } void ObjHandler::split_lines(char *data) { while (*data) { /* find \n or \r\n */ char *ptr = strchr(data, '\n'); if (ptr) { *ptr = '\0'; if (ptr[-1] == '\r') ptr[-1] = '\0'; } this->parse_line(data); if (ptr) { data = ptr + 1; } else { return; } } } void ObjHandler::parse_line(char *data) { /* look at the line type */ switch (data[0]) { case 'v': switch (data[1]) { case ' ': this->parse_vertex(data + 2); break; case 't': this->parse_texcoords(data + 3); break; case 'n': this->parse_normals(data + 3); break; } break; case 'f': this->parse_faces(data + 2); break; case 'g': if (strncmp(data, "g presorted", 11) == 0) { this->pure_indices = true; } break; case '\0': case '#': default: break; /* unknown, comment, or blank line */ } } void ObjHandler::parse_vertex(char *data) { struct vertex v; if (sscanf(data, "%f %f %f", &v.x, &v.y, &v.z) != 3) throw new FatalException("Error in .obj data"); this->add_vertex(v); } void ObjHandler::parse_texcoords(char *data) { struct texcoord tc; if (sscanf(data, "%f %f", &tc.u, &tc.v) != 2) throw new FatalException("Error in .obj data"); if (this->pure_indices) this->texcoords.add_end(tc); else this->temp_texcoords.add_end(tc); } void ObjHandler::parse_normals(char *data) { struct normal n; if (sscanf(data, "%f %f %f", &n.nx, &n.ny, &n.nz) != 3) throw new FatalException("Error in .obj data"); if (this->pure_indices) this->normals.add_end(n); else this->temp_normals.add_end(n); } void ObjHandler::parse_faces(char *data) { if (this->vertices_per_face == 0) { /* determine how many groups we have */ int vpf = 1; char *ptr = strchr(data, ' '); while (ptr) { vpf++; ptr = strchr(ptr + 1, ' '); } this->vertices_per_face = vpf; } int v[4], t[4], n[4], i; for (i = 0; i < this->vertices_per_face; i++) { if (data == NULL) throw new FatalException("Error in .obj data"); v[i] = atoi(data); if (strchr(data, '/') == NULL) { if (strchr(data, ' ') == NULL) { continue; } else { data = strchr(data, ' '); } } else { data = strchr(data, '/'); } switch (data[1]) { case '/': /* no texcoord, but a normal */ data += 1; break; case ' ': /* only the vertex */ data += 2; continue; case '\0': /* end of line */ continue; default: /* a texcoord */ t[i] = atoi(data + 1); char *ptr = strchr(data, ' '); data = strchr(data + 1, '/'); if (ptr != NULL && ptr < data || data == NULL) data = ptr; if (data == NULL && ptr == NULL) continue; break; } /* finally read a normal if there is one */ switch (data[0]) { case '/': n[i] = atoi(data + 1); data = strchr(data, ' ') + 1; break; } } /* now add */ for (i = 0; i < this->vertices_per_face; i++) { this->faces.add_end(v[i] - 1); if (this->temp_texcoords.num_elems() > 0) this->texcoords.add_end(temp_texcoords[t[i] - 1]); if (this->temp_normals.num_elems() > 0) this->normals.add_end(temp_normals[n[i] - 1]); } } void ObjHandler::start_effect() { Object::start_effect(); } void ObjHandler::draw_scene(float progress) { Object::draw_scene(progress); } void ObjHandler::end_effect() { Object::end_effect(); } #endif /* DEMOLIB_MAINLOOP */ ���������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/linearcurve.cpp����������������������������������������������������������������0100644�0000000�0000000�00000004105�07467224170�016215� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include "main/linearcurve.h" #include "demolib_prefs.h" #include "exception.h" #include #if DEMOLIB_MAINLOOP LinearCurve::LinearCurve() { this->num_points = 0; } LinearCurve::~LinearCurve() {} void LinearCurve::add_curvepoint(float x, float y) { if (this->num_points == MAX_POINTS) throw new FatalException("Maximum number of points reached!"); /* check better for dupes later */ this->x[this->num_points] = x; this->y[this->num_points] = y; this->num_points++; this->pos_hint = 0; } void LinearCurve::end_curvepoints(float start, float length) { if (this->num_points == 0) throw new FatalException("No points for linear movement!"); int i; for (i = 0; i < this->num_points; i++) { this->x[i] -= start; this->x[i] /= length; } /* whee, O(n^2) bubblesort */ for (i = 0; i < this->num_points; i++) { for (int j = i; j < this->num_points; j++) { if (x[i] > x[j]) { float xt = x[j]; float yt = y[j]; x[j] = x[i]; y[j] = y[i]; x[i] = xt; y[i] = yt; } } } } float LinearCurve::get_value(float x) { if (this->num_points == 1) return this->y[0]; /* extrapolation to the left */ if (x < this->x[0]) { return (this->x[0] - x) * (this->y[1] - this->y[0]) / (this->x[1] - this->x[0]); } float leftx = 0.0f, rightx = 0.1f, lefty = 0.0f, righty = 0.0f; /* * We have so many long linear curves we'll try to optimize this a bit: * We check to see if the last used value is a usable starting point -- * if it is, we start from there, if not, we start from 0. we should * also implement a binary search really soon. ;-) This will work real * crappy if progress went backwards, but in 99% of the cases, it isn't. ;-) */ if (this->pos_hint == -1 || x > this->x[this->pos_hint]) { this->pos_hint = 0; } for (int i = this->pos_hint; i < this->num_points - 1; i++) { leftx = this->x[i]; rightx = this->x[i + 1]; lefty = this->y[i]; righty = this->y[i + 1]; if (x <= rightx) { this->pos_hint = i - 1; break; } } float t = (x - leftx) / (rightx - leftx); return lefty + (righty - lefty) * t; } #endif �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/curve.cpp����������������������������������������������������������������������0100644�0000000�0000000�00000000414�07407525176�015025� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include "curve.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP Curve::Curve() {} Curve::~Curve() {} void Curve::add_curvepoint(float x, float y) {} void Curve::end_curvepoints(float start, float length) {} float Curve::get_value(float x) { return x; } #endif ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/object.h�����������������������������������������������������������������������0100644�0000000�0000000�00000005451�07473204670�014616� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _OBJECT_H #define _OBJECT_H 1 #include "main/event.h" #include "main/mainloop.h" #include "opengl/texture.h" #include "math/array.h" #if defined(WIN32) || defined(__CYGWIN__) #include #endif #include #ifndef APIENTRY #define APIENTRY #endif /* from GLext.h */ typedef void (APIENTRY *PFNGLACTIVETEXTUREARBPROC)(GLenum texture); typedef void (APIENTRY *PFNGLCLIENTACTIVETEXTUREARBPROC)(GLenum texture); typedef void (APIENTRY *PFNGLMULTITEXCOORD2FVARBPROC)(GLenum target, const GLfloat *v); typedef void (APIENTRY *PFNGLLOCKARRAYSEXTPROC)(GLint first, GLsizei count); typedef void (APIENTRY *PFNGLUNLOCKARRAYSEXTPROC)(void); typedef void (APIENTRY *PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); struct vertex { float x, y, z; }; struct normal { float nx, ny, nz; }; struct texcoord { float u, v; }; class Object : public Event { protected: Array vertices; Array normals; Array texcoords, *ctexcoords[2]; Array faces; Array *tv; bool pure_indices; bool pretrans, precolor; int vertices_per_face; Texture *tex[2]; enum gentype { none, linmap, envmap } texgen[2]; float texstr0; bool has_multitexture; bool has_compiled_vertex_array; bool has_draw_range_elements; bool has_rescale_normal; bool additive_blend, no_zbuffer; /* texunit 1 parameters (for multitexture) */ GLenum tu1combine, tu1s0, tu1o0, tu1s1, tu1o1, tu1s2, tu1o2; /* pass 2 blending functions (for non-multitexture) */ GLenum p2sf, p2df; bool p2light; /* stencil mask, primarily for halos (0x0 not to stencil) */ int stencil_mask; /* be sure to have unit length normals for this ;-) */ bool draw_halo; float halo_length; struct vertex *halo_vert; /* for RTG compatibility */ bool inverse_rotorder; PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB; PFNGLMULTITEXCOORD2FVARBPROC glMultiTexCoord2fvARB; PFNGLLOCKARRAYSEXTPROC glLockArraysEXT; PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT; PFNGLDRAWRANGEELEMENTSEXTPROC glDrawRangeElementsEXT; void setup_drawing(float progress); virtual void draw_object(); virtual void draw_object(bool textures, bool normals); void add_vertex(const struct vertex v); void add_normal(const struct normal n); void add_texcoord(const struct texcoord tc); void add_face(const int a, const int b, const int c); void add_face(const int a, const int b, const int c, const int d); void unlock_object(); void setup_vertex_arrays(bool textures, bool normals); public: Object(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); virtual ~Object(); virtual void start_effect(); virtual void draw_scene(float progress); virtual void end_effect(); }; #endif /* !defined(_OBJECT_H) */ �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/fpshandler.h�������������������������������������������������������������������0100644�0000000�0000000�00000000653�07407525176�015501� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _FPSHANDLER_H #define _FPSHANDLER_H #include "main/event.h" #include "main/mainloop.h" #include "opengl/fpscount.h" class FPSHandler : public Event { public: FPSHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~FPSHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: bool active; FPSCounter *fps; }; #endif /* defined(_FPSHANDLER_H) */ �������������������������������������������������������������������������������������amoeba-1.1.orig/main/lighthandler.h�����������������������������������������������������������������0100644�0000000�0000000�00000000633�07407525176�016016� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _LIGHTHANDLER_H #define _LIGHTHANDLER_H #include "main/event.h" #include "main/mainloop.h" class LightHandler : public Event { public: LightHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~LightHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: bool positional; int light_num; }; #endif /* defined(_LIGHTHANDLER_H) */ �����������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/demohandler.h������������������������������������������������������������������0100644�0000000�0000000�00000000751�07415166036�015627� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _DEMOHANDLER_H #define _DEMOHANDLER_H #include "main/event.h" #include "main/mainloop.h" #include "opengl/glwindow.h" class DemoHandler : public Event { public: DemoHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~DemoHandler(); bool can_handle(char *elem); void start_effect(); void draw_scene(float progress); void end_effect(); MainLoop *ml; protected: GLWindow *win; friend class MainLoop; }; #endif /* defined(_DEMOHANDLER_H) */ �����������������������amoeba-1.1.orig/main/shadowhandler.cpp��������������������������������������������������������������0100644�0000000�0000000�00000017276�07475160050�016531� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #include #ifdef WIN32 #include #endif #include #ifndef M_PI #define M_PI 3.14159265358979323846264 #endif #include "main/shadowhandler.h" #include "math/vector.h" #include "math/matrix.h" #include "packer/file.h" #include "exception.h" #include "demolib_prefs.h" #define SHADOWLENGTH 10.0f #if DEMOLIB_MAINLOOP ShadowHandler::ShadowHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : ObjHandler(ml, title, elem, attr) { if (!this->pure_indices) throw new FatalException(elem, "Needs a presorted object!"); if (this->vertices_per_face != 3) throw new FatalException(elem, "Can only work with triangles!"); int i; for (i = 0; i < faces.num_elems(); i += 3) { struct extravertexinfo e; /* calculate the plane for the triangle */ const struct vertex &v1 = vertices[faces[i]]; const struct vertex &v2 = vertices[faces[i + 1]]; const struct vertex &v3 = vertices[faces[i + 2]]; e.a = v1.y*(v2.z-v3.z) + v2.y*(v3.z-v1.z) + v3.y*(v1.z-v2.z); e.b = v1.z*(v2.x-v3.x) + v2.z*(v3.x-v1.x) + v3.z*(v1.x-v2.x); e.c = v1.x*(v2.y-v3.y) + v2.x*(v3.y-v1.y) + v3.x*(v1.y-v2.y); e.d = -(v1.x*(v2.y*v3.z - v3.y*v2.z) + v2.x*(v3.y*v1.z - v1.y*v3.z) + v3.x*(v1.y*v2.z - v2.y*v1.z)); e.neighbours[0] = -1; e.neighbours[1] = -1; e.neighbours[2] = -1; e.visible = false; evi.add_end(e); } /* * now find the neighbours * optimization: use a vertex->face cache, which we make first :-) */ struct vfc { int face[6]; }; vfc *vfcache = new vfc[vertices.num_elems()]; for (i = 0; i < vertices.num_elems(); i++) { for (int j = 0; j < 6; j++) { vfcache[i].face[j] = -1; } } for (i = 0; i < faces.num_elems(); i++) { int v = faces[i]; bool found = true; for (int j = 0; j < 6; j++) { if (vfcache[v].face[j] == -1) { vfcache[v].face[j] = i/3; found = true; break; } } if (!found) { throw new FatalException("Vertex->face cache overload"); } } for (i = 0; i < faces.num_elems(); i += 3) { for (int ea = 0; ea < 3; ea++) { if (evi[i/3].neighbours[ea] != -1) continue; for (int k = 0; k < 6; k++) { int j = vfcache[faces[i + ea]].face[k]; if (j >= i/3) continue; if (j == -1) break; bool found = false; for (int eb = 0; eb < 3; eb++) { const int va1 = faces[i + ea]; const int va2 = faces[i + (ea+1)%3]; const int vb1 = faces[j*3 + eb]; const int vb2 = faces[j*3 + (eb+1)%3]; if ((va1 == vb1 && va2 == vb2) || (va1 == vb2 && va2 == vb1)) { evi[i/3].neighbours[ea] = j; evi[j].neighbours[eb] = i/3; found = true; break; } } if (found) break; } } } delete vfcache; this->shadowvol = new GLfloat[evi.num_elems() * 16]; } ShadowHandler::~ShadowHandler() { delete[] this->shadowvol; this->shadowvol = NULL; } void ShadowHandler::start_effect() { ObjHandler::start_effect(); } void ShadowHandler::draw_scene(float progress) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); /* translate */ const float x = this->get_val("xpos", progress); const float y = this->get_val("ypos", progress); const float z = this->get_val("zpos", progress); const float xr = this->get_val("xrot", progress); const float yr = this->get_val("yrot", progress); const float zr = this->get_val("zrot", progress); glTranslatef(x,y,z); if (this->inverse_rotorder) { glRotatef(zr, 0.0f, 0.0f, 1.0f); glRotatef(yr, 0.0f, 1.0f, 0.0f); glRotatef(xr, 1.0f, 0.0f, 0.0f); } else { glRotatef(xr, 1.0f, 0.0f, 0.0f); glRotatef(yr, 0.0f, 1.0f, 0.0f); glRotatef(zr, 0.0f, 0.0f, 1.0f); } const float scale = this->get_val("scale", progress); glScalef(scale, scale, scale); /* get the lightsource position from x/y/z */ const float lx = this->get_val("user1", progress); const float ly = this->get_val("user2", progress); const float lz = this->get_val("user3", progress); const Vector lvec(lx, ly, lz); /* get the modelview matrix */ float mv[16]; glGetFloatv(GL_MODELVIEW_MATRIX, mv); Matrix mvm(mv); /* find the lightsource position in object space */ const Vector olvec = mvm.transpose() * lvec; /* determine which faces are visible by the light */ int i; const float olx = olvec.x; const float oly = olvec.y; const float olz = olvec.z; for (i = 0; i < evi.num_elems(); i++) { evi[i].visible = (evi[i].a * olx + evi[i].b * oly + evi[i].c * olz + evi[i].d > 0); } glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glDisable(GL_FOG); glEnable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glDepthFunc(GL_LEQUAL); glEnable(GL_STENCIL_TEST); glColor4f(0.0f, 1.0f, 0.0f, 0.0f); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFFL); glStencilMask(0xFFFFFFFFL); /* generate the shadow volume */ int svi = this->do_shadow_pass(olx, oly, olz, shadowvol); glVertexPointer(4, GL_FLOAT, 0, shadowvol); if (this->has_compiled_vertex_array) { (*this->glLockArraysEXT)(0, svi); } glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); /* pass 1 - increase stencil value in the shadow */ glFrontFace(GL_CCW); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); glDrawArrays(GL_QUADS, 0, svi/4); /* pass 2 - decrease stencil value in the shadow */ glFrontFace(GL_CW); glStencilOp(GL_KEEP, GL_KEEP, GL_DECR); glDrawArrays(GL_QUADS, 0, svi/4); /* pass 3 - remove the light-culled objects from the shadow volume */ glFrontFace(GL_CCW); glBegin(GL_TRIANGLES); for (int i = 0, ii = 0; i < evi.num_elems(); i++, ii += 3) { if (evi[i].visible) continue; const struct vertex * const v1 = &this->vertices[faces[ii]]; const struct vertex * const v2 = &this->vertices[faces[ii + 1]]; const struct vertex * const v3 = &this->vertices[faces[ii + 2]]; glVertex3fv((GLfloat *)v1); glVertex3fv((GLfloat *)v2); glVertex3fv((GLfloat *)v3); } glEnd(); if (this->has_compiled_vertex_array) { (*this->glUnlockArraysEXT)(); } glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glPopAttrib(); glPopMatrix(); } void ShadowHandler::end_effect() { ObjHandler::end_effect(); } int ShadowHandler::do_shadow_pass(const float lx, const float ly, const float lz, GLfloat *shadowvol) { int svi = 0; const float lxm = lx * SHADOWLENGTH; const float lym = ly * SHADOWLENGTH; const float lzm = lz * SHADOWLENGTH; for (int i = 0, ii = 0; i < evi.num_elems(); i++, ii += 3) { if (!evi[i].visible) continue; for (int j = 0; j < 3; j++) { const int ni = evi[i].neighbours[j]; if (ni != -1 && evi[ni].visible) continue; const struct vertex * const v1 = &this->vertices[faces[ii + j]]; const struct vertex * const v2 = &this->vertices[faces[ii + (j+1)%3]]; /* calculate the two vertices in distance */ shadowvol[svi++] = v1->x; shadowvol[svi++] = v1->y; shadowvol[svi++] = v1->z; shadowvol[svi++] = 1.0f; /* equivalent to v1->x + (v1->x - lx) * SHADOWLENGTH etc. */ shadowvol[svi++] = v1->x * (SHADOWLENGTH + 1.0f) - lxm; shadowvol[svi++] = v1->y * (SHADOWLENGTH + 1.0f) - lym; shadowvol[svi++] = v1->z * (SHADOWLENGTH + 1.0f) - lzm; shadowvol[svi++] = 1.0f; /* equivalent to v2->x + (v2->x - lx) * SHADOWLENGTH etc. */ shadowvol[svi++] = v2->x * (SHADOWLENGTH + 1.0f) - lxm; shadowvol[svi++] = v2->y * (SHADOWLENGTH + 1.0f) - lym; shadowvol[svi++] = v2->z * (SHADOWLENGTH + 1.0f) - lzm; shadowvol[svi++] = 1.0f; shadowvol[svi++] = v2->x; shadowvol[svi++] = v2->y; shadowvol[svi++] = v2->z; shadowvol[svi++] = 1.0f; } } return svi; } #endif /* DEMOLIB_MAINLOOP */ ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/timerhandler.cpp���������������������������������������������������������������0100644�0000000�0000000�00000005063�07467011776�016366� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #include "main/timerhandler.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP TimerHandler::TimerHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "value") { this->digits = texture::load("digitsxp.png"); } TimerHandler::~TimerHandler() { texture::free(this->digits); this->digits = NULL; } void TimerHandler::start_effect() { } void TimerHandler::draw_scene(float progress) { char buf[10]; sprintf(buf, "%6.2f", this->get_val("value", progress)); const float pix = 1.0f / 127.0f; const float vpix = 0.2f / 9.0f; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f,1.0f,0.0f,1.0f,0.0f,10.0f); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); this->digits->bind(); glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); for (int i = 0; i < 6; i++) { int offs = 0; if (buf[i] == ' ') continue; switch (buf[i]) { case '0': offs = 0; break; case '1': offs = 6; break; case '2': offs = 12; break; case '3': offs = 18; break; case '4': offs = 24; break; case '5': offs = 30; break; case '6': offs = 36; break; case '7': offs = 42; break; case '8': offs = 48; break; case '9': offs = 54; break; case '.': offs = 60; break; case 'f': offs = 66; break; case 'p': offs = 72; break; case 's': offs = 78; break; } glTexCoord2f(offs * pix + 0.001f, 1.0f); glVertex3f(vpix * i, 0.9f, 0.0f); glTexCoord2f((offs+6) * pix, 1.0f); glVertex3f(vpix * (i+1), 0.9f, 0.0f); glTexCoord2f((offs+6) * pix, 0.0f); glVertex3f(vpix * (i+1), 1.0f, 0.0f); glTexCoord2f(offs * pix + 0.001f, 0.0f); glVertex3f(vpix * i, 1.0f, 0.0f); } glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void TimerHandler::end_effect() {} #endif �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/particlepathhandler.h����������������������������������������������������������0100644�0000000�0000000�00000002224�07443503120�017346� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _PARTICLEPATHHANDLER_H #define _PARTICLEPATHHANDLER_H 1 #include "opengl/texture.h" #include "main/object.h" #include "main/event.h" #include "main/mainloop.h" struct particle { float progress; float angle_sin, angle_cos; }; struct particle_sort { int num; float z; }; typedef void (APIENTRY *PFNGLLOCKARRAYSEXTPROC)(GLint first, GLsizei count); typedef void (APIENTRY *PFNGLUNLOCKARRAYSEXTPROC)(void); class ParticlePathHandler : public Event { protected: Texture *tex; particle *particles; int num_particles; float size, speed, radius; float last_progress, headstart, streamlength; vertex *vert; texcoord *tc; particle_sort *particle_sortdata; bool has_compiled_vertex_array; PFNGLLOCKARRAYSEXTPROC glLockArraysEXT; PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT; void spawn_particle(int i, float progress); inline float find_roty_from_deriv(float t); bool uniform; public: ParticlePathHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~ParticlePathHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); }; #endif /* !defined(_PARTICLEPATHHANDLER_H) */ ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/heightmaptunnelhandler.h�������������������������������������������������������0100644�0000000�0000000�00000001232�07435575774�020111� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _HEIGHTMAPTUNNELHANDLER_H #define _HEIGHTMAPTUNNELHANDLER_H 1 #include "main/event.h" #include "main/object.h" class HeightmapTunnelHandler : public Object { public: HeightmapTunnelHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~HeightmapTunnelHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: float zspeed, zlength; int xlod, ylod; float speedlin, freqlinx, freqliny, ampllin; float speedcirc, freqcirc, amplcirc; inline float hfunc(float xf, float yf, float u1, float u2, float u3, float u4, float progress); }; #endif /* !defined(_HEIGHTMAPTUNNELHANDLER_H) */ ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/overlayanimhandler.h�����������������������������������������������������������0100644�0000000�0000000�00000001444�07477420104�017226� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _OVERLAYANIMHANDLER_H #define _OVERLAYANIMHANDLER_H #include "main/event.h" #include "math/array.h" #include "opengl/texture.h" struct picsegment { int pos; unsigned int texnum; bool deleted; }; class OverlayAnimHandler : public Event { public: OverlayAnimHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~OverlayAnimHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); void create_subtexture(Image *img, Array *frame, int pos, int maxsize); protected: int num_frames; /* for unoptimized overlay anims */ Array tex; /* for optimized ones */ bool optimize; bool optimize_vertical; Array *frames; int xsize, ysize; }; #endif /* defined(_OVERLAYANIMHANDLER_H) */ ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/interferenceheightmaphandler.h�������������������������������������������������0100644�0000000�0000000�00000001244�07412401362�021230� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _INTERFERENCEHEIGHTMAPHANDLER_H #define _INTERFERENCEHEIGHTMAPHANDLER_H 1 #include "main/event.h" #include "main/object.h" class InterferenceHeightmapHandler : public Object { public: InterferenceHeightmapHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~InterferenceHeightmapHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); protected: int xlod, ylod; float speedlin, freqlinx, freqliny, ampllin; float speedcirc, freqcirc, amplcirc; inline float hfunc(float xf, float yf, float u1, float u2, float u3, float u4, float progress); }; #endif /* !defined(_INTERFERENCEHEIGHTMAPHANDLER_H) */ ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/overlayanimhandler.cpp���������������������������������������������������������0100644�0000000�0000000�00000023464�07502371500�017561� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Loops a few images fullscreen. Since we often want to use this for noise * etc., which often has large blanks areas, we also have an "optimize=" * parameter, splitting the image into smaller horizontal or vertical textures * (set optimize=horizontal or optimize=vertical), throwing away the blank * ones. NOTE: for speed, our definition of "blank" is "the first 16x4 pixels * are totally transparent" (4x16 for optimize=vertical). Needless to say, * optimize= as it is today is quite bad for more complex overlays, but it's * to speed up Amoeba anyway (full 512x512 textures eats fillrate and perhaps * even more important, texture RAM) -- we'll make something more complex * later :-) * * The splitting is quite dumb (just split the image into 16-pixel lumps and * check for "emptiness"), but it should be quick, and as soon you remove the * "hey, let's destroy the framerate by loading 25MB of noise textures" problem * it all doesn't matter anyhow. :-) Optimized animation frames must be a * multiple of 16 pixels the "optimized" way, and all textures must be of equal * size then. * * Unfortunately, we get a "kink" if we free all the small textures at once -- * therefore, we introduce delete=, which is kind of a hack... If it's over 0, * we delete a texture after drawing it. If you try to use a texture/frame that * is deleted, you'll get an exception :-) This can be quite tricky to get * right, unfortunately, and it doesn't help that much -- but it helps. An * alternative would simply be never clearing it up, which isn't really that * bad :-) */ #include #include #include #ifdef WIN32 #include #endif #include #include "main/overlayanimhandler.h" #include "exception.h" #include "demolib_prefs.h" #include "opengl/texture.h" #if DEMOLIB_MAINLOOP OverlayAnimHandler::OverlayAnimHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "num:alpha:delete") { const char *imgbase = attr->get_str("imgbase"); const char *imgsuffix = attr->get_str("imgsuffix"); this->num_frames = attr->get_int("num"); if (attr->exists("optimize")) { this->optimize = true; char *optimize_dir = attr->get_str("optimize"); if (strcmp(optimize_dir, "vertical") == 0) { this->optimize_vertical = true; } else if (strcmp(optimize_dir, "horizontal") == 0) { this->optimize_vertical = false; } else { throw new FatalException(elem, "optimize= must be `horizontal' or `vertical'!"); } this->frames = new Array[this->num_frames]; } GLint maxsize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize); char filename[256]; for (int i = 0; i < num_frames; i++) { sprintf(filename, "%s%02d%s", imgbase, i, imgsuffix); if (optimize) { Image *img = load_image(filename); if (i == 0) { this->xsize = img->get_width(); this->ysize = img->get_height(); if ((this->xsize % 16 != 0) || (this->ysize % 16 != 0)) { throw new FatalException(filename, "Dimensions must be a multiple of 16!"); } } else { if (img->get_width() != xsize || img->get_height() != ysize) { throw new FatalException(filename, "All frames must have equal dimensions!"); } } if (img->get_bpp() != 16 && img->get_bpp() != 32) { throw new FatalException(filename, "Must be 16bpp or 32bpp!"); } int bs = img->get_bpp() / 8; int bo = (img->get_bpp() == 32) ? 3 : 1; unsigned char *ptr = img->get_pixel_data(); /* simplest to split the loop this way :-) (yes, I use goto. :-P) */ if (this->optimize_vertical) { for (int y = 0; y < this->ysize; y += 16) { /* check if the first four rows are empty */ for (int ly = y; ly < y + 4; ly++) { for (int lx = 0; lx < 16; lx++) { if (ptr[(ly * xsize + lx) * bs + bo] != 0x00) { goto nonempty_vert; } } } continue; nonempty_vert: this->create_subtexture(img, &(frames[i]), y, maxsize); } } else { for (int x = 0; x < this->xsize; x += 16) { /* check if the first four rows are empty */ for (int ly = 0; ly < 4; ly++) { for (int lx = x; lx < x + 16; lx++) { if (ptr[(ly * xsize + lx) * bs + bo] != 0x00) { goto nonempty_horiz; } } } continue; nonempty_horiz: this->create_subtexture(img, &(frames[i]), x, maxsize); } } delete img; } else { this->tex.add_end(texture::load(filename)); } } } OverlayAnimHandler::~OverlayAnimHandler() { if (this->optimize) { /* it seems to be slightly quicker to free many textures at once :-) */ Array texnums; for (int i = 0; i < this->num_frames; i++) { for (int j = 0; j < this->frames[i].num_elems(); j++) { if (!this->frames[i][j].deleted) { texnums.add_end(this->frames[i][j].texnum); } } } if (texnums.num_elems() > 0) { glDeleteTextures(texnums.num_elems(), texnums.get_array()); } delete[] this->frames; } else { for (int i = 0; i < this->num_frames; i++) { texture::free(this->tex[i]); this->tex[i] = NULL; } } } void OverlayAnimHandler::start_effect() { } void OverlayAnimHandler::draw_scene(float progress) { int num = (int)(floor(this->get_val("num", progress))) % this->num_frames; float alpha = this->get_val("alpha", progress); if (alpha <= 0.0f) return; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); if (this->optimize) { glOrtho(0.0f, (float)(this->xsize), (float)(this->ysize), 0.0f, 0.0f, 1.0f); } else { glOrtho(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f); } glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, alpha); if (this->optimize) { bool delete_now = (this->get_val("delete", progress) >= 0.0f); for (int i = 0; i < this->frames[num].num_elems(); i++) { if (this->frames[num][i].deleted) { throw new FatalException("Overlay frame already deleted!"); } glBindTexture(GL_TEXTURE_2D, this->frames[num][i].texnum); float xstart, ystart, xend, yend; if (this->optimize_vertical) { xstart = 0.0f; xend = (float)(this->xsize); ystart = (float)(this->frames[num][i].pos); yend = ystart + 16.0f; } else { xstart = (float)(this->frames[num][i].pos); xend = xstart + 16.0f; ystart = 0.0f; yend = (float)(this->ysize); } glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(xstart, ystart, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(xstart, yend, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(xend, yend, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(xend, ystart, 0.0f); glEnd(); } if (delete_now) { /* * it seems to be slightly quicker to free many textures at once :-) * (don't delete the current frame, we might need to show it again :-) ) */ Array texnums; for (int j = 0; j < num; j++) { for (int k = 0; k < this->frames[j].num_elems(); k++) { if (this->frames[j][k].deleted) continue; this->frames[j][k].deleted = true; texnums.add_end(this->frames[j][k].texnum); } } if (texnums.num_elems() > 0) { glDeleteTextures(texnums.num_elems(), texnums.get_array()); } } } else { this->tex[num]->bind(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glEnd(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void OverlayAnimHandler::end_effect() {} void OverlayAnimHandler::create_subtexture(Image *img, Array *frame, int pos, int maxsize) { int xsize = img->get_width(); int ysize = img->get_height(); int bs = img->get_bpp() / 8; GLenum fmt = texture::get_opengl_format(img->get_bpp()); GLenum ifmt = texture::get_opengl_internal_format(img->get_bpp()); struct picsegment ps; ps.pos = pos; ps.deleted = false; glGenTextures(1, &(ps.texnum)); glBindTexture(GL_TEXTURE_2D, ps.texnum); /* don't care about Voodoo1/2/3 not handling large enough textures ;-) */ unsigned char *ptr = img->get_pixel_data(); if (this->optimize_vertical) { glTexImage2D(GL_TEXTURE_2D, 0, ifmt, xsize, 16, 0, fmt, GL_UNSIGNED_BYTE, ptr + (pos * xsize * bs)); } else { /* instead of messing with strides etc., we just create a new copy here :-) */ unsigned char *tmpbuf = (unsigned char *)(malloc(16 * ysize * bs)); if (tmpbuf == NULL) throw new FatalException("create_subtexture", "Out of memory!"); for (int y = 0; y < ysize; y++) { memcpy(tmpbuf + (16 * y * bs), ptr + ((xsize * y + pos) * bs), 16 * bs); } glTexImage2D(GL_TEXTURE_2D, 0, ifmt, 16, ysize, 0, fmt, GL_UNSIGNED_BYTE, tmpbuf); free(tmpbuf); } /* no mipmapping, save memory and hope we don't have to minify :-) */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); frame->add_end(ps); } #endif ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/fpshandler.cpp�����������������������������������������������������������������0100644�0000000�0000000�00000001015�07407525176�016025� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include "main/fpshandler.h" #include "../exception.h" #include "../demolib_prefs.h" #if DEMOLIB_MAINLOOP FPSHandler::FPSHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, NULL) { this->fps = new FPSCounter(); } FPSHandler::~FPSHandler() { delete this->fps; this->fps = NULL; } void FPSHandler::start_effect() { this->fps->reset(); } void FPSHandler::draw_scene(float progress) { fps->draw(); } void FPSHandler::end_effect() {} #endif �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/lighthandler.cpp���������������������������������������������������������������0100644�0000000�0000000�00000003723�07407717426�016355� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #ifdef WIN32 #include #endif #include #include "main/lighthandler.h" #include "exception.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP LightHandler::LightHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "ambr:ambg:ambb:difr:difg:difb:specr:specg:specb:x:y:z:catt:latt:qatt") { this->positional = (strcmp(elem, "poslight") == 0); this->light_num = GL_LIGHT0 + attr->get_int("num"); this->layer = -50.0f; /* okay to set here, I suppose -- still a hack, though :-) */ float zero_light[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, zero_light); } LightHandler::~LightHandler() { } void LightHandler::start_effect() { glEnable(light_num); } void LightHandler::draw_scene(float progress) { GLfloat ambient[] = { this->get_val("ambr", progress), this->get_val("ambg", progress), this->get_val("ambb", progress), 1.0f }; GLfloat diffuse[] = { this->get_val("difr", progress), this->get_val("difg", progress), this->get_val("difb", progress), 1.0f }; GLfloat specular[] = { this->get_val("specr", progress), this->get_val("specg", progress), this->get_val("specb", progress), 1.0f }; GLfloat position[] = { this->get_val("x", progress), this->get_val("y", progress), this->get_val("z", progress), positional ? 1.0f : 0.0f }; GLfloat catt[] = { this->get_val("catt", progress) }; GLfloat latt[] = { this->get_val("latt", progress) }; GLfloat qatt[] = { this->get_val("qatt", progress) }; glLightfv(light_num, GL_AMBIENT, ambient); glLightfv(light_num, GL_DIFFUSE, diffuse); glLightfv(light_num, GL_SPECULAR, specular); glLightfv(light_num, GL_POSITION, position); glLightfv(light_num, GL_CONSTANT_ATTENUATION, catt); glLightfv(light_num, GL_LINEAR_ATTENUATION, latt); glLightfv(light_num, GL_QUADRATIC_ATTENUATION, qatt); } void LightHandler::end_effect() { glDisable(light_num); } #endif ���������������������������������������������amoeba-1.1.orig/main/fovhandler.h�������������������������������������������������������������������0100644�0000000�0000000�00000000573�07407525176�015504� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _FOVHANDLER_H #define _FOVHANDLER_H #include "main/event.h" #include "math/vector.h" #include "opengl/texture.h" class FOVHandler : public Event { public: FOVHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~FOVHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); }; #endif /* defined(_FOVHANDLER_H) */ �������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/autosplinecurve.h��������������������������������������������������������������0100644�0000000�0000000�00000000636�07441453770�016602� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _AUTOSPLINECURVE_H #define _AUTOSPLINECURVE_H #include "main/curve.h" class AutoSplineCurve : public Curve { protected: float deriv[256]; public: AutoSplineCurve(); ~AutoSplineCurve(); void add_curvepoint(float x, float y); void end_curvepoints(float start, float length); float get_value(float x); int get_curvetype() { return CURVE_AUTOSPLINE; } }; #endif /* !defined(_AUTOSPLINECURVE_H) */ ��������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/camerahandler.cpp��������������������������������������������������������������0100644�0000000�0000000�00000004751�07465277602�016501� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #include #ifdef WIN32 #include #include #define isnan(x) _isnan(x) #endif #include #include #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 #endif #include "math/vector.h" #include "exception.h" #include "camerahandler.h" #include "demolib_prefs.h" #if DEMOLIB_MAINLOOP CameraHandler::CameraHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "x:y:z:lx:ly:lz:zrot") { this->gravity = attr->get_float("gravity"); this->layer = -60.0f; } CameraHandler::~CameraHandler() { } void CameraHandler::start_effect() { } #define DELTA 0.01f #define MULTDELTA 100.0f void CameraHandler::draw_scene(float progress) { /* get our position */ Vector pos(this->get_val("x", progress), this->get_val("y", progress), this->get_val("z", progress)); /* determine two speeds, and thus get the acceleration */ Vector pos1(this->get_val("x", progress + DELTA), this->get_val("y", progress + DELTA), this->get_val("z", progress + DELTA)); Vector sp1 = (pos1 - pos) * MULTDELTA; Vector pos2(this->get_val("x", progress + DELTA * 2.0f), this->get_val("y", progress + DELTA * 2.0f), this->get_val("z", progress + DELTA * 2.0f)); Vector sp2 = (pos2 - pos1) * MULTDELTA; Vector acc = (sp2 - sp1) * MULTDELTA; /* * find the "left" vector, relative to the absolute up position, * and the forward component */ Vector up(0.0f, 1.0f, 0.0f); Vector left = sp1.cross_product(up).normalize(); /* * find the acceleration in the "left" direction */ float acc_proj = acc * left; /* * find the rotation by a/g */ float camrot = acos(acc_proj / this->gravity) - M_PI / 2.0f; if (left.x < 0.0f) { if (camrot < 0.0f) camrot = -camrot; } else { if (camrot > 0.0f) camrot = -camrot; } const float x = pos.x; const float y = pos.y; const float z = pos.z; const float lx = this->get_val("lx", progress); const float ly = this->get_val("ly", progress); const float lz = this->get_val("lz", progress); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (camrot > -M_PI && camrot < M_PI && !isnan(camrot)) { gluLookAt(x, y, z, lx, ly, lz, sin(camrot), cos(camrot), 0.0f); } else { gluLookAt(x, y, z, lx, ly, lz, 0.0f, 1.0f, 0.0f); } glTranslatef(x, y, z); glRotatef(this->get_val("zrot", progress), lx - x, ly - y, lz - z); glTranslatef(-x, -y, -z); } void CameraHandler::end_effect() {} #endif �����������������������amoeba-1.1.orig/main/foghandler.cpp�����������������������������������������������������������������0100644�0000000�0000000�00000001763�07475437574�016033� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #ifdef WIN32 #include #endif #include #include "main/foghandler.h" #include "exception.h" #include "demolib_prefs.h" #ifndef M_PI #define M_PI 3.141592653589793238462643383279502 #endif #if DEMOLIB_MAINLOOP FogHandler::FogHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, "start:end:r:g:b:a") { } FogHandler::~FogHandler() { } void FogHandler::start_effect() { glEnable(GL_FOG); glHint(GL_FOG_HINT, GL_FASTEST); glFogi(GL_FOG_MODE, GL_LINEAR); } void FogHandler::draw_scene(float progress) { GLfloat fog_color[] = { this->get_val("r", progress), this->get_val("g", progress), this->get_val("b", progress), this->get_val("a", progress) }; glFogf(GL_FOG_START, this->get_val("start", progress)); glFogf(GL_FOG_END, this->get_val("end", progress)); glFogfv(GL_FOG_COLOR, fog_color); } void FogHandler::end_effect() { glDisable(GL_FOG); } #endif �������������amoeba-1.1.orig/main/linux-config/������������������������������������������������������������������0040755�0000000�0000000�00000000000�07557051141�015573� 5����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/linux-config/linux-config.h����������������������������������������������������0100644�0000000�0000000�00000005553�07466602760�020363� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _LINUX_CONFIG_H #define _LINUX_CONFIG_H 1 #include #include #include "util/hashtable.h" class LinuxConfig { public: LinuxConfig(); void show(int *argc, char ***argv, Hashtable *attr_hash); private: GdkPixmap* (*_gdk_pixmap_new)(GdkWindow*, gint, gint, gint); void (*_gdk_pixmap_unref)(GdkPixmap*); GdkGC* (*_gdk_gc_new)(GdkDrawable*); void (*_gdk_gc_unref)(GdkGC*); void (*_gdk_rgb_init)(void); void (*_gdk_draw_rgb_32_image)(GdkDrawable *, GdkGC *, gint, gint, gint, gint, GdkRgbDither, guchar *, gint); GtkWidget* (*_gtk_alignment_new)(gfloat, gfloat, gfloat, gfloat); void (*_gtk_box_pack_start)(GtkBox*, GtkWidget*, gboolean, gboolean, guint); GtkWidget* (*_gtk_button_new_with_label)(const gchar*); void (*_gtk_container_add)(GtkContainer*, GtkWidget*); void (*_gtk_container_set_border_width)(GtkContainer*, guint); GtkWidget* (*_gtk_hbox_new)(gboolean, gint); GtkWidget* (*_gtk_label_new)(const gchar*); void (*_gtk_label_set_justify)(GtkLabel*, GtkJustification); gint (*_gtk_main_iteration_do)(gboolean); void (*_gtk_main_quit)(void); void (*_gtk_menu_append)(GtkMenu*, GtkWidget*); GtkWidget* (*_gtk_menu_get_active)(GtkMenu*); GtkWidget* (*_gtk_menu_item_new_with_label)(const gchar*); GtkWidget* (*_gtk_menu_new)(void); void (*_gtk_misc_set_alignment)(GtkMisc*, gfloat, gfloat); gpointer (*_gtk_object_get_data)(GtkObject*, const gchar*); void (*_gtk_object_set_data)(GtkObject*, const gchar*, gpointer); void (*_gtk_object_set_data_full)(GtkObject*, const gchar*, gpointer, GtkDestroyNotify); GtkWidget* (*_gtk_option_menu_new)(void); void (*_gtk_option_menu_set_history)(GtkOptionMenu*, guint); void (*_gtk_option_menu_set_menu)(GtkOptionMenu*, GtkWidget*); GtkWidget* (*_gtk_pixmap_new)(GdkPixmap*, GdkBitmap*); guint (*_gtk_signal_connect)(GtkObject*, const gchar*, GtkSignalFunc, gpointer); void (*_gtk_signal_disconnect)(GtkObject*, guint); void (*_gtk_table_attach)(GtkTable*, GtkWidget*, guint, guint, guint, guint, GtkAttachOptions, GtkAttachOptions, guint, guint); GtkWidget* (*_gtk_table_new)(guint, guint, gboolean); void (*_gtk_table_set_col_spacings)(GtkTable*, guint); GtkWidget* (*_gtk_vbox_new)(gboolean, gint); void (*_gtk_widget_destroy)(GtkWidget*); GdkVisual* (*_gtk_widget_get_visual)(GtkWidget*); void (*_gtk_widget_hide)(GtkWidget*); void (*_gtk_widget_ref)(GtkWidget*); void (*_gtk_widget_show)(GtkWidget*); void (*_gtk_widget_unref)(GtkWidget*); GtkWidget* (*_gtk_window_new)(GtkWindowType); void (*_gtk_window_set_modal)(GtkWindow*, gboolean); void (*_gtk_window_set_policy)(GtkWindow*, gint, gint, gint); void (*_gtk_window_set_position)(GtkWindow*, GtkWindowPosition); void (*_gtk_window_set_title)(GtkWindow*, const gchar*); void (*_gtk_init)(int*, char ***); void (*_gtk_main)(void); void (*_gtk_set_locale)(void); void (*_gtk_exit)(gint); }; #endif /* !defined(_LINUX_CONFIG_H) */ �����������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/main/linux-config/linux-config.cpp��������������������������������������������������0100644�0000000�0000000�00000052513�07476442470�020715� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * A Linux GTK+ configuration dialog. Tries to use GTK+ using runtime * linking -- if the user hasn't got GTK+ on his/her system, we revert * to plain command line (ie. we just throw a NonFatalException and * the main loop reverts to command line :-) ). * * We use GTK+ 1.2, since it would appear most people has got that * version, and that's what GLADE outputs ;-) The code is rather messy, * but it more or less has to be that way when we use dlsym() for so * many objects (no, I don't want to link in GTK+ statically ;-) ). * Probably leaks memory badly too, but Linux will clean it up for us * and it's only a few kB anyhow, so it won't matter much for the * actual demo :-) * * FIXME: Should we support command line options even with GTK+? */ #define GTK_NO_CHECK_CASTS #include #include #include #include #include #include #include #include #include #include "image/image.h" #include "linux-config.h" #include "exception.h" #undef GTK_OBJECT #define GTK_OBJECT(object) (GtkObject*) (object) int modeline_compare(const void *a, const void *b) { XF86VidModeModeInfo *am = *((XF86VidModeModeInfo **)a); XF86VidModeModeInfo *bm = *((XF86VidModeModeInfo **)b); if (am->hdisplay < bm->hdisplay) return -1; if (am->hdisplay == bm->hdisplay) { if (am->vdisplay < bm->vdisplay) return -1; if (am->vdisplay == bm->vdisplay) return 0; return 1; } return 1; } LinuxConfig::LinuxConfig() { void *gdkh = dlopen("libgdk-1.2.so.0", RTLD_GLOBAL | RTLD_NOW); if (gdkh == NULL) throw new NonFatalException("libgdk-1.2.so.0", strerror(errno)); void *gtkh = dlopen("libgtk-1.2.so.0", RTLD_NOW); if (gtkh == NULL) throw new NonFatalException("libgtk-1.2.so.0", strerror(errno)); /* now we go through and load all the symbols we need, error-checking as we go */ #define LOAD_SYMBOL(lib, x, cast) { \ this->_ ## x = (cast)dlsym(lib ## h, #x); \ if (this->_ ## x == NULL) throw new NonFatalException(#x, strerror(errno)); \ } LOAD_SYMBOL(gdk, gdk_pixmap_new, GdkPixmap* (*)(GdkWindow*, gint, gint, gint)); LOAD_SYMBOL(gdk, gdk_pixmap_unref, void (*)(GdkPixmap*)); LOAD_SYMBOL(gdk, gdk_gc_new, GdkGC* (*)(GdkDrawable*)); LOAD_SYMBOL(gdk, gdk_gc_unref, void (*)(GdkGC*)); LOAD_SYMBOL(gdk, gdk_rgb_init, void (*)(void)); LOAD_SYMBOL(gdk, gdk_draw_rgb_32_image, void (*)(GdkDrawable *, GdkGC *, gint, gint, gint, gint, GdkRgbDither, guchar *, gint)); LOAD_SYMBOL(gtk, gtk_alignment_new, GtkWidget* (*)(gfloat, gfloat, gfloat, gfloat)); LOAD_SYMBOL(gtk, gtk_box_pack_start, void (*)(GtkBox*, GtkWidget*, gboolean, gboolean, guint)); LOAD_SYMBOL(gtk, gtk_button_new_with_label, GtkWidget* (*)(const gchar *)); LOAD_SYMBOL(gtk, gtk_container_add, void (*)(GtkContainer*, GtkWidget *)); LOAD_SYMBOL(gtk, gtk_container_set_border_width, void (*)(GtkContainer*, guint)); LOAD_SYMBOL(gtk, gtk_exit, void (*)(gint)); LOAD_SYMBOL(gtk, gtk_hbox_new, GtkWidget* (*)(gboolean, gint)); LOAD_SYMBOL(gtk, gtk_label_new, GtkWidget* (*)(const gchar*)); LOAD_SYMBOL(gtk, gtk_label_set_justify, void (*)(GtkLabel*, GtkJustification)); LOAD_SYMBOL(gtk, gtk_main_iteration_do, int (*)(gboolean)); LOAD_SYMBOL(gtk, gtk_main_quit, void (*)(void)); LOAD_SYMBOL(gtk, gtk_menu_append, void (*)(GtkMenu*, GtkWidget*)); LOAD_SYMBOL(gtk, gtk_menu_get_active, GtkWidget* (*)(GtkMenu*)); LOAD_SYMBOL(gtk, gtk_menu_item_new_with_label, GtkWidget* (*)(const gchar*)); LOAD_SYMBOL(gtk, gtk_menu_new, GtkWidget* (*)(void)); LOAD_SYMBOL(gtk, gtk_misc_set_alignment, void (*)(GtkMisc*, gfloat, gfloat)); LOAD_SYMBOL(gtk, gtk_object_get_data, gpointer (*)(GtkObject*, const gchar*)); LOAD_SYMBOL(gtk, gtk_object_set_data, void (*)(GtkObject*, const gchar*, gpointer)); LOAD_SYMBOL(gtk, gtk_object_set_data_full, void (*)(GtkObject*, const gchar*, gpointer, GtkDestroyNotify)); LOAD_SYMBOL(gtk, gtk_option_menu_new, GtkWidget* (*)(void)); LOAD_SYMBOL(gtk, gtk_option_menu_set_history, void (*)(GtkOptionMenu*, guint)); LOAD_SYMBOL(gtk, gtk_option_menu_set_menu, void (*)(GtkOptionMenu*, GtkWidget*)); LOAD_SYMBOL(gtk, gtk_pixmap_new, GtkWidget* (*)(GdkPixmap*, GdkPixmap*)); LOAD_SYMBOL(gtk, gtk_signal_connect, guint (*)(GtkObject*, const gchar*, GtkSignalFunc, gpointer)); LOAD_SYMBOL(gtk, gtk_signal_disconnect, void (*)(GtkObject*, guint)); LOAD_SYMBOL(gtk, gtk_table_attach, void (*)(GtkTable*, GtkWidget*, guint, guint, guint, guint, GtkAttachOptions, GtkAttachOptions, guint, guint)); LOAD_SYMBOL(gtk, gtk_table_new, GtkWidget* (*)(guint, guint, gboolean)); LOAD_SYMBOL(gtk, gtk_table_set_col_spacings, void (*)(GtkTable*, guint)); LOAD_SYMBOL(gtk, gtk_vbox_new, GtkWidget* (*)(gboolean, gint)); LOAD_SYMBOL(gtk, gtk_widget_destroy, void (*)(GtkWidget*)); LOAD_SYMBOL(gtk, gtk_widget_get_visual, GdkVisual* (*)(GtkWidget*)); LOAD_SYMBOL(gtk, gtk_widget_hide, void (*)(GtkWidget*)); LOAD_SYMBOL(gtk, gtk_widget_ref, void (*)(GtkWidget*)); LOAD_SYMBOL(gtk, gtk_widget_show, void (*)(GtkWidget*)); LOAD_SYMBOL(gtk, gtk_widget_unref, void (*)(GtkWidget*)); LOAD_SYMBOL(gtk, gtk_window_new, GtkWidget* (*)(GtkWindowType)); LOAD_SYMBOL(gtk, gtk_window_set_modal, void (*)(GtkWindow*, gboolean)); LOAD_SYMBOL(gtk, gtk_window_set_policy, void (*)(GtkWindow*, gint, gint, gint)); LOAD_SYMBOL(gtk, gtk_window_set_position, void (*)(GtkWindow*, GtkWindowPosition)); LOAD_SYMBOL(gtk, gtk_window_set_title, void (*)(GtkWindow*, const gchar*)); LOAD_SYMBOL(gtk, gtk_init, void (*)(int*, char ***)); LOAD_SYMBOL(gtk, gtk_main, void (*)(void)); LOAD_SYMBOL(gtk, gtk_set_locale, void (*)(void)); } /* this is largely GLADE-generated code, but modified for the dl */ void LinuxConfig::show(int *argc, char ***argv, Hashtable *attr_hash) { /* * open an X connection to enumerate resolutions and visuals * (code duplication from glwindow.cpp, not good) */ XF86VidModeModeInfo **modes; Display *dpy = XOpenDisplay(0); int screen = DefaultScreen(dpy); (*_gtk_set_locale) (); (*_gtk_init) (argc, argv); GtkWidget *config; GtkWidget *alignment1; GtkWidget *vbox2; GtkWidget *hbox2; GtkWidget *pixmap1; GtkWidget *table2; GtkWidget *mode_label; GtkWidget *vis_label; GtkWidget *res_menu; GtkWidget *res_menu_menu; GtkWidget *glade_menuitem; GtkWidget *fullscreenmenu; GtkWidget *fullscreenmenu_menu; GtkWidget *visualmenu; GtkWidget *visualmenu_menu; GtkWidget *sound_label; GtkWidget *soundmenu; GtkWidget *soundmenu_menu; GtkWidget *res_label; GtkWidget *spacefiller1; GtkWidget *spacefiller2; GtkWidget *hbox4; GtkWidget *ok; GdkPixmap *gdkpixmap; Image *logo; int w, h, bpp; unsigned char *ptr; GdkGC *gc; config = (*_gtk_window_new) (GTK_WINDOW_DIALOG); (*_gtk_object_set_data) (GTK_OBJECT (config), "config", config); (*_gtk_window_set_title) (GTK_WINDOW (config), "Excess demo configuration (GLX/X11)"); (*_gtk_window_set_position) (GTK_WINDOW (config), GTK_WIN_POS_CENTER); (*_gtk_window_set_modal) (GTK_WINDOW (config), TRUE); (*_gtk_window_set_policy) (GTK_WINDOW (config), FALSE, FALSE, FALSE); alignment1 = (*_gtk_alignment_new) (0.5, 0.5, 1, 1); (*_gtk_widget_ref) (alignment1); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "alignment1", alignment1, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (alignment1); (*_gtk_container_add) (GTK_CONTAINER (config), alignment1); vbox2 = (*_gtk_vbox_new) (FALSE, 0); (*_gtk_widget_ref) (vbox2); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "vbox2", vbox2, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (vbox2); (*_gtk_container_add) (GTK_CONTAINER (alignment1), vbox2); hbox2 = (*_gtk_hbox_new) (FALSE, 10); (*_gtk_widget_ref) (hbox2); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "hbox2", hbox2, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (hbox2); (*_gtk_box_pack_start) (GTK_BOX (vbox2), hbox2, TRUE, TRUE, 0); (*_gtk_container_set_border_width) (GTK_CONTAINER (hbox2), 5); /* * Get the logo from a PNG -- what idiots made it so we can't just get a * GdkPixmap directly from a raw buffer? */ logo = load_image("launcherlogo.png"); w = logo->get_width(); h = logo->get_height(); bpp = logo->get_bpp(); ptr = logo->get_pixel_data(); if (bpp != 32) throw new NonFatalException("Launcher logo must be 32bpp"); gdkpixmap = (*_gdk_pixmap_new) (NULL, w, h, ((*_gtk_widget_get_visual) (config))->depth); gc = (*_gdk_gc_new) (gdkpixmap); (*_gdk_rgb_init) (); (*_gdk_draw_rgb_32_image) (gdkpixmap, gc, 0, 0, w, h, GDK_RGB_DITHER_NONE, ptr, w * 4); pixmap1 = (*_gtk_pixmap_new) (gdkpixmap, NULL); (*_gdk_gc_unref) (gc); (*_gdk_pixmap_unref) (gdkpixmap); delete logo; (*_gtk_widget_ref) (pixmap1); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "pixmap1", pixmap1, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (pixmap1); (*_gtk_box_pack_start) (GTK_BOX (hbox2), pixmap1, FALSE, TRUE, 0); table2 = (*_gtk_table_new) (6, 2, FALSE); (*_gtk_widget_ref) (table2); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "table2", table2, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (table2); (*_gtk_box_pack_start) (GTK_BOX (hbox2), table2, TRUE, FALSE, 0); (*_gtk_table_set_col_spacings) (GTK_TABLE (table2), 7); mode_label = (*_gtk_label_new) ("Window mode:"); (*_gtk_widget_ref) (mode_label); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "mode_label", mode_label, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (mode_label); (*_gtk_table_attach) (GTK_TABLE (table2), mode_label, 0, 1, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); (*_gtk_label_set_justify) (GTK_LABEL (mode_label), GTK_JUSTIFY_LEFT); (*_gtk_misc_set_alignment) (GTK_MISC (mode_label), 0, 0.5); vis_label = (*_gtk_label_new) ("OpenGL visual:"); (*_gtk_widget_ref) (vis_label); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "vis_label", vis_label, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (vis_label); (*_gtk_table_attach) (GTK_TABLE (table2), vis_label, 0, 1, 3, 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); (*_gtk_label_set_justify) (GTK_LABEL (vis_label), GTK_JUSTIFY_LEFT); (*_gtk_misc_set_alignment) (GTK_MISC (vis_label), 0, 0.5); res_menu = (*_gtk_option_menu_new) (); (*_gtk_widget_ref) (res_menu); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "res_menu", res_menu, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (res_menu); (*_gtk_table_attach) (GTK_TABLE (table2), res_menu, 1, 2, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); /* * enumerate through all the resolutions, then sort */ { int modeNum; int selected = 0; XF86VidModeGetAllModeLines(dpy, screen, &modeNum, &modes); qsort(modes, modeNum, sizeof(XF86VidModeModeInfo *), modeline_compare); res_menu_menu = (*_gtk_menu_new) (); for (int i = 0; i < modeNum; i++) { char buf[32]; sprintf(buf, "%ux%u", modes[i]->hdisplay, modes[i]->vdisplay); glade_menuitem = (*_gtk_menu_item_new_with_label) (buf); (*_gtk_widget_show) (glade_menuitem); (*_gtk_menu_append) (GTK_MENU (res_menu_menu), glade_menuitem); sprintf(buf, "%u", modes[i]->hdisplay); (*_gtk_object_set_data) (GTK_OBJECT (glade_menuitem), strdup("xres"), strdup(buf)); sprintf(buf, "%u", modes[i]->vdisplay); (*_gtk_object_set_data) (GTK_OBJECT (glade_menuitem), strdup("yres"), strdup(buf)); if (modes[i]->hdisplay == 640 && modes[i]->vdisplay == 480) { selected = i; } } (*_gtk_option_menu_set_menu) (GTK_OPTION_MENU (res_menu), res_menu_menu); (*_gtk_option_menu_set_history) (GTK_OPTION_MENU (res_menu), selected); XFree(modes); } fullscreenmenu = (*_gtk_option_menu_new) (); (*_gtk_widget_ref) (fullscreenmenu); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "fullscreenmenu", fullscreenmenu, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (fullscreenmenu); (*_gtk_table_attach) (GTK_TABLE (table2), fullscreenmenu, 1, 2, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); fullscreenmenu_menu = (*_gtk_menu_new) (); glade_menuitem = (*_gtk_menu_item_new_with_label) ("Fullscreen"); (*_gtk_object_set_data) (GTK_OBJECT (glade_menuitem), strdup("fullscreen"), strdup("yes")); (*_gtk_widget_show) (glade_menuitem); (*_gtk_menu_append) (GTK_MENU (fullscreenmenu_menu), glade_menuitem); glade_menuitem = (*_gtk_menu_item_new_with_label) ("Windowed"); (*_gtk_object_set_data) (GTK_OBJECT (glade_menuitem), strdup("fullscreen"), strdup("no")); (*_gtk_widget_show) (glade_menuitem); (*_gtk_menu_append) (GTK_MENU (fullscreenmenu_menu), glade_menuitem); (*_gtk_option_menu_set_menu) (GTK_OPTION_MENU (fullscreenmenu), fullscreenmenu_menu); (*_gtk_option_menu_set_history) (GTK_OPTION_MENU (fullscreenmenu), 0); /* * now find all the visuals available, sort out the useless ones, and * show them in the dialog */ visualmenu = (*_gtk_option_menu_new) (); (*_gtk_widget_ref) (visualmenu); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "visualmenu", visualmenu, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (visualmenu); (*_gtk_table_attach) (GTK_TABLE (table2), visualmenu, 1, 2, 3, 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); visualmenu_menu = (*_gtk_menu_new) (); { XVisualInfo tmplate; int nret, usable = 0; int bestid = 0, bestbpp = 0, bestdepth = 0; tmplate.screen = screen; XVisualInfo *xvi = XGetVisualInfo(dpy, VisualScreenMask, &tmplate, &nret); if (xvi == NULL) throw new FatalException("No usable visuals!"); for (int i = 0; i < nret; i++) { int has_gl, has_db, stencil_bpp, bpp, depth; char buf[256]; /* first check for doublebuffered GL */ if (glXGetConfig(dpy, &(xvi[i]), GLX_USE_GL, &has_gl) != 0 || !has_gl) continue; if (glXGetConfig(dpy, &(xvi[i]), GLX_DOUBLEBUFFER, &has_db) != 0 || !has_db) continue; /* we also need at least 4bpp stencil */ if (glXGetConfig(dpy, &(xvi[i]), GLX_STENCIL_SIZE, &stencil_bpp) != 0 || stencil_bpp < 4) continue; if (glXGetConfig(dpy, &(xvi[i]), GLX_BUFFER_SIZE, &bpp) != 0) continue; if (glXGetConfig(dpy, &(xvi[i]), GLX_DEPTH_SIZE, &depth) != 0) continue; sprintf(buf, "%dbpp, %d-bits Z-buffer", bpp, depth); /* * verify that there aren't already identical (for our purposes -- * the first usable will be selected anyhow by glXChooseVisual * so we don't have to do any better guesses, I think ;-) ) * modes in the list... a bit ineffective, but doesn't matter either. * if we really want to optimize, we could make our own array * or something :-) */ bool dup = false; for (int j = 0; j < i; j++) { int has_gl2, has_db2, stencil_bpp2, bpp2, depth2; if (glXGetConfig(dpy, &(xvi[j]), GLX_USE_GL, &has_gl2) != 0 || !has_gl2) continue; if (glXGetConfig(dpy, &(xvi[j]), GLX_DOUBLEBUFFER, &has_db2) != 0 || !has_db2) continue; if (glXGetConfig(dpy, &(xvi[j]), GLX_STENCIL_SIZE, &stencil_bpp2) != 0 || stencil_bpp2 < 4) continue; if (glXGetConfig(dpy, &(xvi[j]), GLX_BUFFER_SIZE, &bpp2) != 0 || bpp2 != bpp) continue; if (glXGetConfig(dpy, &(xvi[j]), GLX_DEPTH_SIZE, &depth2) != 0 || depth2 != depth) continue; dup = true; break; } if (dup) continue; glade_menuitem = (*_gtk_menu_item_new_with_label) (buf); (*_gtk_widget_show) (glade_menuitem); (*_gtk_menu_append) (GTK_MENU (visualmenu_menu), glade_menuitem); sprintf(buf, "%lu", xvi[i].visualid); (*_gtk_object_set_data) (GTK_OBJECT (glade_menuitem), strdup("visual_id"), strdup(buf)); if (bpp > bestbpp || bpp == bestbpp && depth >= bestdepth) { bestid = usable; bestbpp = bpp; bestdepth = depth; } usable++; } if (usable == 0) throw new FatalException("No usable visuals!"); (*_gtk_option_menu_set_menu) (GTK_OPTION_MENU (visualmenu), visualmenu_menu); (*_gtk_option_menu_set_history) (GTK_OPTION_MENU (fullscreenmenu), bestid); } XCloseDisplay(dpy); sound_label = (*_gtk_label_new) ("Sound:"); (*_gtk_widget_ref) (sound_label); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "sound_label", sound_label, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (sound_label); (*_gtk_table_attach) (GTK_TABLE (table2), sound_label, 0, 1, 4, 5, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); (*_gtk_label_set_justify) (GTK_LABEL (sound_label), GTK_JUSTIFY_LEFT); (*_gtk_misc_set_alignment) (GTK_MISC (sound_label), 0, 0.5); soundmenu = (*_gtk_option_menu_new) (); (*_gtk_widget_ref) (soundmenu); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "soundmenu", soundmenu, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (soundmenu); (*_gtk_table_attach) (GTK_TABLE (table2), soundmenu, 1, 2, 4, 5, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); soundmenu_menu = (*_gtk_menu_new) (); if (access("/dev/dsp", R_OK | W_OK) == 0 || access("/dev/sound/dsp", R_OK | W_OK) == 0) { glade_menuitem = (*_gtk_menu_item_new_with_label) ("Yes"); (*_gtk_object_set_data) (GTK_OBJECT (glade_menuitem), strdup("sound"), strdup("yes")); (*_gtk_widget_show) (glade_menuitem); (*_gtk_menu_append) (GTK_MENU (soundmenu_menu), glade_menuitem); } glade_menuitem = (*_gtk_menu_item_new_with_label) ("No"); (*_gtk_object_set_data) (GTK_OBJECT (glade_menuitem), strdup("sound"), strdup("no")); (*_gtk_widget_show) (glade_menuitem); (*_gtk_menu_append) (GTK_MENU (soundmenu_menu), glade_menuitem); (*_gtk_option_menu_set_menu) (GTK_OPTION_MENU (soundmenu), soundmenu_menu); res_label = (*_gtk_label_new) ("Screen resolution:"); (*_gtk_widget_ref) (res_label); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "res_label", res_label, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (res_label); (*_gtk_table_attach) (GTK_TABLE (table2), res_label, 0, 1, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); (*_gtk_label_set_justify) (GTK_LABEL (res_label), GTK_JUSTIFY_LEFT); (*_gtk_misc_set_alignment) (GTK_MISC (res_label), 0, 0.5); spacefiller1 = (*_gtk_label_new) (""); (*_gtk_widget_ref) (spacefiller1); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "spacefiller1", spacefiller1, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (spacefiller1); (*_gtk_table_attach) (GTK_TABLE (table2), spacefiller1, 0, 1, 0, 1, (GtkAttachOptions) (0), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); (*_gtk_misc_set_alignment) (GTK_MISC (spacefiller1), 0, 0.5); spacefiller2 = (*_gtk_label_new) (""); (*_gtk_widget_ref) (spacefiller2); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "spacefiller2", spacefiller2, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (spacefiller2); (*_gtk_table_attach) (GTK_TABLE (table2), spacefiller2, 0, 1, 5, 6, (GtkAttachOptions) (0), (GtkAttachOptions) (GTK_EXPAND), 0, 0); (*_gtk_misc_set_alignment) (GTK_MISC (spacefiller2), 0, 0.5); hbox4 = (*_gtk_hbox_new) (FALSE, 0); (*_gtk_widget_ref) (hbox4); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "hbox4", hbox4, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_widget_show) (hbox4); (*_gtk_box_pack_start) (GTK_BOX (vbox2), hbox4, FALSE, FALSE, 0); (*_gtk_container_set_border_width) (GTK_CONTAINER (hbox4), 4); ok = (*_gtk_button_new_with_label) ("Ninja!"); (*_gtk_widget_ref) (ok); (*_gtk_object_set_data_full) (GTK_OBJECT (config), "ok", ok, (GtkDestroyNotify) (*_gtk_widget_unref)); (*_gtk_signal_connect) (GTK_OBJECT (ok), "clicked", GTK_SIGNAL_FUNC (*_gtk_main_quit), NULL); (*_gtk_widget_show) (ok); (*_gtk_box_pack_start) (GTK_BOX (hbox4), ok, TRUE, TRUE, 1); int dest_signal = (*_gtk_signal_connect) (GTK_OBJECT (config), "destroy", GTK_SIGNAL_FUNC (*_gtk_exit), NULL); (*_gtk_widget_show)(config); (*_gtk_main) (); /* get the parameters that were set */ GtkObject *resolution = GTK_OBJECT ((*_gtk_menu_get_active) (GTK_MENU (res_menu_menu))); attr_hash->insert("xres", (*_gtk_object_get_data) (resolution, "xres")); attr_hash->insert("yres", (*_gtk_object_get_data) (resolution, "yres")); GtkObject *fullscreen = GTK_OBJECT ((*_gtk_menu_get_active) (GTK_MENU (fullscreenmenu_menu))); attr_hash->insert("fullscreen", (*_gtk_object_get_data) (fullscreen, "fullscreen")); GtkObject *visid = GTK_OBJECT ((*_gtk_menu_get_active) (GTK_MENU (visualmenu_menu))); attr_hash->insert("visual_id", (*_gtk_object_get_data) (visid, "visual_id")); GtkObject *sound = GTK_OBJECT ((*_gtk_menu_get_active) (GTK_MENU (soundmenu_menu))); attr_hash->insert("sound", (*_gtk_object_get_data) (sound, "sound")); (*_gtk_signal_disconnect) (GTK_OBJECT (config), dest_signal); (*_gtk_widget_hide) (config); (*_gtk_widget_destroy) (config); (*_gtk_main_iteration_do) (false); } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/math/�������������������������������������������������������������������������������0040755�0000000�0000000�00000000000�07557051141�013176� 5����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/math/Makefile�����������������������������������������������������������������������0100644�0000000�0000000�00000000233�07357121752�014635� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������MATH_OBJS = math/vector.o OBJS += $(MATH_OBJS) SUBLIBS += math/math.a math/math.a: $(MATH_OBJS) $(AR) rc math/math.a $(MATH_OBJS) $(RANLIB) math/math.a ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/math/vector.cpp���������������������������������������������������������������������0100644�0000000�0000000�00000000201�07407525176�015202� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #include #include "vector.h" #include "../demolib_prefs.h" �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/math/vector.h�����������������������������������������������������������������������0100644�0000000�0000000�00000003376�07407525176�014667� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _VECTOR_H #define _VECTOR_H #include class Vector { public: Vector() { } Vector(const float x, const float y, const float z) { this->x = x; this->y = y; this->z = z; } ~Vector() { } inline Vector operator+(const Vector v) const { return Vector(this->x + v.x, this->y + v.y, this->z + v.z); } inline Vector &operator+=(const Vector v) { this->x += v.x; this->y += v.y; this->z += v.z; return *this; } inline Vector operator-(const Vector v) const { return Vector(this->x - v.x, this->y - v.y, this->z - v.z); } inline Vector &operator-=(const Vector v) { this->x -= v.x; this->y -= v.y; this->z -= v.z; return *this; } inline Vector operator*(const float s) const { return Vector(this->x * s, this->y * s, this->z * s); } inline Vector &operator*=(const float s) { this->x *= s; this->y *= s; this->z *= s; return *this; } inline float operator*(const Vector v) const { return (this->x * v.x + this->y * v.y + this->z * v.z) / (float)sqrt((this->x * this->x + this->y * this->y + this->z * this->z) * (v.x * v.x + v.y * v.y + v.z * v.z)); } inline Vector operator/(const float s) const { return *this * (1.0f / s); } inline Vector &operator/=(const float s) { *this *= (1.0f / s); return *this; } inline Vector cross_product(const Vector v) const { return Vector(this->y * v.z - this->z * v.y, this->z * v.x - this->x * v.z, this->x * v.y - this->y * v.x); } inline float magnitude() const { return sqrt(this->x * this->x + this->y * this->y + this->z * this->z); } inline Vector &normalize() { *this *= (1.0f / this->magnitude()); return *this; } float x, y, z; }; #endif /* defined(_VECTOR_H) */ ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/math/matrix.h�����������������������������������������������������������������������0100644�0000000�0000000�00000013531�07407764570�014666� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _MATRIX_H #define _MATRIX_H #include #include "math/vector.h" typedef float MatrixGL[16]; typedef float Matrix3DS[12]; class Matrix{ public: float matrix[4][4]; Matrix(){ Identity(); } Matrix(const Matrix3DS &m) { Identity(); matrix[0][0] = m[0]; matrix[0][1] = m[1 ]; matrix[0][2] = m[2 ]; matrix[0][3] = 0; matrix[1][0] = m[3]; matrix[1][1] = m[4 ]; matrix[1][2] = m[5 ]; matrix[1][3] = 0; matrix[2][0] = m[6]; matrix[2][1] = m[7 ]; matrix[2][2] = m[8 ]; matrix[2][3] = 0; matrix[3][0] = m[9]; matrix[3][1] = m[10]; matrix[3][2] = m[11]; matrix[3][3] = 1; swap(); } Matrix(const MatrixGL &m) { Identity(); matrix[0][0] = m[ 0]; matrix[1][0] = m[ 1]; matrix[2][0] = m[ 2]; matrix[3][0] = m[ 3]; matrix[0][1] = m[ 4]; matrix[1][1] = m[ 5]; matrix[2][1] = m[ 6]; matrix[3][1] = m[ 7]; matrix[0][2] = m[ 8]; matrix[1][2] = m[ 9]; matrix[2][2] = m[10]; matrix[3][2] = m[11]; matrix[0][3] = m[12]; matrix[1][3] = m[13]; matrix[2][3] = m[14]; matrix[3][3] = m[15]; } /* special thanks to Farbrausch ;-) */ Matrix(const float x, const float y, const float z, const float w) { /* ( 1-yy-zz , xy+wz , xz-wy ) T = ( xy-wz , 1-xx-zz , yz+wx ) ( xz+wy , yz-wx , 1-xx-yy ) */ float fx2, fy2, fz2, fwx, fwy, fwz, fxx, fxy, fxz, fyy, fyz, fzz; fx2 = x + x; fy2 = y + y; fz2 = z + z; fwx = w * fx2; fwy = w * fy2; fwz = w * fz2; fxx = x * fx2; fxy = x * fy2; fxz = x * fz2; fyy = y * fy2; fyz = y * fz2; fzz = z * fz2; matrix[0][0] = (float)1.0 - (fyy + fzz); matrix[0][1] = (float)fxy + fwz; matrix[0][2] = (float)fxz - fwy; matrix[0][3] = 0.0f; matrix[1][0] = (float)fxy - fwz; matrix[1][1] = (float)1.0f - (fxx + fzz); matrix[1][2] = (float)fyz + fwx; matrix[1][3] = 0.0f; matrix[2][0] = (float)fxz + fwy; matrix[2][1] = (float)fyz - fwx; matrix[2][2] = (float)1.0f - (fxx + fyy); matrix[2][3] = 0.0f; matrix[3][0] = 0.0f; matrix[3][1] = 0.0f; matrix[3][2] = 0.0f; matrix[3][3] = 1.0f; } inline Matrix operator *=(const Matrix &a) { Matrix temp; int i; for (i=0; i<3; i++) for (int j=0; j<3; j++) temp.matrix[i][j] = (matrix[i][0]*a.matrix[0][j])+ (matrix[i][1]*a.matrix[1][j])+ (matrix[i][2]*a.matrix[2][j]); for (i=0; i<3; i++) for (int j=0; j<3; j++) matrix[i][j] = temp.matrix[i][j]; return temp; } inline Matrix operator +=(const Matrix &a) { Matrix temp; for (int i=0; i<3; i++) for (int j=0; j<3; j++) temp.matrix[i][j] = matrix[i][j] + a.matrix[i][j]; return temp; } inline Matrix operator*(const Matrix &a) const { Matrix temp; for (int i=0; i<3; i++) for (int j=0; j<3; j++) temp.matrix[i][j] = (matrix[i][0]*a.matrix[0][j])+ (matrix[i][1]*a.matrix[1][j])+ (matrix[i][2]*a.matrix[2][j]); return temp; } inline Vector operator*(const Vector &v) const { Vector temp; temp.x = (v.x*matrix[0][0])+(v.y*matrix[0][1])+(v.z*matrix[0][2])+matrix[0][3]; temp.y = (v.x*matrix[1][0])+(v.y*matrix[1][1])+(v.z*matrix[1][2])+matrix[1][3]; temp.z = (v.x*matrix[2][0])+(v.y*matrix[2][1])+(v.z*matrix[2][2])+matrix[2][3]; return temp; } inline Matrix operator+(const Matrix &a) const { Matrix temp; for (int i=0; i<3; i++) for (int j=0; j<3; j++) temp.matrix[i][j] = matrix[i][j] + a.matrix[i][j]; return temp; } inline void Identity() { matrix[0][0] = 1; matrix[1][0] = 0; matrix[2][0] = 0; matrix[3][0] = 0; matrix[0][1] = 0; matrix[1][1] = 1; matrix[2][1] = 0; matrix[3][1] = 0; matrix[0][2] = 0; matrix[1][2] = 0; matrix[2][2] = 1; matrix[3][2] = 0; matrix[0][3] = 0; matrix[1][3] = 0; matrix[2][3] = 0; matrix[3][3] = 1; } inline Matrix operator =(Matrix3DS &m) { return Matrix(m); } inline Matrix Invscale() { Matrix temp; for(int i=0; i<4; i++){ float scale = (matrix[i][0] * matrix[i][0]) + (matrix[i][1] * matrix[i][1]) + (matrix[i][2] * matrix[i][2]); scale = 1.0f / scale; for( int j = 0; j < 4; j++ ) temp.matrix[i][j] = matrix[i][j] * scale; } return temp; } inline void swap() { float tmp; int i; for (i = 0; i < 3; i++) { tmp = matrix[i][1]; matrix[i][1] = matrix[i][2]; matrix[i][2] = tmp; } for (i = 0; i < 3; i++) { tmp = matrix[1][i]; matrix[1][i] = matrix[2][i]; matrix[2][i] = tmp; } tmp = matrix[3][1]; matrix[3][1] = matrix[3][2]; matrix[3][2] = tmp; } inline Matrix transpose() { Matrix temp; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) temp.matrix[i][j] = matrix[j][i]; const float tx = matrix[0][3]; const float ty = matrix[1][3]; const float tz = matrix[2][3]; temp.matrix[0][3] = -(temp.matrix[0][0] * tx + temp.matrix[0][1] * ty + temp.matrix[0][2] * tz); temp.matrix[1][3] = -(temp.matrix[1][0] * tx + temp.matrix[1][1] * ty + temp.matrix[1][2] * tz); temp.matrix[2][3] = -(temp.matrix[2][0] * tx + temp.matrix[2][1] * ty + temp.matrix[2][2] * tz); *this = temp; return *this; } void ToGL(float *temp) { temp[0 ] = matrix[0][0]; temp[1 ] = matrix[0][1]; temp[2 ] = matrix[0][2]; temp[3 ] = matrix[0][3]; temp[4 ] = matrix[1][0]; temp[5 ] = matrix[1][1]; temp[6 ] = matrix[1][2]; temp[7 ] = matrix[1][3]; temp[8 ] = matrix[2][0]; temp[9 ] = matrix[2][1]; temp[10] = matrix[2][2]; temp[11] = matrix[2][3]; temp[12] = matrix[3][0]; temp[13] = matrix[3][1]; temp[14] = matrix[2][2]; temp[15] = matrix[3][3]; } void print() { printf("%5.3f %5.3f %5.3f %5.3f\n", matrix[0][0], matrix[0][1], matrix[0][2], matrix[0][3]); printf("%5.3f %5.3f %5.3f %5.3f\n", matrix[1][0], matrix[1][1], matrix[1][2], matrix[1][3]); printf("%5.3f %5.3f %5.3f %5.3f\n", matrix[2][0], matrix[2][1], matrix[2][2], matrix[2][3]); printf("%5.3f %5.3f %5.3f %5.3f\n", matrix[3][0], matrix[3][1], matrix[3][2], matrix[3][3]); printf("\n"); } }; #endif // _MATRIX_H �����������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/math/array.h������������������������������������������������������������������������0100644�0000000�0000000�00000003225�07457117274�014475� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * An automatically scaling array implementation -- no bounds checking. */ #ifndef _ARRAY_H #define _ARRAY_H #include template class Array { typedef T * iterator; typedef const T * const_iterator; protected: T *array; unsigned int room, elem; public: Array() { this->array = (T *)(malloc(sizeof(T))); this->room = 1; this->elem = 0; } ~Array() { free(this->array); this->array = NULL; } const Array &operator=(Array const &other) { if (this != &other) { free(this->array); this->room = this->elem = other.num_elems(); this->array = (T *)malloc(this->room * sizeof(T)); memcpy(this->array, other.get_array(), this->room * sizeof(T)); } return *this; } inline T &operator[](const unsigned int index) { if (index >= room) { while (index >= room) { room <<= 1; } this->array = (T *)realloc(this->array, room * sizeof(T)); } if (index >= elem) elem = index + 1; return this->array[index]; } inline T operator[](const unsigned int index) const { return this->array[index]; } /* duplicated code here, but I'm too lazy to fix it ;-) */ inline void add_end(T t) { if (elem == room) { room <<= 1; this->array = (T *)realloc(this->array, room * sizeof(T)); } this->array[this->elem++] = t; } inline int num_elems() const { return elem; } inline T *get_array() const { return this->array; } inline iterator begin() { return array; } inline const_iterator begin() const { return array; } inline iterator end() { return array + elem; } inline const_iterator end() const { return array + elem; } }; #endif /* defined(_ARRAY_H) */ ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/util/�������������������������������������������������������������������������������0040755�0000000�0000000�00000000000�07557051141�013222� 5����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/util/Makefile�����������������������������������������������������������������������0100644�0000000�0000000�00000000234�07404457456�014670� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������UTIL_OBJS=util/hashtable.o OBJS += $(UTIL_OBJS) SUBLIBS += util/util.a util/util.a: $(UTIL_OBJS) $(AR) rc util/util.a $(UTIL_OBJS) $(RANLIB) util/util.a ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/util/hashtable.cpp������������������������������������������������������������������0100644�0000000�0000000�00000012742�07467763336�015704� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Simple (and reasonably efficient -- we don't use large hashes so it doesn't * really matter that we fix the number of buckets) hash tables, locked to * strings. */ #include #include #include #include "main/curve.h" #include "exception.h" #include "demolib_prefs.h" #ifndef __linux__ #define strcasecmp stricmp #endif #include "hashtable.h" #if DEMOLIB_MAINLOOP unsigned int Hashtable::string_hash(const char *str) { unsigned int hash = 0; while (*str) { char schar = *str++; #if CASE_INSENSITIVE_HASHES if (schar > 'a' && schar < 'z') schar ^= 32; #endif hash <<= 2; hash ^= schar; hash += hash >> 30; } return hash; } Hashtable::Hashtable() { for (int i = 0; i < NUM_BUCKETS; i++) { this->buckets[i] = NULL; } } /* all the linked lists will be in reverse order ;-) */ Hashtable::Hashtable(Hashtable *h) { for (int i = 0; i < NUM_BUCKETS; i++) { buckets[i] = NULL; struct linked_list *ptr = (struct linked_list *)h->buckets[i]; while (ptr) { struct linked_list *nptr = (struct linked_list *)malloc(sizeof(struct linked_list)); nptr->key = strdup(ptr->key); nptr->hash = ptr->hash; nptr->obj = ptr->obj; nptr->next = buckets[i]; buckets[i] = nptr; ptr = ptr->next; } } } Hashtable::~Hashtable() { for (int i = 0; i < NUM_BUCKETS; i++) { struct linked_list *ptr = buckets[i]; while (ptr) { struct linked_list *next = ptr->next; free(ptr->key); free(ptr); ptr = next; } buckets[i] = NULL; } } void Hashtable::insert(const char * const key, void * const obj) { const unsigned int hash = string_hash(key); const unsigned int partial_hash = hash & BUCKET_MASK; this->remove(key); /* insert in the beginning of the list */ struct linked_list *ptr = (struct linked_list *)malloc(sizeof(struct linked_list)); ptr->key = strdup(key); ptr->hash = hash; ptr->obj = obj; ptr->next = this->buckets[partial_hash]; this->buckets[partial_hash] = ptr; } void Hashtable::insert(const char * const key, char * const str) { this->insert(key, (void * const)str); } /* makes no error if it doesn't exist (make it return a bool?) */ void Hashtable::remove(const char * const key) { const unsigned int hash = string_hash(key); const unsigned int partial_hash = hash & BUCKET_MASK; struct linked_list *ptr = buckets[partial_hash]; struct linked_list *prev = NULL; while (ptr) { if (ptr->hash == hash && #if CASE_INSENSITIVE_HASHES strcasecmp(ptr->key, key) == 0 #else strcmp(ptr->key, key) == 0 #endif ) { if (prev == NULL) { buckets[partial_hash] = ptr->next; } else { prev->next = ptr->next; } free(ptr->key); return; } prev = ptr; ptr = ptr->next; } } void *Hashtable::lookup(const char * const key) const { const unsigned int hash = string_hash(key); const unsigned int partial_hash = hash & BUCKET_MASK; struct linked_list *ptr = buckets[partial_hash]; while (ptr) { if (ptr->hash == hash && #if CASE_INSENSITIVE_HASHES strcasecmp(ptr->key, key) == 0 #else strcmp(ptr->key, key) == 0 #endif ) { return ptr->obj; } ptr = ptr->next; } return NULL; } bool Hashtable::exists(const char * const key) const { return (this->lookup(key) != NULL); } char *Hashtable::get_str(const char * const key) const { char *obj = (char *)(this->lookup(key)); if (obj == NULL) throw new ValueNotSpecifiedException(key); return obj; } /* might want to check this and get_float() for validity, but okay for now */ int Hashtable::get_int(const char * const key) const { const char * const obj = (const char * const)(this->lookup(key)); if (obj == NULL) throw new ValueNotSpecifiedException(key); return atoi(obj); } float Hashtable::get_float(const char * const key) const { const char * const obj = (const char * const)(this->lookup(key)); if (obj == NULL) throw new ValueNotSpecifiedException(key); return atof(obj); } bool Hashtable::get_bool(const char * const key) const { const char * const obj = (const char * const)(this->lookup(key)); if (obj == NULL) throw new ValueNotSpecifiedException(key); if (strcmp(obj, "yes") == 0 || strcmp(obj, "true") == 0 || strcmp(obj, "on") == 0) { return true; } if (strcmp(obj, "no") == 0 || strcmp(obj, "false") == 0 || strcmp(obj, "off") == 0) { return false; } throw new ValueNotSpecifiedException(key, "Illegal boolean value!"); } /* * free all objects in hash (not keys or the hash itself, use delete for those) */ void Hashtable::destroy_values() { for (int i = 0; i < NUM_BUCKETS; i++) { struct linked_list *ptr = buckets[i]; while (ptr) { free(ptr->obj); ptr->obj = NULL; ptr = ptr->next; } } } /* partly obsolete now that we have foreach()? */ void Hashtable::finish_curvedata(const float start, const float stop) { for (int i = 0; i < NUM_BUCKETS; i++) { struct linked_list *ptr = buckets[i]; while (ptr) { Curve *c = (Curve *)ptr->obj; try { c->end_curvepoints(start, stop - start); } catch (FatalException *e) { /* no such curve */ char buf[256]; sprintf(buf, "Curve `%s' missing!", ptr->key); throw new FatalException(buf); } ptr = ptr->next; } } } void Hashtable::foreach(hash_callback callback, const void * const user_data) { for (int i = 0; i < NUM_BUCKETS; i++) { struct linked_list *ptr = buckets[i]; while (ptr) { struct linked_list *next = ptr->next; (*callback)(ptr->key, ptr->obj, user_data); ptr = next; } } } #endif ������������������������������amoeba-1.1.orig/util/hashtable.h��������������������������������������������������������������������0100644�0000000�0000000�00000002357�07467763352�015350� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _HASH_H #define _HASH_H 1 #define BUCKET_BITS 4 #define NUM_BUCKETS (1< #include "audio/vorbis.h" #include "exception.h" /* * These simply emulate a file to libvorbisfile, using the FileReader * class. */ size_t mem_readfunc(void *ptr, size_t size, size_t nmemb, void *datasource) { return ((FileReader *) datasource)->fread(ptr, size, nmemb); } int mem_seekfunc(void *datasource, ogg_int64_t offset, int whence) { // make sure your seek callback returns -1 if you want to save cpu time, // effort, and so on . // (but for jump support, seek is nice) return ((FileReader *) datasource)->fseek(offset, whence); // return -1; } int mem_closefunc(void *datasource) { return 0; } long mem_tellfunc(void *datasource) { return ((FileReader *) datasource)->ftell(); } OggVorbisAudioProvider::OggVorbisAudioProvider(File *file, float jump) { this->vf = (OggVorbis_File *)malloc(sizeof(OggVorbis_File)); if (this->vf == NULL) { throw new FatalException("Out of memory!"); } ov_callbacks mem_callbacks = { mem_readfunc, mem_seekfunc, mem_closefunc, mem_tellfunc }; this->vfr = new FileReader(file); if (ov_open_callbacks(this->vfr, this->vf, NULL, 0, mem_callbacks) < 0) throw new FatalException("Couldn't open the Ogg bitstream"); if (jump != 0.0f) { ov_time_seek(this->vf, jump); } /* validate it better later */ } OggVorbisAudioProvider::~OggVorbisAudioProvider() { ov_clear(this->vf); free(this->vf); this->vf = NULL; delete this->vfr; this->vfr = NULL; } int OggVorbisAudioProvider::fill_buf(char *buf, int bytes) { int junk, ret; ret = ov_read(this->vf, buf, bytes, 0, 2, 1, &junk); if (ret < 0) throw new FatalException("Ogg Vorbis stream error!"); return ret; } ���������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/audio/win32_dsound.h����������������������������������������������������������������0100644�0000000�0000000�00000001517�07432335454�016042� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _WIN32_DSOUND_H #define _WIN32_DSOUND_H 1 #define NOCOMINTERFACE #define WIN32_LEAN_AND_MEAN #define CINTERFACE #include #include #include #include "audio/audio.h" #include "main/mainloop.h" #include #include #include class DirectSoundAudioDriver : public AudioDriver { public: DirectSoundAudioDriver(AudioProvider *prv, float jump, MainLoop *ml); ~DirectSoundAudioDriver(); bool run(); float get_time(); protected: LPDIRECTSOUND dsound; LPDIRECTSOUNDBUFFER primary_buf; LPDIRECTSOUNDBUFFER stream_buf; unsigned int last_played; int bytes_played; unsigned int last_fill; bool eof; MainLoop *ml; int fill_buf_completely(char *buf, int bytes); }; #endif /* !defined(_WIN32_DSOUND_H) */ ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/audio/musichandler.h����������������������������������������������������������������0100644�0000000�0000000�00000000777�07431044574�016210� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _MUSICHANDLER_H #define _MUSICHANDLER_H 1 #include "audio/audio.h" #include "main/event.h" class MusicBar; class MusicHandler : public Event { public: MusicHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr); ~MusicHandler(); void start_effect(); void draw_scene(float progress); void end_effect(); float get_time(); protected: File *musicfile; AudioProvider *prov; AudioDriver *drv; float jump; friend class MusicBar; }; #endif /* defined(_OGGHANDLER_H) */ �amoeba-1.1.orig/audio/linux_oss.cpp�����������������������������������������������������������������0100644�0000000�0000000�00000006041�07500721140�016062� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * A quite standard OSS (Linux) output driver. Uses fragments and byte * counters, so your soundcard driver would better support it :-) I've * heard not everybody do, but never had a bug report on it yet, at * least :-) */ #include "audio/linux_oss.h" #include "exception.h" #include #include #include #include #include #include #include #include #include OSSAudioDriver::OSSAudioDriver(AudioProvider *prv, float jump, MainLoop *lp) { this->prov = prv; this->oss_fd = open("/dev/sound/dsp", O_RDWR); if (this->oss_fd == -1) { this->oss_fd = open("/dev/dsp", O_RDWR); if (this->oss_fd == -1) throw new FatalException("/dev/dsp", strerror(errno)); } this->set_ioctl(SNDCTL_DSP_RESET, 1); this->set_ioctl(SOUND_PCM_WRITE_RATE, 44100); this->set_ioctl(SOUND_PCM_WRITE_CHANNELS, 2); this->set_ioctl(SNDCTL_DSP_SETFMT, AFMT_S16_LE); this->set_ioctl(SNDCTL_DSP_NONBLOCK, 1); this->set_ioctl(SNDCTL_DSP_SETFRAGMENT, 0x7fff000c); this->bytes_played = (int)(jump * 44100.0f) * 4; this->eof = false; this->in_outbuf = 0; { struct audio_buf_info abinfo; if (ioctl(this->oss_fd, SNDCTL_DSP_GETOSPACE, &abinfo) == -1) throw new FatalException("Couldn't call SNDCTL_DSP_GETOSPACE!"); this->last_fill = abinfo.bytes; } } OSSAudioDriver::~OSSAudioDriver() { } inline void OSSAudioDriver::set_ioctl(int command, int value) { ioctl(this->oss_fd, command, &value); } bool OSSAudioDriver::run() { /* find out how many fragments are free */ struct audio_buf_info abinfo; if (ioctl(this->oss_fd, SNDCTL_DSP_GETOSPACE, &abinfo) == -1) throw new FatalException("Couldn't call SNDCTL_DSP_GETOSPACE!"); /* record how much was actually played */ this->bytes_played += abinfo.bytes - last_fill; last_fill = abinfo.bytes; if (this->eof) { struct timeval now; gettimeofday(&now, NULL); float secs = (float)(now.tv_sec - eof_time.tv_sec) + (float)(now.tv_usec - eof_time.tv_usec) * 0.000001f; this->bytes_played += (int)(secs * 44100.0f * 4.0f); memcpy(&this->eof_time, &now, sizeof(struct timeval)); return true; } while (abinfo.fragments > 0 && abinfo.fragments * abinfo.fragsize >= 8192) { /* whopee, we can output :-) */ int ret = this->prov->fill_buf(this->outbuf + in_outbuf, 65536 - in_outbuf); if (ret == 0) { /* switch to software timer */ this->eof = true; gettimeofday(&this->eof_time, NULL); return true; } in_outbuf += ret; /* write only whole fragments */ if (in_outbuf >= abinfo.fragsize) { int to_write = in_outbuf - (in_outbuf % abinfo.fragsize); to_write = write(this->oss_fd, this->outbuf, to_write); in_outbuf -= to_write; memmove(outbuf, outbuf + to_write, in_outbuf); /* avoid another ioctl */ abinfo.fragments -= to_write / abinfo.fragsize; abinfo.bytes -= to_write; last_fill = abinfo.bytes; } } return false; } float OSSAudioDriver::get_time() { return (float)(this->bytes_played) / 44100.0f / 4.0f; } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/audio/win32_dsound.cpp��������������������������������������������������������������0100644�0000000�0000000�00000013441�07476454552�016405� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Oh my goodness, how ugly DirectSound is. SOMEBODY PORT OSS/ALSA TO * WINDOWS, PLEASE! ;-) Needs DX3 or something. ;-) */ #include "audio/win32_dsound.h" #include "main/win32-config/win32-config.h" #include "exception.h" #include #include #include typedef HRESULT (WINAPI *DIRECTSOUNDCREATE) (GUID FAR *lpGUID,LPDIRECTSOUND FAR *lplpDS, IUnknown FAR *pUnkOuter); DirectSoundAudioDriver::DirectSoundAudioDriver(AudioProvider *prv, float jump, MainLoop *ml) { HWND hWnd = ml->win->hWnd; DSBUFFERDESC dsbd_p, dsbd_s; WAVEFORMATEX format; DIRECTSOUNDCREATE dsCreate; HMODULE library; int err; this->ml = ml; this->eof = false; this->bytes_played = (int)(jump * 44100.0f) * 4; this->prov = prv; library = (HMODULE)LoadLibrary("dsound.dll"); if (library == NULL) throw new FatalException("DirectSound", "Error in loading dsound.dll"); dsCreate = (DIRECTSOUNDCREATE)GetProcAddress(library, "DirectSoundCreate"); if (dsCreate == NULL) throw new FatalException("DirectSound", "Error in finding DirectSoundCreate"); if (dsCreate(Win32Config::instance()->get_sound(), &dsound, NULL) != DS_OK) throw new FatalException("DirectSound", "DirectSoundCreate"); err = IDirectSound_SetCooperativeLevel(dsound, hWnd, DSSCL_EXCLUSIVE | DSSCL_PRIORITY); if (err != DS_OK) throw new FatalException("DirectSound", "SetCooperativeLevel"); /* * Now create any buffers we need, first a primary buffer (to * get the format right and thus eliminate any conversion noise * DirectSound might try to impose on us :-P), then the secondary * buffer, which is used for the actual stream. * * Our buffer is exactly one second of stereo, 16-bit 44100Hz raw * PCM, ie. 44100 * 4 bytes. */ memset(&dsbd_p, 0, sizeof(DSBUFFERDESC)); dsbd_p.dwSize = sizeof(DSBUFFERDESC); dsbd_p.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_STICKYFOCUS; dsbd_p.dwBufferBytes = 0; dsbd_p.lpwfxFormat = NULL; err = IDirectSound_CreateSoundBuffer(dsound, &dsbd_p, &this->primary_buf, NULL); if (err != DS_OK) throw new FatalException("DirectSound", "Create primary buffer"); memset(&format, 0, sizeof(WAVEFORMATEX)); format.wFormatTag = WAVE_FORMAT_PCM; format.nChannels = 2; format.nSamplesPerSec = 44100; format.nAvgBytesPerSec = 44100 * 4; format.nBlockAlign = 4; format.wBitsPerSample = 16; if (IDirectSoundBuffer_SetFormat(primary_buf, &format) != DS_OK) throw new FatalException("DirectSound", "SetFormat"); /* now for the secondary buffer */ memset(&dsbd_s, 0, sizeof(DSBUFFERDESC)); dsbd_s.dwSize = sizeof(DSBUFFERDESC); dsbd_s.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2; dsbd_s.lpwfxFormat = &format; dsbd_s.dwBufferBytes = format.nAvgBytesPerSec; err = IDirectSound_CreateSoundBuffer(dsound, &dsbd_s, &this->stream_buf, NULL); if (err != DS_OK) throw new FatalException("DirectSound", "Create secondary buffer"); /* fill the first buffer */ char *write_buf; DWORD write_len; this->last_played = 0; IDirectSoundBuffer_Lock(stream_buf, 0, 44100 * 4, (void **)(&write_buf), &write_len, NULL, 0, 0); memset(write_buf, 0, write_len); this->last_fill = this->fill_buf_completely(write_buf, write_len); IDirectSoundBuffer_Unlock(stream_buf, (void *)write_buf, write_len, NULL, 0); /* now play :-) */ if (IDirectSoundBuffer_SetCurrentPosition(stream_buf, 0) != DS_OK) throw new FatalException ("DirectSound", "SetCurrentPosition"); if (IDirectSoundBuffer_Play(stream_buf, 0, 0, DSBPLAY_LOOPING) != DS_OK) throw new FatalException("DirectSound", "Play"); } DirectSoundAudioDriver::~DirectSoundAudioDriver() { IDirectSoundBuffer_Release(this->primary_buf); IDirectSoundBuffer_Release(this->stream_buf); IDirectSound_Release(this->dsound); } bool DirectSoundAudioDriver::run() { unsigned char *write_buf1, *write_buf2; DWORD write_len1, write_len2, play_pos, junk; int err; err = IDirectSoundBuffer_GetCurrentPosition(stream_buf, &play_pos, &junk); if (err != DS_OK) throw new FatalException("DirectSound", "GetCurrentPosition"); if (play_pos != last_played) { int fill, tfill, err, played; char outbuf[44100 * 4]; if (this->last_fill < play_pos) { fill = play_pos - last_fill; } else { fill = 44100 * 4 - (last_fill - play_pos); } /* very crude error detection */ while ((err = IDirectSoundBuffer_Lock(stream_buf, this->last_fill, fill, (void **)(&write_buf1), &write_len1, (void **)(&write_buf2), &write_len2, 0)) != DS_OK) { IDirectSoundBuffer_Restore(stream_buf); IDirectSoundBuffer_Play(stream_buf, 0, 0, DSBPLAY_LOOPING); } tfill = this->fill_buf_completely(outbuf, write_len1 + write_len2); if ((unsigned int)tfill <= write_len1) { memcpy(write_buf1, outbuf, tfill); } else { memcpy(write_buf1, outbuf, write_len1); memcpy(write_buf2, outbuf + write_len1, tfill - write_len1); } this->last_fill += tfill; if (this->last_fill >= 44100 * 4) this->last_fill -= 44100 * 4; played = play_pos - last_played; if (played < 0) played += 44100 * 4; this->bytes_played += played; this->last_played = play_pos; IDirectSoundBuffer_Unlock(stream_buf, (void *)(write_buf1), write_len1, (void *)(write_buf2), write_len2); } return true; } float DirectSoundAudioDriver::get_time() { return (float)(this->bytes_played) / 44100.0f / 4.0f; } int DirectSoundAudioDriver::fill_buf_completely(char *buf, int bytes) { int junk; int ret = 0; while (bytes > 4096) { int i = this->prov->fill_buf(buf, bytes); if (i == 0) { /* fill with zeroes */ memset(buf, 0, bytes); i = bytes; } if (i < 0) throw new FatalException("Error in Ogg stream"); ret += i; bytes -= i; buf += i; } return ret; } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/audio/audio.h�����������������������������������������������������������������������0100644�0000000�0000000�00000001017�07432325164�014615� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Some general abstract base classes. The AudioDriver gets input from the * AudioProvider and plays it. */ #ifndef _AUDIO_H #define _AUDIO_H 1 #include "packer/file.h" class AudioProvider { public: virtual ~AudioProvider() {}; virtual int fill_buf(char *buf, int bytes) = 0; protected: AudioProvider() {}; }; class AudioDriver { public: virtual ~AudioDriver() {}; virtual bool run() = 0; virtual float get_time() = 0; protected: AudioDriver() {}; AudioProvider *prov; }; #endif /* !defined(_AUDIO_H) */ �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/audio/musichandler.cpp��������������������������������������������������������������0100644�0000000�0000000�00000003161�07502415500�016517� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * The general sound system. In theory, this is meant to be flexible enough * to support softsynths etc.. Who knows if it will work -- only time will * show :-) */ #define NOCOMINTERFACE #define WIN32_LEAN_AND_MEAN #define CINTERFACE #include "packer/file.h" #include "exception.h" #include "demolib_prefs.h" #include "audio/musichandler.h" #include "audio/audio.h" #include "audio/vorbis.h" #define DEMOLIB_SOUND_PROVIDER OggVorbisAudioProvider #if __linux__ #include "audio/linux_oss.h" #define DEMOLIB_SOUND_DRIVER OSSAudioDriver #else #include "audio/win32_dsound.h" #define DEMOLIB_SOUND_DRIVER DirectSoundAudioDriver #endif #include #include #include MusicHandler::MusicHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) : Event(ml, title, elem, attr, NULL) { this->musicfile = load_file(attr->get_str("file")); if (attr->exists("jump")) { this->jump = attr->get_float("jump"); } else { this->jump = 0.0f; } this->prov = new DEMOLIB_SOUND_PROVIDER(this->musicfile, jump); this->ml = ml; if (this->ml) this->ml->timer = this; this->drv = NULL; } MusicHandler::~MusicHandler() { delete this->prov; this->prov = NULL; } void MusicHandler::start_effect() { this->drv = new DEMOLIB_SOUND_DRIVER(this->prov, jump, this->ml); } void MusicHandler::end_effect() { delete this->drv; this->drv = NULL; } void MusicHandler::draw_scene(float progress) { /* ignore the eof info */ if (this->drv) { (void)this->drv->run(); } } float MusicHandler::get_time() { if (this->drv == NULL) { return 0.0f; } else { return this->drv->get_time(); } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/audio/linux_oss.h�������������������������������������������������������������������0100644�0000000�0000000�00000001042�07432325210�015525� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _LINUX_OSS_H #define _LINUX_OSS_H 1 #include "audio/audio.h" #include "main/mainloop.h" #include #include class OSSAudioDriver : public AudioDriver { public: OSSAudioDriver(AudioProvider *prv, float jump, MainLoop *ml); ~OSSAudioDriver(); bool run(); float get_time(); protected: int oss_fd; struct timeval eof_time; char outbuf[65536]; int in_outbuf; unsigned int last_fill, bytes_played; bool eof; private: inline void set_ioctl(int command, int value); }; #endif /* !defined(_LINUX_OSS_H) */ ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/audio/vorbis.h����������������������������������������������������������������������0100644�0000000�0000000�00000000711�07431044150�015010� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _VORBIS_H #define _VORBIS_H 1 #include "audio/audio.h" #include "packer/filereader.h" #include class MusicBar; class OggVorbisAudioProvider : public AudioProvider { public: OggVorbisAudioProvider(File *file, float jump); ~OggVorbisAudioProvider(); int fill_buf(char *buf, int bytes); protected: OggVorbis_File *vf; FileReader *vfr; friend class MusicBar; }; #endif /* !defined(_VORBIS_H) */ �������������������������������������������������������amoeba-1.1.orig/image/������������������������������������������������������������������������������0040755�0000000�0000000�00000000000�07557051141�013327� 5����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/png_image.cpp�����������������������������������������������������������������0100644�0000000�0000000�00000007432�07467344610�015772� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Based on libpng's example.c (so it needs libpng) */ #include #include #include #include "png_image.h" #include "../exception.h" #include "../demolib_prefs.h" #if DEMOLIB_IMAGE_PNG /* ugly, but works (unless there is corrupted data :-D) */ char *curr_png_ptr = NULL; void read_mem(png_structp png_ptr, png_bytep data, unsigned int length) { memcpy(data, curr_png_ptr, length); curr_png_ptr += length; } PNGImage::PNGImage(File *file) { png_structp png_ptr; png_infop info_ptr; int bit_depth, color_type, interlace_type; // png_color_16 my_background, *image_background; png_info intent; png_bytep *row_pointers; float screen_gamma; unsigned int row; png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) { throw new FatalException("png_create_read_struct() failed"); } /* Allocate/initialize the memory for image information. */ info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); throw new FatalException("png_create_info_struct() failed"); } /* Set up error handling. */ if (setjmp(png_ptr->jmpbuf)) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); throw new FatalException("PNG decompression failed"); } /* Set up the memory reader. */ curr_png_ptr = file->get_data(); png_set_read_fn(png_ptr, NULL, read_mem); png_read_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *)(&this->width), (png_uint_32 *)(&this->height), &bit_depth, &color_type, &interlace_type, NULL, NULL); if (color_type == PNG_COLOR_TYPE_GRAY) { this->bpp = 8; } if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { this->bpp = 16; } if (color_type == PNG_COLOR_TYPE_PALETTE) { this->bpp = 32; } if (color_type == PNG_COLOR_TYPE_RGB) { this->bpp = 24; } if (color_type == PNG_COLOR_TYPE_RGBA) { this->bpp = 32; } /* Allocate memory if needed */ this->image_buf = (unsigned char *)(malloc(this->width * this->height * this->bpp / 8)); if (this->image_buf == NULL) { throw new FatalException("Couldn't allocate memory for JPEG image"); } // png_set_strip_16(png_ptr); png_set_packing(png_ptr); if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr); if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_expand(png_ptr); if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_expand(png_ptr); /* if (png_get_bKGD(png_ptr, info_ptr, &image_background)) png_set_background(png_ptr, image_background, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); else png_set_background(png_ptr, &my_background, PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); */ screen_gamma = 2.2; if (png_get_sRGB(png_ptr, info_ptr, (int *)(&intent))) { png_set_sRGB(png_ptr, &intent, 0); } else { double image_gamma; if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)) png_set_gamma(png_ptr, screen_gamma, image_gamma); else png_set_gamma(png_ptr, screen_gamma, 0.45455); } // png_set_bgr(png_ptr); /* if (color_type != PNG_COLOR_TYPE_RGBA) png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); */ /* Allocate the row pointers (ick!) */ row_pointers = (png_bytep *)(malloc(sizeof(png_bytep) * this->height)); if (row_pointers == NULL) { throw new FatalException("Out of memory"); } for (row = 0; row < height; row++) { row_pointers[row] = this->image_buf + (this->width * row * this->bpp / 8); } /* Read the image in one pass. */ png_read_image(png_ptr, row_pointers); free(row_pointers); png_read_end(png_ptr, info_ptr); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); } PNGImage::~PNGImage() { free(this->image_buf); } unsigned char *PNGImage::get_pixel_data() { return this->image_buf; } #endif /* DEMOLIB_IMAGE_PNG */ ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/Makefile����������������������������������������������������������������������0100644�0000000�0000000�00000000363�07467344134�014775� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������IMAGE_OBJS=image/jpeg_image.o image/png_image.o image/load_image.o image/image.o image/imagecombiner.o OBJS += $(IMAGE_OBJS) SUBLIBS += image/image.a image/image.a: $(IMAGE_OBJS) $(AR) rc image/image.a $(IMAGE_OBJS) $(RANLIB) image/image.a �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/load_image.cpp����������������������������������������������������������������0100644�0000000�0000000�00000003030�07467350110�016103� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Sesse's demolib */ #include #include #include #include "demolib_prefs.h" #include "image/image.h" #include "image/jpeg_image.h" #include "image/png_image.h" #include "image/imagecombiner.h" #include "packer/file.h" #include "exception.h" #if !defined(__GNUC__) && !defined(__ICC__) #define strcasecmp stricmp #endif Image *load_image(const char * const filename) { /* * a syntax of "image:alpha" indicates that the image data and the alpha data * is in separate files */ char *ptr = strchr(filename, ':'); if (ptr != NULL) { char *fn = strdup(filename); ptr = strchr(fn, ':'); ptr[0] = 0; Image *rgb = load_image(fn); Image *alpha = load_image(ptr + 1); try { Image *combined = new ImageCombiner(rgb, alpha); delete rgb; delete alpha; free(fn); return combined; } catch (FatalException *e) { throw new FatalException(filename, e->get_error()); } } File *file = load_file(filename); /* find out what kind of image this is by looking at the extension */ #if DEMOLIB_IMAGE_JPEG if (strcasecmp(filename + strlen(filename) - 4, ".jpg") == 0 || strcasecmp(filename + strlen(filename) - 5, ".jpeg") == 0) { Image *img = new JPEGImage(file); delete file; return img; } #endif /* DEMOLIB_IMAGE_JPEG */ #if DEMOLIB_IMAGE_PNG if (strcasecmp(filename + strlen(filename) - 4, ".png") == 0) { Image *img = new PNGImage(file); delete file; return img; } #endif /* DEMOLIB_IMAGE_PNG */ throw new FatalException("Couldn't figure out type of image"); } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/imagecombiner.cpp�������������������������������������������������������������0100644�0000000�0000000�00000003324�07470307620�016633� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include "image/imagecombiner.h" #include "exception.h" ImageCombiner::ImageCombiner(Image *rgb, Image *alpha) { if (rgb->get_width() != alpha->get_width() || rgb->get_height() != alpha->get_height()) { throw new FatalException("Alpha image is not the same dimensions as the base image!"); } if (rgb->get_bpp() != 8 && rgb->get_bpp() != 24) { throw new FatalException("RGB image must be 8bpp or 24bpp!"); } if (alpha->get_bpp() != 8) { throw new FatalException("Alpha map but isn't 8bpp!"); } /* slow but works well. :-) */ this->width = rgb->get_width(); this->height = rgb->get_height(); if (rgb->get_bpp() == 24) { this->bpp = 32; this->image_buf = (unsigned char *)malloc(width * height * 4); if (this->image_buf == NULL) throw new FatalException("Out of memory!"); unsigned char *ptr_rgb = rgb->get_pixel_data(); unsigned char *ptr_alpha = alpha->get_pixel_data(); unsigned char *out = this->image_buf; for (unsigned int i = 0; i < width * height; i++) { *out++ = *ptr_rgb++; *out++ = *ptr_rgb++; *out++ = *ptr_rgb++; *out++ = *ptr_alpha++; } } else { this->bpp = 16; this->image_buf = (unsigned char *)malloc(width * height * 2); if (this->image_buf == NULL) throw new FatalException("Out of memory!"); unsigned char *ptr_rgb = rgb->get_pixel_data(); unsigned char *ptr_alpha = alpha->get_pixel_data(); unsigned char *out = this->image_buf; for (unsigned int i = 0; i < width * height; i++) { *out++ = *ptr_rgb++; *out++ = *ptr_alpha++; } } } ImageCombiner::~ImageCombiner() { free(this->image_buf); this->image_buf = NULL; } unsigned char *ImageCombiner::get_pixel_data() { return this->image_buf; } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/jpeg_image.h������������������������������������������������������������������0100644�0000000�0000000�00000000357�07467344310�015574� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include "image.h" #include "packer/file.h" class JPEGImage : public Image { public: JPEGImage(File *file); ~JPEGImage(); int get_width(); int get_height(); unsigned char *get_pixel_data(); protected: unsigned char *image_buf; }; ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/jpeg_image.cpp����������������������������������������������������������������0100644�0000000�0000000�00000006702�07473703236�016132� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Sesse's demolib: JPEG-specific functions * Based on libjpeg's example.c (so it needs libjpeg) */ #include #include #include #include #include #include #include #include "demolib_prefs.h" #include "jpeg_image.h" #include "../exception.h" #include "packer/file.h" #if DEMOLIB_IMAGE_JPEG extern "C" { #include #include } /* we need an error manager to make this work cleanly */ struct my_error_mgr { struct jpeg_error_mgr pub; /* "public" fields */ jmp_buf setjmp_buffer; /* for return to caller */ }; typedef struct my_error_mgr * my_error_ptr; /* And this is the error handler -- it simply throws the error :-) */ void my_error_exit(j_common_ptr cinfo) { char buf[JMSG_LENGTH_MAX]; (*cinfo->err->format_message)(cinfo, buf); throw new FatalException("JPEG error", buf); } /* * These four functions constitute a simple memory reader, for making * libjpeg read from a pointer, not a file */ void noop(j_decompress_ptr cinfo) {} #if defined(__GNUC__) || defined(__ICC__) int fill(j_decompress_ptr cinfo) #else unsigned char fill(j_decompress_ptr cinfo) #endif { if (cinfo->src->bytes_in_buffer >= 0) { return TRUE; } else { return FALSE; } } void skip (j_decompress_ptr cinfo, long num_bytes) { cinfo->src->bytes_in_buffer -= num_bytes; cinfo->src->next_input_byte += num_bytes; } void init_mem_source(j_decompress_ptr cinfo, File *file) { cinfo->src = (struct jpeg_source_mgr *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(struct jpeg_source_mgr)); cinfo->src->init_source = noop; cinfo->src->fill_input_buffer = fill; cinfo->src->skip_input_data = skip; cinfo->src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ cinfo->src->term_source = noop; cinfo->src->bytes_in_buffer = file->data_length(); /* forces fill_input_buffer on first read */ cinfo->src->next_input_byte = (const JOCTET *)file->get_data(); /* until buffer loaded */ } /* * Main function: Decompress JPEG into buffer. If buf is NULL, automatically * allocates a suitable buffer. */ JPEGImage::JPEGImage(File *file) { struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; int row_stride; JSAMPARRAY buffer; cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; jpeg_create_decompress(&cinfo); /* source */ init_mem_source(&cinfo, file); (void) jpeg_read_header(&cinfo, TRUE); (void) jpeg_start_decompress(&cinfo); this->width = cinfo.output_width; this->height = cinfo.output_height; this->bpp = cinfo.output_components * 8; row_stride = this->width * cinfo.output_components; buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, 1); /* allocate the buffer */ this->image_buf = (unsigned char *)(malloc(this->width * this->height * cinfo.output_components)); if (this->image_buf == NULL) { throw new FatalException("Couldn't allocate memory for JPEG image"); } while (cinfo.output_scanline < this->height) { const unsigned int w = this->width * this->bpp / 8; (void) jpeg_read_scanlines(&cinfo, buffer, 1); memcpy(this->image_buf + (cinfo.output_scanline-1) * w, buffer[0], w); } (void) jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); } JPEGImage::~JPEGImage() { free(this->image_buf); } unsigned char *JPEGImage::get_pixel_data() { return this->image_buf; } #endif /* DEMOLIB_IMAGE_JPEG */ ��������������������������������������������������������������amoeba-1.1.orig/image/image.cpp���������������������������������������������������������������������0100644�0000000�0000000�00000000421�07467344242�015116� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * virtual image class :-) */ #include "image.h" #include #include Image::Image() {} Image::~Image() {} int Image::get_width() { return this->width; } int Image::get_height() { return this->height; } int Image::get_bpp() { return this->bpp; } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/png_image.h�������������������������������������������������������������������0100644�0000000�0000000�00000000354�07467344316�015436� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include "image.h" #include "packer/file.h" class PNGImage : public Image { public: PNGImage(File *file); ~PNGImage(); int get_width(); int get_height(); unsigned char *get_pixel_data(); protected: unsigned char *image_buf; }; ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/imagecombiner.h���������������������������������������������������������������0100644�0000000�0000000�00000000503�07467344336�016307� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _IMAGECOMBINER_H #define _IMAGECOMBINER_H 1 #include "image.h" #include "packer/file.h" class ImageCombiner : public Image { public: ImageCombiner(Image *rgb, Image *alpha); ~ImageCombiner(); unsigned char *get_pixel_data(); protected: unsigned char *image_buf; }; #endif /* !defined(_IMAGECOMBINER_H) */ ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/image/image.h�����������������������������������������������������������������������0100644�0000000�0000000�00000000562�07467344250�014570� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * virtual image class :-) */ #ifndef _IMAGE_H #define _IMAGE_H class Image { public: Image(); virtual ~Image(); int get_width(); int get_height(); virtual unsigned char *get_pixel_data() = 0; int get_bpp(); protected: unsigned int width; unsigned int height; unsigned int bpp; }; Image *load_image(const char * const filename); #endif /* _IMAGE_H */ ����������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/file_id.diz�������������������������������������������������������������������������0100644�0000000�0000000�00000001676�07502441570�014356� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� __________ ____/\ \ / .-------- - \ \/ // - ---[ e X C E S s ! ]----------------------. | /\_______\____/ //__________ _____________ ______ __________ | | / _______/ //_\ _ \_ ______/ ___/_ ____/_ | _ _/ __/_ / // /_____/ __/_ ______ \_ ___ \_ __ | \\ / \_/ //\ / \_ / \_ / / / // | | \\ / / // \ / / / / / / / // | |___\\ ________/ // \ ________/\ ________/\ ________/\ ________//____| . \/ / //\ \/ \/ \/ \/ . '------- - / // /______\ - --------------------sCr/sAc!-------------' /____ // \ // gloom - sesse - neuromancer - tick - kusma \/ amoeba - underscore2k2 - win32/linux/opengl - final ver! ������������������������������������������������������������������amoeba-1.1.orig/exception.cpp�����������������������������������������������������������������������0100644�0000000�0000000�00000004000�07440421126�014731� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * generic exception class */ #include #include #include #ifdef __GNUC__ #include #endif #include "exception.h" /* * Generic exception class */ Exception::Exception(const char *msg) { this->str = strdup(msg); } Exception::Exception(const char *owner, const char *msg) { this->str = (char *)malloc(strlen(owner) + strlen(msg) + 3); if (this->str == NULL) throw new FatalException("Out of memory"); /* beautiful :-P */ sprintf(this->str, "%s: %s", owner, msg); } Exception::~Exception() { free(this->str); } char *Exception::get_error() { return this->str; } int Exception::get_fatal() { return 0; } /* * Fatal exceptions */ FatalException::FatalException(const char *msg) : Exception(msg) { /* grossss hack */ // fprintf(stderr, "Unhandled exception: %s\n", msg); } FatalException::FatalException(const char *owner, const char *msg) : Exception(owner, msg) { /* grossss hack */ // fprintf(stderr, "Unhandled exception: %s: %s\n", owner, msg); } int FatalException::get_fatal() { return 1; } /* * Non-fatal exceptions */ NonFatalException::NonFatalException(const char *msg) : Exception(msg) {} NonFatalException::NonFatalException(const char *owner, const char *msg) : Exception(owner, msg) {} int NonFatalException::get_fatal() { return 1; } /* * A fatal exception thrown from the Hashtable class when a value * requested wasn't found (only from get_int() and get_float() -- * lookup() returns NULL but get_int() and get_float() are simplifications * to get less code duplication, and "not found" would definitely * be an error here) */ ValueNotSpecifiedException::ValueNotSpecifiedException(const char *msg) : FatalException(msg) {} ValueNotSpecifiedException::ValueNotSpecifiedException (const char *owner, const char *msg) : FatalException(owner, msg) {} FileNotFoundException::FileNotFoundException(const char *msg) : NonFatalException(msg) {} FileNotFoundException::FileNotFoundException (const char *owner, const char *msg) : NonFatalException(owner, msg) {} amoeba-1.1.orig/config.mak��������������������������������������������������������������������������0100644�0000000�0000000�00000000663�07466625640�014220� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������# # PLATFORM=win32 for Windows # PLATFORM=linux for Linux # # DESTPLATFORM=win32 for crosscompilation etc. # # LINUXVARIANT=gcc for gcc # LINUXVARIANT=icc for Intel's C++ compiler # # WIN32VARIANT=mingw for MinGW, or crosscompiling Linux -> Win32 # (don't use WIN32VARIANT=cygwin with PLATFORM=linux) # WIN32VARIANT=cygwin for Cygwin (ie. for AIDC use primarily) # PLATFORM=linux DESTPLATFORM=linux LINUXVARIANT=gcc WIN32VARIANT=mingw �����������������������������������������������������������������������������amoeba-1.1.orig/readme.txt��������������������������������������������������������������������������0100644�0000000�0000000�00000032235�07502445532�014246� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba a demo by excess released at underscore 2002 (1st place), may 2002 final version released june 2002 ___________________________________________________ demo as with the last demo, we've been working international, with gloom designing the demo in norway while we were busy coding and ironing out the last bugs at the partyplace in sweden.. and as if putting this demo together wasn't hard enough as it is, gloom actually had to -break into- his own office to work on it during the night. the things we do for the demoscene.. :) anyways; here it is - we hope you like it. ________________________________________________ credits gloom design, music, graphics sesse code neuromancer graphics kusma graphics, code tick 3d modelling satcom101 music ________________________________________________ machine should work more or less equally well on linux and win32. opengl and a relatively fast 3d accelerator needed -- this final version has been tested on various geforce cards (including geforce2go), matrox g200/g400/g450/g550 (g200/g400 only under linux, no opengl support for those on windows), radeon (also mobile), trident cyberblade (!), tnt2, i815 etc. etc. etc., so we hope most people should be able to watch the demo. if you don't have hardware stencil buffers some parts (like the shadows) will be incredibly slow, though... tough luck. perhaps a -nostencil option next time. _________________________________________________ binary the default settings should be okay, just click the binary for windows or execute it (remember chmod +x) under linux (the -oldg++ version is for those of you who still don't have libstdc++ v4 installed -- sorry, libstdc++ v3 isn't supported anymore, we can't have _three_ different versions ;-) ). if you use linux and have libgtk+ somewhere, we have a colourful configuration dialog, if not, you can still use the good old unfancy (but working) command line switches. try "-help", for instance. ;-) the final adds a windows config dialog too, so you can enjoy easy setup on both platforms (if you don't want the dialog box, simply specify command line switches and they will override the dialog box code). (note: most drivers don't expose stencil visuals if you're in 16bpp mode. try changing to 24/32bpp if you get errors or the box scene is very slow. note to matrox users on windows: if the shadows are buggy, check that "use 32-bit z-buffers" is checked in the powerdesk control panel.) _________________________________________________ source yes, you guessed it, the src/ directory includes complete source. see gpldemo.txt for more information. don't complain to us if it doesn't compile -- demosource was never intended to be portable anyhow. (the final should be slightly better than the party version, though :-) ) _________________________________________________ we use linux. windows. vim. ultraedit. expat. freetype. libjpeg. libpng. gcc. (sometimes msvc.) various ogg vorbis libraries (go vorbis!). gimp. photoshop. acid. soundforge. coke. beer. (no drugs.) computers. __________________________________________________ party for some reason, underscore2002 is... dark. after we logged in (the sign-in terminals were showing all passwords in cleartext in the URL and thus in the history too, nice going ;-) ) we found a more or less empty place, tried to get used to the dark and set up our equipment. of course, sesse almost lost his digicam, but the taxi driver had found it (and we had to pay for him to drive back with it -- boo). kusma and the others went to drink as always, while some weirdo in the democrew decided to play with some sound generator so nobody could go to sleep in the main hall... of course, the showers were good to sleep in -- but cold. 3/4th of the norwegian posse have forgotten their sleeping bags, but fortunately, some swede was nice enough to lend out a sleeping mat, so we didn't have to get to know the floor _that_ well... we're actually handing in something like five productions from four people here, and as usual, lug00ber looks like he could go on stage quite a few times. the network here is, well, almost non-existant, but heck, it's a sceneparty, no lame-ass lan party (there are still people playing games, here, though). still could use some light though, the weather outside is real good this weekend and there's a barbeque planned or something... oh well, signing off, hopefully gloom will finish his stuff in norway soon so we can get to an internet café or something, fetch the stuff, finish the demo and just wait for the show to start :-) _______________________________________________ party II (written for the final, we didn't have time to update readme.txt before release) okay, so the problem was getting the data from gloom to the party. we talked to lator/dxm (stefan), member of the underscore democrew, and he agreed to fetch some files for us later that day when he was going home. after some cell phone stress (the (borrowed) cellphone sesse was using didn't work in sweden) we managed to get in touch with gloom, and get an url... there was little to do with the demo, since the source was already largely ready, so the norwegian posse went out for the usual scene-grill (although it rained, it was definitely a success), keeping an eye on the arriving cars, waiting for lator to return. when he finally returned, he just gave us a notebook, saying "the data is there", so we took it to our place in the hall and tried to transfer the files. the first problem was finding some way to transfer the files -- sesse didn't have samba installed on his linux machine, so "windows file sharing" was out of the question... the portable (running windows xp home edition -- swedish) didn't have anything useful on it except ftp.exe, so we started up an ftp daemon and started transferring the files... it froze after a few hundred kB. we tried like _everything_ -- switching ftp daemon, switching ip ranges, splitting the file into multiple smaller ones, using samba the other way (ie. smbclient, with the notebook as server -- enabling file sharing in xp isn't exactly intuitive, the "shared files" folder isn't shared by default even though the help tells you it is), etc... we tried moving the files to the win2000 notebook nelius had brought with him -- but still _exactly the same_ problem. we even tried uploading, cancelling and resuming multiple times, which didn't work out either (the file got corrupted). we were quite out of ideas when neon suggested that we could use the usb compactflash reader for sesse's digicam (which you might recall was lost earlier) to transfer the files... it worked first time, and quickly. THEN we discovered that gloom suddenly had used the font support in the demolib, which had been removed (ie. deleted) only hours earlier -- fortunately, there was an old backup lying around still containing the code (underscore did, as you've probably noticed by now, not have internet access, otherwise we could simply have fetched an old copy from somewhere -- hadn't the CVS server, which was situated in germany, been down, of course ;-) )... problem fixed. but gloom still wasn't content -- he wanted to transfer an update to the demo script, and neon's gsm phone (which _did_ work for voice calls) didn't work for data calls abroad... fortunately, inm was nice enough to transfer the remaining 39kB using his cell phone phoning home (of course, after his machine had had major problems, having to phone home to get somebody to reset mgetty, having problems with gnokii etc.), and after getting the remaining files over (FTP worked well first time this time, happily -- probably the network card was what was fscked, by the way, we tried multiple different cables ;-) ) we could finalize the demo, fix a few remaining bugs (although there were still some left, including a radeon mobility hang we still haven't managed to fix/reproduce -- probably caused by outdated drivers, and it magically fixed itself later on anyhow ;-) ), test it on the compo machine (or rather, test it on the _second_ compo machine, we never got to test it properly on the first one ;-) ) and sit back and wait for the demo show :-) (we even reached the second deadline this time, which was more or less identical to the original showing time -- earlier, we've been up to twelve hours late ;-) ) we really thought we could make a demo without all the stress this time, though, but it turned out to be almost exactly as bad as usual ;-) amoeba placed 1st in the pc demo competition at underscore, something we were very pleased with, although the prize was a ten year old old sparcstation we still haven't managed to get any contact with ;-) ______________________________________________ party III perhaps the most interesting part of the party was the trip home -- after taking the bus to the train station, we discovered that the train was crammed, so we asked for some place to put our luggage while looking for somewhere to sit -- something we later discovered would have been quite hopeless, as there was people almost _everywhere_. some were crouched in a corner for over four hours straight... but... sceners always know a way. we soon discovered that the luggage room would be ideal to sit in -- it wasn't too clean, it bumped a bit and the lights were flickering, but at least there was plenty of space, so we simply closed the door, found something comfortable to sit on and opened lug00ber's portable so we could get some music... so while the others were sitting outside in all sorts of weird uncomfortable positions were we quite happy, having a lot of fun with the "expedition robinson" game (which lug00ber and kusma won at underscore, and, by the way, I'd guess nobody will ever play again ;-) ). the friendly train personnel even allowed us to recharge the portable when the battery was empty, so we had music almost the whole journey (if the 220v hadn't been in a different wagon, we would have started up the flatscreen and sesse's pc, and watched movies or something ;-) ). people outside were getting more and more irritated -- now and then, we even went around taking pictures of tired and beat people. they must have thought we were drunk or something, and they must _definitely_ have heard the music and the laughter. nobody really understood why none of them came into the room asking to sit there with us ;-) pictures, video, more text etc. will be included in the forthcoming party report. ;-) _________________________________________________ efnet? *** Now talking in #underscore stefan? <@inm> gloom <@inm> Känner inte jag igen ditt nick ? bent fra excess det var du som skulle ta med demoen vår til underscore? ..som jeg nettopp fikk mail fra? <@inm> Nope.. vet jag ingenting om <@inm> Tyvärr okei, men vet du hvem stefan er? <@inm> Sorry, nope.. lator / deus ex machina? *** stefandxm (stefan@as2-4-1.bdn.g.bonet.se) has joined #underscore gloom ! der ah takk gud.. :) ircnet i meant hehe but ok ;) _________________________________________________ greets acme, appendix, array, bypass, coma, contraz, darkzone, deux ex machina, ephidrena, fairlight, gollum, granma, haujobb, inf, komplex, kvasigen, moondreamers, nocturnal, purple, progress, prone, proxima, razor 1911, rebels, sorrox, skulls, spaceballs, squirrelz, tbl, therapii, the silents, tls, unique, yaphan, #scene.no, #amigascne _________________________________________________ sweden det heter "jordbær" og "gulrot"! og ikke minst... "pølse"! mens vi snakker om pølse, hvorfor har ikke dette landet lompe? på togstasjonen henger det plakater med "slut" rett over der det står jenter... brødet er dyrt også, og sære svensker forstår ikke norsk engang (bytte over på engelsk når noen snakker til deg)... og angående jämtland og härjedalen -- få tilbake støffet vårt, for helvete!!! sees på rrrrrymdtorget... __________________ 3.14159265358979323846264338327950288 yes, it's pi. no, we didn't look it up. __________________________________________________ final this final is actually the first we got out -- a lot of problems have been fixed, most of them in the performance area, but also in the source release, some size optimizations (the final version shaves some 3MB off the party version's .dat file), some artifact fixes and some (at times) really weird compatibility fixes (shame on companies making opengl drivers that don't return errors on non-supported flags, but instead decide to magically crash at more or less random spots later on). in short, it should be quite a lot nicer to your system, especially on fillrate- and texture memory-limited systems. in addition, we have done the design-changes that were planned for the original release, but never got finished in time. deadlines suck. ___________________ excess - a very very ninja demogroup �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/�����������������������������������������������������������������������������0040755�0000000�0000000�00000000000�07557051141�013512� 5����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/memfile.cpp������������������������������������������������������������������0100644�0000000�0000000�00000002221�07407525200�015622� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #ifdef __GNUC__ #include #endif #include #include #include "demolib_prefs.h" #include "file.h" #include "memfile.h" #include "../exception.h" #if DEMOLIB_DATA_DIR_NONMMAP MemFile::MemFile(char *filename) { struct stat buf; FILE *file; int i = 0; if (stat(filename, &buf) == -1) throw new FileNotFoundException("couldn't find file in data/"); file = fopen(filename, "rb"); if (file == NULL) throw new FatalException("error in opening file in data/"); this->data = (char *)(malloc(buf.st_size)); if (this->data == NULL) throw new FatalException("Out of memory"); while (i < buf.st_size) { int num_bytes = buf.st_size - i; int err; if (num_bytes > 4096) num_bytes = 4096; err = fread(this->data + i, num_bytes, 1, file); if (err <= 0) throw new FatalException("Error on read()"); i += err * num_bytes; } this->length = buf.st_size; fclose(file); } MemFile::~MemFile() { free(this->data); } char *MemFile::get_data() { return this->data; } int MemFile::data_length() { return this->length; } #endif /* DEMOLIB_DATA_DIR_NONMMAP */ �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/Makefile���������������������������������������������������������������������0100644�0000000�0000000�00000000375�07441020032�015137� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������PACKER_OBJS=packer/file.o packer/memfile.o packer/pakfile.o \ packer/filereader.o packer/zfile.o OBJS += $(PACKER_OBJS) SUBLIBS += packer/packer.a packer/packer.a: $(PACKER_OBJS) $(AR) rc packer/packer.a $(PACKER_OBJS) $(RANLIB) packer/packer.a �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/filereader.h�����������������������������������������������������������������0100644�0000000�0000000�00000000633�07407525200�015760� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _FILEREADER_H #define _FILEREADER_H #ifdef __GNUG__ #include #endif #include #include "packer/file.h" class FileReader { public: FileReader(File *file); ~FileReader(); size_t fread(void *ptr, size_t size, size_t nmemb); size_t read(void *buf, size_t count); long ftell(); int fseek(long offset, int whence); protected: File *curr_file; size_t position; }; #endif �����������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/zfile.h����������������������������������������������������������������������0100644�0000000�0000000�00000000346�07407525200�014770� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _ZFILE_H #define _ZFILE_H #include "file.h" class ZFile : public File { public: ZFile(File *basefile); ~ZFile(); char *get_data(); int data_length(); protected: char *data; int length; }; #endif /* !_ZFILE_H */ ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/zfile.cpp��������������������������������������������������������������������0100644�0000000�0000000�00000001742�07407525200�015324� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #include #include "demolib_prefs.h" #include "file.h" #include "zfile.h" #include "../exception.h" #if DEMOLIB_DATA_ZLIB ZFile::ZFile(File *basefile) { z_stream zs; char *file_data = basefile->get_data(); /* read the file length first */ this->length = *((unsigned int *)file_data); this->data = (char *)(malloc(this->length)); if (this->data == NULL) { throw new FatalException("Out of memory!"); } memset(&zs, 0, sizeof(zs)); zs.next_in = (Bytef *)(file_data + 4); zs.avail_in = basefile->data_length() - 4; zs.next_out = (Bytef *)(this->data); zs.avail_out = this->length; if (inflateInit(&zs) != Z_OK || inflate(&zs, Z_FINISH) != Z_STREAM_END) { throw new FatalException("zlib", zs.msg); } inflateEnd(&zs); } ZFile::~ZFile() { free(this->data); } char *ZFile::get_data() { return this->data; } int ZFile::data_length() { return this->length; } #endif /* DEMOLIB_DATA_ZLIB */ ������������������������������amoeba-1.1.orig/packer/file.cpp���������������������������������������������������������������������0100644�0000000�0000000�00000002042�07441020174�015122� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Sesse's demolib */ #include #include #include #ifdef __GNUC__ #include #endif #include "demolib_prefs.h" #include "exception.h" #include "file.h" #include "memfile.h" #include "pakfile.h" #include "zfile.h" File::File() {} File::~File() {} /* * Gives a File (from data/, data.tar or the `demodata' symbol * from the exe). */ File *load_file(const char * const filename) { char fname[256]; sprintf(fname, "data/%s", filename); #if !DEMOLIB_SILENT printf("%s\n", fname); #endif #if DEMOLIB_DATA_ZLIB if (strlen(filename) > 6 && strncmp(filename, "zlib:", 5) == 0) { File *tempfile = load_file(filename + 5); ZFile *zf = new ZFile(tempfile); delete tempfile; return zf; } #endif #if DEMOLIB_DATA_DIR_NONMMAP try { return new MemFile(fname); } catch (NonFatalException *e) {} #endif #if DEMOLIB_DATA_PAKFILE try { return new PakFile(fname); } catch (NonFatalException *e) {} #endif sprintf(fname, "%s not found", filename); throw new FileNotFoundException(fname); } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/file.h�����������������������������������������������������������������������0100644�0000000�0000000�00000000344�07407525200�014574� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* virtual top class */ #ifndef _FILE_H #define _FILE_H class File { public: File(); virtual ~File(); virtual char *get_data() = 0; virtual int data_length() = 0; }; File *load_file(const char * const filename); #endif ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/memfile.h��������������������������������������������������������������������0100644�0000000�0000000�00000000362�07407525200�015273� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _MEMFILE_H #define _MEMFILE_H #include "file.h" class MemFile : public File { public: MemFile(char *filename); ~MemFile(); char *get_data(); int data_length(); protected: char *data; int length; }; #endif /* !_MEMFILE_H */ ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/pakfile.h��������������������������������������������������������������������0100644�0000000�0000000�00000000507�07407525200�015271� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _PAKFILE_H #define _PAKFILE_H #include "file.h" struct pak_direntry { char filename[56]; unsigned int pos; unsigned int size; }; class PakFile : public File { public: PakFile(char *filename); ~PakFile(); char *get_data(); int data_length(); protected: char *data; int length; }; #endif /* !_PAKFILE_H */ �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/packer/pakfile.cpp������������������������������������������������������������������0100644�0000000�0000000�00000004662�07467236770�015653� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Sesse's demolib */ #include #include #include #ifdef __linux__ #include #else #include #define strncasecmp strnicmp #endif #include #include #include #include #include "demolib_prefs.h" #include "file.h" #include "pakfile.h" #include "../exception.h" #if DEMOLIB_DATA_PAKFILE #ifndef __i386__ #define fixendianl(x) \ ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) #else #define fixendianl(x) (x) #endif PakFile::PakFile(char *filename) { char buf[12]; int err, dirpos, dirsize; unsigned int i; #if __linux__ int fd = open("demo.dat", O_RDONLY); #else int fd = open("demo.dat", O_RDONLY | O_BINARY); #endif if (fd == -1) throw new FileNotFoundException("demo.dat wasn't found"); /* first verify that this is indeed a pakfile */ err = read(fd, buf, 12); if (err != 12 || strncasecmp(buf, "PACK", 4) != 0) { throw new FatalException("demo.dat is not a valid pakfile"); } /* seek to the beginning of the directory */ dirpos = fixendianl(*(int *)(buf + 4)); if (lseek(fd, dirpos, SEEK_SET) != dirpos) { throw new FatalException("demo.dat is truncated"); } dirsize = fixendianl(*(int *)(buf + 8)); for (i = 0; i < dirsize / sizeof(struct pak_direntry); i++) { char *ptr; struct pak_direntry d; if (read(fd, (char *)(&d), sizeof(d)) != sizeof(d)) { throw new FatalException("demo.dat is truncated"); } d.pos = fixendianl(d.pos); d.size = fixendianl(d.size); d.filename[55] = 0; if (strcmp(filename, d.filename) != 0) continue; ptr = (char *)(malloc(d.size)); if (ptr == NULL) { throw new FatalException("Out of memory!"); } if (lseek(fd, d.pos, SEEK_SET) == -1) { throw new FatalException("pakfile truncated!"); } unsigned int i = 0; while (i < d.size) { int num_bytes = d.size - i; int err; if (num_bytes > 4096) num_bytes = 4096; err = read(fd, ptr + i, num_bytes); if (err <= 0) throw new FatalException("Error on read()", strerror(errno)); i += err; } this->data = ptr; this->length = d.size; close(fd); return; } throw new FileNotFoundException("file not found in demo.dat"); } PakFile::~PakFile() { free(this->data); } char *PakFile::get_data() { return this->data; } int PakFile::data_length() { return this->length; } #endif /* DEMOLIB_DATA_PAKFILE */ ������������������������������������������������������������������������������amoeba-1.1.orig/packer/filereader.cpp���������������������������������������������������������������0100644�0000000�0000000�00000002657�07500715524�016327� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* simple wrapper class to port stdio-based code easier */ #include #include #include "demolib_prefs.h" #include "filereader.h" #if DEMOLIB_DATA_FILEREADER FileReader::FileReader(File *file) { this->curr_file = file; this->position = 0; } FileReader::~FileReader() { delete this->curr_file; } size_t FileReader::fread(void *ptr, size_t size, size_t nmemb) { size_t i; for (i = 0; i < nmemb; i++) { if ((int)this->position + (int)size > (int)this->curr_file->data_length()) { return i; } memcpy((char *)(ptr) + i * size, this->curr_file->get_data() + this->position, size); this->position += size; } return i; } size_t FileReader::read(void *buf, size_t count) { if ((int)this->position + (int)count > (int)this->curr_file->data_length()) { count = this->curr_file->data_length() - this->position; } memcpy(buf, this->curr_file->get_data() + this->position, count); return count; } long FileReader::ftell() { return this->position; } int FileReader::fseek(long offset, int whence) { int real_offset; switch (whence) { case SEEK_SET: real_offset = 0; break; case SEEK_CUR: real_offset = this->position; break; case SEEK_END: real_offset = this->curr_file->data_length(); break; default: return -1; } if (real_offset + offset < 0 || real_offset + offset > this->curr_file->data_length()) { return -1; } this->position = real_offset + offset; return 0; } #endif ���������������������������������������������������������������������������������amoeba-1.1.orig/opengl/�����������������������������������������������������������������������������0040755�0000000�0000000�00000000000�07557051141�013531� 5����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/glwindow.cpp�����������������������������������������������������������������0100644�0000000�0000000�00000024662�07477157512�016110� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * The whole interface between GLWindow and the configuration stuff is rather * icky, and _should_ be rewritten. It appears to work somehow, though ;-) */ #include #ifdef WIN32 #include #endif #ifdef __linux__ #include #include #include #include #endif #include #include #include "opengl/glwindow.h" #include "exception.h" #include "demolib_prefs.h" #ifdef WIN32 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* this is ugly, but so is Win32 ;-) */ GLWindow *win; #endif void GLWindow::resize(int x, int y, int w, int h) { /* Prevent division by zero */ if (h == 0) { h = 1; } float aspect = (float)w / (float)h; if (aspect > DEMOLIB_XASPECT / DEMOLIB_YASPECT) { int new_w = (int)((float)h * DEMOLIB_XASPECT / DEMOLIB_YASPECT); x += (w - new_w) / 2; w = new_w; } else if (aspect < DEMOLIB_XASPECT / DEMOLIB_YASPECT) { int new_h = (int)((float)w * DEMOLIB_YASPECT / DEMOLIB_XASPECT); y += (h - new_h) / 2; h = new_h; } glViewport(x, y, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(53.0f, (GLfloat)w / (GLfloat)h, 1.0f, 500.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); #ifdef __linux__ // XClearWindow(this->dpy, this->win); #endif } GLWindow::GLWindow(char *title, int width, int height, int bpp, bool fullscreen, int zbuffer, int visual_id) { #ifdef WIN32 GLuint PixelFormat; WNDCLASS wc; DWORD dwExStyle; DWORD dwStyle; DEVMODE dmScreenSettings; if (visual_id != -1) { EnumDisplaySettings(NULL, visual_id, &dmScreenSettings); width = dmScreenSettings.dmPelsWidth; height = dmScreenSettings.dmPelsHeight; bpp = dmScreenSettings.dmBitsPerPel; } else { memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = width; dmScreenSettings.dmPelsHeight = height; dmScreenSettings.dmBitsPerPel = bpp; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; } win = this; RECT WindowRect; WindowRect.left = (long)0; WindowRect.right = (long)width; WindowRect.top = (long)0; WindowRect.bottom = (long)height; #endif /* WIN32 */ #ifdef __linux__ XVisualInfo *vi; int dpyWidth = 0, dpyHeight = 0; int i; XF86VidModeModeInfo **modes; int modeNum; int bestMode; Atom wmDelete; Window winDummy; unsigned int borderDummy; static int attrList[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, zbuffer, GLX_STENCIL_SIZE, 4, None }; #endif /* __linux__ */ this->x = 0; this->y = 0; this->width = width; this->height = height; this->bpp = bpp; this->fullscreen = fullscreen; this->zbuffer = zbuffer; this->done = 0; #ifdef WIN32 this->hInstance = GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = this->hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = "Excess-OGL"; if( !RegisterClass(&wc) ) throw new FatalException("Couldn't register Window Class"); #endif /* WIN32 */ #ifdef __linux__ /* set best mode to current */ bestMode = 0; /* get a connection */ this->dpy = XOpenDisplay(0); this->screen = DefaultScreen(this->dpy); if (fullscreen) { XF86VidModeGetAllModeLines(this->dpy, this->screen, &modeNum, &modes); /* save desktop-resolution before switching modes */ this->deskMode = *modes[0]; /* look for mode with requested resolution */ for (i = 0; i < modeNum; i++) { if ((modes[i]->hdisplay == width) && (modes[i]->vdisplay == height)) { bestMode = i; } } /* if we don't have it, bomb out */ if (bestMode == 0 && (modes[0]->hdisplay != width || modes[0]->vdisplay != height)) { throw new FatalException("Couldn't set requested screen mode."); } } if (visual_id != -1) { XVisualInfo tmplate; int nret; tmplate.visualid = visual_id; vi = XGetVisualInfo(this->dpy, VisualIDMask, &tmplate, &nret); if (vi == NULL) { throw new FatalException("Couldn't get selected visual!"); } } else { /* get an appropriate visual */ vi = glXChooseVisual(this->dpy, this->screen, attrList); if (vi == NULL) { throw new FatalException("Couldn't get double-buffered visual"); } } /* create a GLX context */ this->ctx = glXCreateContext(this->dpy, vi, NULL, GL_TRUE); /* create a color map (umm, needed?) */ Colormap cmap = XCreateColormap(this->dpy, RootWindow(this->dpy, vi->screen), vi->visual, AllocNone); this->attr.colormap = cmap; /* make a blank cursor */ { static char data[1] = {0}; Cursor cursor; Pixmap blank; XColor dummy; blank = XCreateBitmapFromData(this->dpy, RootWindow(this->dpy, vi->screen), data, 1, 1); if (blank == None) throw new FatalException("Out of memory!"); cursor = XCreatePixmapCursor(this->dpy, blank, blank, &dummy, &dummy, 0, 0); XFreePixmap(this->dpy, blank); this->attr.cursor = cursor; } this->attr.border_pixel = 0; #endif /* __linux__ */ /* change screen mode */ if (fullscreen) { #ifdef WIN32 if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { throw new FatalException("Couldn't set requested screen mode."); } #endif /* WIN32 */ #ifdef __linux__ XF86VidModeSwitchToMode(this->dpy, this->screen, modes[bestMode]); XF86VidModeSetViewPort(this->dpy, this->screen, 0, 0); dpyWidth = modes[bestMode]->hdisplay; dpyHeight = modes[bestMode]->vdisplay; XFree(modes); #endif /* __linux__ */ } /* create the window */ #ifdef WIN32 if (fullscreen) { dwExStyle = WS_EX_APPWINDOW; dwStyle = WS_POPUP; ShowCursor(FALSE); } else { dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); if (!(hWnd = CreateWindowEx(dwExStyle, "Excess-OGL", title, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, NULL, NULL, this->hInstance, NULL))) { delete this; throw new FatalException("Could not change screenmode"); } #endif #ifdef __linux__ this->attr.background_pixel = 0; if (fullscreen) { /* create a fullscreen window */ this->attr.override_redirect = True; this->attr.event_mask = KeyPressMask | ButtonPressMask | StructureNotifyMask; this->win = XCreateWindow(this->dpy, RootWindow(this->dpy, vi->screen), 0, 0, dpyWidth, dpyHeight, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWCursor | CWEventMask | CWOverrideRedirect, &this->attr); XWarpPointer(this->dpy, None, this->win, 0, 0, 0, 0, 0, 0); XMapRaised(this->dpy, this->win); XGrabKeyboard(this->dpy, this->win, True, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabPointer(this->dpy, this->win, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, this->win, None, CurrentTime); } else { /* create a window in window mode*/ this->attr.event_mask = KeyPressMask | ButtonPressMask | StructureNotifyMask; this->win = XCreateWindow(this->dpy, RootWindow(this->dpy, vi->screen), 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWBorderPixel | CWEventMask, &this->attr); /* only set window title and handle wm_delete_events if in windowed mode */ wmDelete = XInternAtom(this->dpy, "WM_DELETE_WINDOW", True); XSetWMProtocols(this->dpy, this->win, &wmDelete, 1); XSetStandardProperties(this->dpy, this->win, title, title, None, NULL, 0, NULL); XMapRaised(this->dpy, this->win); } #endif /* __linux__ */ #ifdef WIN32 static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bpp, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, zbuffer, 8, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; hDC = GetDC(hWnd); PixelFormat = ChoosePixelFormat(hDC, &pfd); if (PixelFormat == 0) { throw new FatalException("Could not find a usable pixelformat"); } SetPixelFormat(hDC, PixelFormat, &pfd); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); #endif /* WIN32 */ #ifdef __linux__ /* connect the glx-context to the window */ glXMakeCurrent(this->dpy, this->win, this->ctx); XClearWindow(this->dpy, this->win); XGetGeometry(this->dpy, this->win, &winDummy, &this->x, &this->y, &this->width, &this->height, &borderDummy, &this->bpp); if (!glXIsDirect(this->dpy, this->ctx)) { throw new FatalException("No direct rendering (hardware acceleration) available!"); } nice(-7); #endif /* __linux__ */ this->resize(0, 0, this->width, this->height); } GLWindow::~GLWindow() { #ifdef __linux__ if (this->ctx) { if (!glXMakeCurrent(this->dpy, None, NULL)) { throw new FatalException("Could not release drawing context."); } glXDestroyContext(this->dpy, this->ctx); this->ctx = NULL; } #endif if (fullscreen) { #ifdef __linux__ XF86VidModeSwitchToMode(this->dpy, this->screen, &this->deskMode); XF86VidModeSetViewPort(this->dpy, this->screen, 0, 0); #endif #ifdef WIN32 ChangeDisplaySettings(NULL,0); ShowCursor(TRUE); #endif } #ifdef __linux__ XCloseDisplay(this->dpy); #endif #ifdef WIN32 if (hRC) { wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); hRC = NULL; } if (hDC != NULL && ReleaseDC(hWnd, hDC)) hDC = NULL; if (hWnd != NULL && DestroyWindow(hWnd)) hWnd = NULL; UnregisterClass("Excess-OGL", hInstance); #endif } void GLWindow::flip() { #ifdef WIN32 MSG msg; if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { this->done = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } SwapBuffers(this->hDC); #endif #ifdef __linux__ glXSwapBuffers(this->dpy, this->win); #endif } bool GLWindow::is_done() { return this->done; } #ifdef WIN32 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_SYSCOMMAND: switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } break; case WM_CLOSE: PostQuitMessage(0); return 0; case WM_KEYUP: if (wParam == VK_ESCAPE) PostQuitMessage(0); return 0; case WM_SIZE: win->resize(0, 0, LOWORD(lParam), HIWORD(lParam)); return 0; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } #endif //WIN32 ������������������������������������������������������������������������������amoeba-1.1.orig/opengl/Makefile���������������������������������������������������������������������0100644�0000000�0000000�00000000404�07502415354�015164� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������OPENGL_OBJS=opengl/fpscount.o opengl/fontttf.o \ opengl/texture.o opengl/glwindow.o opengl/extensions.o OBJS += $(OPENGL_OBJS) SUBLIBS += opengl/opengl.a opengl/opengl.a: $(OPENGL_OBJS) $(AR) rc opengl/opengl.a $(OPENGL_OBJS) $(RANLIB) opengl/opengl.a ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/fontttf.cpp������������������������������������������������������������������0100644�0000000�0000000�00000012525�07477733550�015737� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #include #include "demolib_prefs.h" #if DEMOLIB_OPENGL_FONT_TTF #include #include FT_FREETYPE_H #include "fontttf.h" #include "../exception.h" #include "packer/file.h" #ifdef WIN32 #include #endif #include #include #ifndef M_PI #define M_PI 3.141592653589793238462643383279502 #endif #define PIXMAP_HEIGHT 128 #define PIXMAP_BASE 96 #define SCALE_FACTOR 0.5f FontTTF::FontTTF(File *ttffile, const char *text, int size) { if (FT_Init_FreeType(&library)) throw new FatalException("FreeType init failed."); if (FT_New_Memory_Face(library, (FT_Byte *)ttffile->get_data(), ttffile->data_length(), 0, &face)) throw new FatalException("Face opening failed."); if (FT_Set_Char_Size(face, 0, (int)(size * (64.0f/SCALE_FACTOR)), 96, 96)) throw new FatalException("Size set failed."); realwidth = width = draw_text(text, false); /* now round up to closest power-of-two */ for (int i = 0; i < 31; i++) { if (width <= (1 << i)) { width = 1 << i; break; } } texmap = (unsigned char *)(malloc(width * PIXMAP_HEIGHT)); if (texmap == NULL) throw new FatalException("Out of memory!"); memset(texmap, 0, width * PIXMAP_HEIGHT); draw_text(text, true); FT_Done_Face(face); FT_Done_FreeType(library); /* now see if we need to scale down to fit the card :-( */ GLint texwidth = width; GLint maxwidth; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxwidth); while (texwidth > maxwidth) { /* scale down in the X res only -- everybody supports 32x32 ;-) */ texwidth >>= 1; unsigned char *texmap_s = (unsigned char *)malloc(texwidth * PIXMAP_HEIGHT); if (texmap_s == NULL) throw new FatalException("Out of memory!"); for (int y = 0; y < PIXMAP_HEIGHT; y++) { unsigned char *src = texmap + y * (texwidth * 2); unsigned char *dst = texmap_s + y * texwidth; for (int x = 0; x < texwidth; x++) { unsigned int s1 = (unsigned int)(*src++); unsigned int s2 = (unsigned int)(*src++); *dst++ = (unsigned char)((s1 + s2) >> 1); } } free(texmap); texmap = texmap_s; } /* * bah, GL_ALPHA gives us RGB=0,0,0 and we want RGB=1,1,1... have * to make the RGB part ourselves. :-) */ unsigned char *texptr = (unsigned char *)malloc(texwidth * PIXMAP_HEIGHT * 2); unsigned char *inptr = texmap, *outptr = texptr; if (texptr == NULL) throw new FatalException("Out of memory!"); for (int i = 0; i < texwidth * PIXMAP_HEIGHT; i++) { *outptr++ = 255; *outptr++ = *inptr++; } glGenTextures(1, &texnum); glBindTexture(GL_TEXTURE_2D, texnum); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE8_ALPHA8, texwidth, PIXMAP_HEIGHT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, texptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); free(texptr); free(texmap); } FontTTF::~FontTTF() { glDeleteTextures(1, &texnum); } void FontTTF::draw_object(float xpos, float ypos, float red, float green, float blue, float alpha, bool additive) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glOrtho(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 10.0f); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); if (additive) { glBlendFunc(GL_SRC_ALPHA, GL_ONE); } else { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } glBindTexture(GL_TEXTURE_2D, this->texnum); glEnable(GL_TEXTURE_2D); glScalef(DEMOLIB_YASPECT / DEMOLIB_XASPECT, 1.0f, 1.0f); glTranslatef(xpos + (float)((256.0f/SCALE_FACTOR) - width) / (256.0f/SCALE_FACTOR) * 0.4f, ypos, 0.0f); glColor4f(red, green, blue, alpha); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.2f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(0.8f * ((float)width / (256.0f/SCALE_FACTOR)), 0.2f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(0.8f * ((float)width / (256.0f/SCALE_FACTOR)), 0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } int FontTTF::draw_text(const char *str, bool real_render) { FT_GlyphSlot slot = face->glyph; int x = 0; /* center the text */ if (real_render) x = (this->width - this->realwidth) / 2; for (unsigned int i = 0; i < strlen(str); i++) { if (FT_Load_Char(face, str[i], FT_LOAD_RENDER)) continue; if (real_render) { FT_Bitmap *bm = &(slot->bitmap); for (int y = 0; y < bm->rows; y++) { if (PIXMAP_BASE - slot->bitmap_top + y < 0 || PIXMAP_BASE - slot->bitmap_top + y >= PIXMAP_HEIGHT) continue; memcpy(texmap + (PIXMAP_BASE - slot->bitmap_top + y) * width + x + slot->bitmap_left, bm->buffer + y * bm->width, bm->width); } } x += slot->advance.x >> 6; } return x; } #endif ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/fontttf.h��������������������������������������������������������������������0100644�0000000�0000000�00000001167�07477516404�015401� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _FONTTTF_H #define _FONTTTF_H #include "demolib_prefs.h" #if DEMOLIB_OPENGL_FONT_TTF #include #include FT_FREETYPE_H #include "packer/file.h" class FontTTF { public: FontTTF(File *ttffile, const char *text, int size); ~FontTTF(); void draw_object(float xpos, float ypos, float red, float green, float blue, float alpha, bool additive); protected: int draw_text(const char *str, bool real_render); FT_Library library; FT_Face face; int width, realwidth; unsigned int texnum; unsigned char *texmap; }; #endif /* DEMOLIB_FONT_TTF */ #endif /* !defined(_FONTTTF_H) */ ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/fpscount.cpp�����������������������������������������������������������������0100644�0000000�0000000�00000007467�07461030276�016111� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #include #ifdef WIN32 #include #else #include #endif #include "fpscount.h" #include "../demolib_prefs.h" #include "../image/image.h" #include "../exception.h" #if DEMOLIB_FPSCOUNTER #include FPSCounter::FPSCounter() { Image *digits = load_image("digitsxp.png"); memcpy(this->digits_bm, digits->get_pixel_data(), 128 * 16 * 4); delete digits; this->reset(); } FPSCounter::~FPSCounter() { } void FPSCounter::reset() { #ifdef WIN32 this->tv[0] = GetTickCount(); this->tv[1] = GetTickCount(); this->tv[2] = GetTickCount(); this->tv[3] = GetTickCount(); this->tv[4] = GetTickCount(); this->tv[5] = GetTickCount(); this->tv[6] = GetTickCount(); this->tv[7] = GetTickCount(); this->tv[8] = GetTickCount(); this->tv[9] = GetTickCount(); #else gettimeofday(&(this->tv[0]), NULL); gettimeofday(&(this->tv[1]), NULL); gettimeofday(&(this->tv[2]), NULL); gettimeofday(&(this->tv[3]), NULL); gettimeofday(&(this->tv[4]), NULL); gettimeofday(&(this->tv[5]), NULL); gettimeofday(&(this->tv[6]), NULL); gettimeofday(&(this->tv[7]), NULL); gettimeofday(&(this->tv[8]), NULL); gettimeofday(&(this->tv[9]), NULL); #endif } float FPSCounter::getfps() { float fps; #ifdef WIN32 long now; // QueryPerformanceCounter((LARGE_INTEGER*)&now); now = GetTickCount(); #else struct timeval now; gettimeofday(&now, NULL); #endif #ifdef WIN32 fps = 10000.0f / (float)((now - this->tv[0])); #else fps = 10000000.0f / (float)((now.tv_sec - this->tv[0].tv_sec) * 1000000 + (now.tv_usec - this->tv[0].tv_usec)); #endif tv[0] = tv[1]; tv[1] = tv[2]; tv[2] = tv[3]; tv[3] = tv[4]; tv[4] = tv[5]; tv[5] = tv[6]; tv[6] = tv[7]; tv[7] = tv[8]; tv[8] = tv[9]; tv[9] = now; return fps; } void FPSCounter::draw() { char fpsstring[10]; int i; // GLuint texnum; float fps = this->getfps(); sprintf(fpsstring, "%6.2ffps", fps); memset(texbuf, 0x00, 64*16*4); for (i = 0; i <= 8; i++) { int offs = 0; if (fpsstring[i] == ' ') continue; switch (fpsstring[i]) { case '0': offs = 0; break; case '1': offs = 6; break; case '2': offs = 12; break; case '3': offs = 18; break; case '4': offs = 24; break; case '5': offs = 30; break; case '6': offs = 36; break; case '7': offs = 42; break; case '8': offs = 48; break; case '9': offs = 54; break; case '.': offs = 60; break; case 'f': offs = 66; break; case 'p': offs = 72; break; case 's': offs = 78; break; } for (int y = 0; y < 10; y++) { memcpy(this->texbuf + y*64*4 + i*6*4, this->digits_bm + y*128*4 + offs*4, 24); } } /*glGenTextures(1, &texnum); */ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 64, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, this->texbuf); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f,1.0f,0.0f,1.0f,0.0f,10.0f); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f,1.0f); glVertex3f(0.8f,0.9f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(1.0f,0.9f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(0.8f,1.0f,0.0f); glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); // glDeleteTextures(1, &texnum); } #endif ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/fpscount.h�������������������������������������������������������������������0100644�0000000�0000000�00000000607�07440260672�015545� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _FPSCOUNTER_H #define _FPSCOUNTER_H #ifndef WIN32 #include #endif class FPSCounter { public: FPSCounter(); ~FPSCounter(); void reset(); float getfps(); void draw(); protected: unsigned char digits_bm[128 * 16 * 4]; unsigned char texbuf[64 * 16 * 4]; #ifdef WIN32 long tv[10]; #else struct timeval tv[10]; #endif }; #endif /* !defined(_FPSCOUNTER_H) */ �������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/extensions.h�����������������������������������������������������������������0100644�0000000�0000000�00000000272�07443240746�016104� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _EXTENSIONS_H #define _EXTENSIONS_H namespace GLExtensions { bool has_ext(const char *extname); void *func_ptr(const char *function); } #endif /* !defined(_EXTENSIONS_H) */ ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/texture.h��������������������������������������������������������������������0100644�0000000�0000000�00000001102�07466625374�015407� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _TEXTURE_H #define _TEXTURE_H #ifdef WIN32 #include #endif #include #include "image/image.h" class Texture { public: Texture(Image *img); ~Texture(); void bind(); /* ick :-) */ int refcount; protected: GLuint texnum; void add_mipmap(GLenum ifmt, GLenum fmt, int bpp, int w, int h, int level, unsigned char *pixdata); }; namespace texture { Texture *load(const char *filename); void free(Texture *tex); GLenum get_opengl_format(int bpp); GLenum get_opengl_internal_format(int bpp); } #endif /* !defined(_TEXTURE_H) */ ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/texture.cpp������������������������������������������������������������������0100644�0000000�0000000�00000013613�07467201720�015736� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #include #include "texture.h" #include "../image/image.h" #include "../demolib_prefs.h" #include "../exception.h" #if DEMOLIB_TEXTURES #ifdef WIN32 #include #endif #include #include /* * umm, ugly, but it does the job. :-) a hash table isn't what * we want here, because we want to look up by both values... * and we don't need the extra speed anyhow. :-) besides, it gives * us less init'ing... */ struct { char texname[256]; Texture *tex; } textures[256]; int max_tex_num = -1; Texture *texture::load(const char *filename) { /* see if it is in the `cache' */ for (int i = 0; i <= max_tex_num; i++) { if (strcmp(textures[i].texname, filename) == 0 && textures[i].tex != NULL) { Texture *tex = textures[i].tex; tex->refcount++; return tex; } } Image *img = load_image(filename); Texture *tex = new Texture(img); delete img; tex->refcount = 1; max_tex_num++; strcpy(textures[max_tex_num].texname, filename); textures[max_tex_num].tex = tex; return tex; } void texture::free(Texture *tex) { if (tex == NULL) return; if (--(tex->refcount) == 0) { delete tex; for (int i = 0; i <= max_tex_num; i++) { if (textures[i].tex == tex) { textures[i].tex = NULL; while (i >= max_tex_num && textures[max_tex_num].tex == NULL) { max_tex_num--; } break; } } } } GLenum texture::get_opengl_format(int bpp) { switch (bpp) { case 8: return GL_LUMINANCE; case 16: return GL_LUMINANCE_ALPHA; case 24: return GL_RGB; case 32: return GL_RGBA; } /* better debug message later ;-) */ throw new FatalException("texture::get_opengl_format(): Unknown bpp!"); } GLenum texture::get_opengl_internal_format(int bpp) { switch (bpp) { case 8: return GL_LUMINANCE8; case 16: return GL_LUMINANCE8_ALPHA8; case 24: // return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; return GL_RGB8; case 32: // return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; return GL_RGBA8; } /* better debug message later ;-) */ throw new FatalException("texture::get_opengl_internal_format(): Unknown bpp!"); } Texture::Texture(Image *img) { int w, h; unsigned char *pixdata; /* * clip both dimensions to power-of-two (we used to do this with * 1 << (int)(floor(log((double)(x)) / log(2))), but that proved * inaccurate) */ for (w = (1<<30); w > 0; w >>= 1) { if (img->get_width() & w) { break; } } for (h = (1<<30); h > 0; h >>= 1) { if (img->get_height() & h) { break; } } pixdata = (unsigned char *)(malloc(w * h * img->get_bpp() / 8)); if (pixdata == NULL) throw new FatalException("Out of memory"); memcpy(pixdata, img->get_pixel_data(), w * h * img->get_bpp() / 8); GLenum fmt = texture::get_opengl_format(img->get_bpp()); GLenum ifmt = texture::get_opengl_internal_format(img->get_bpp()); /* now see if we need to scale down to fit the card :-( */ GLint maxsize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize); // maxsize = 256; int new_w = w, new_h = h; if (w > maxsize || h > maxsize) { if (new_w > maxsize) new_w = maxsize; if (new_h > maxsize) new_h = maxsize; unsigned char *pixdata_s = (unsigned char *)malloc(new_w * new_h * 4); if (pixdata_s == NULL) throw new FatalException("Out of memory!"); gluScaleImage(fmt, w, h, GL_UNSIGNED_BYTE, pixdata, new_w, new_h, GL_UNSIGNED_BYTE, pixdata_s); free(pixdata); pixdata = pixdata_s; w = new_w; h = new_h; } glGenTextures(1, &(this->texnum)); glBindTexture(GL_TEXTURE_2D, this->texnum); // glTexImage2D(GL_TEXTURE_2D, 0, ifmt, w, h, 0, fmt, GL_UNSIGNED_BYTE, pixdata); // this->add_mipmap(ifmt, fmt, img->get_bpp(), w, h, 0, pixdata); gluBuild2DMipmaps(GL_TEXTURE_2D, ifmt, w, h, fmt, GL_UNSIGNED_BYTE, pixdata); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); /* glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); */ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); free(pixdata); } Texture::~Texture() { glDeleteTextures(1, &(this->texnum)); } void Texture::bind() { glBindTexture(GL_TEXTURE_2D, this->texnum); } void Texture::add_mipmap(GLenum ifmt, GLenum fmt, int bpp, int w, int h, int level, unsigned char *pixdata) { if (w == 1 && h == 1) return; int comp = bpp / 8; int nw = (w == 1) ? 1 : (w >> 1); int nh = (h == 1) ? 1 : (h >> 1); unsigned char *npd = (unsigned char *)malloc(nw * nh * comp); if (npd == NULL) throw new FatalException("Out of memory!"); if (nw == 1) { /* * ick, special case, but we can fool the scaler and pretend * we have a different picture, so it works well anyhow ;-) */ nw = nh; nh = 1; } /* * general nice scaling code ;-) works for h == 1 * too, although suboptimal... who cares */ for (int y = 0; y < nh; y++) { unsigned char *src1 = (unsigned char *)(pixdata + (y*2)*w*comp); unsigned char *src2 = (unsigned char *)(pixdata + (y*2+1)*w*comp); if (h == 1) src2 = src1; unsigned char *dst = (unsigned char *)(npd + y*nw*comp); for (int x = 0; x < nw; x++) { for (int c = 0; c < comp; c++) { *dst++ = (unsigned char) (((unsigned int)(*src1) + (unsigned int)(*src2) + (unsigned int)(*(src1+comp)) + (unsigned int)(*(src2+comp))) >> 2); src1++; src2++; } src1 += comp; src2 += comp; } } /* just in case we messed with these values further up */ nw = (w == 1) ? 1 : (w >> 1); nh = (h == 1) ? 1 : (h >> 1); glTexImage2D(GL_TEXTURE_2D, level + 1, ifmt, nw, nh, 0, fmt, GL_UNSIGNED_BYTE, npd); this->add_mipmap(ifmt, fmt, bpp, nw, nh, level + 1, npd); free(npd); } #endif ���������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/glwindow.h�������������������������������������������������������������������0100644�0000000�0000000�00000001611�07466523164�015540� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#ifndef _GLWINDOW_H #define _GLWINDOW_H #ifdef WIN32 #include #endif #ifdef __linux__ #include #include #include #endif #include #include class GLWindow { public: GLWindow(char *title, int width, int height, int bpp, bool fullscreen, int zbuffer, int visual_id); ~GLWindow(); void resize(int x, int y, int w, int h); void flip(); bool is_done(); friend class DemoHandler; friend class DirectSoundAudioDriver; protected: #ifdef WIN32 HDC hDC; HGLRC hRC; HWND hWnd; HINSTANCE hInstance; #endif #ifdef __linux__ Display *dpy; int screen; Window win; GLXContext ctx; XSetWindowAttributes attr; Bool fs; XF86VidModeModeInfo deskMode; #endif char *title; bool fullscreen; int x, y; unsigned int width, height; unsigned int bpp; int zbuffer; bool done; void initGL(); }; #endif �����������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/opengl/extensions.cpp���������������������������������������������������������������0100644�0000000�0000000�00000004121�07477220160�016427� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#include #include #include #ifdef WIN32 #include #endif #include "extensions.h" #include "demolib_prefs.h" #include "exception.h" #include #if __linux__ #include #endif bool GLExtensions::has_ext(const char *ext) { /* * ATI drivers on Windows have known to be very buggy on this * extension (unless my code is really fucked up, it could of * course be), so disable it if we're using an ATI card :-) */ if (strcmp(ext, "GL_EXT_draw_range_elements") == 0) { const char *vendor = (const char *)glGetString(GL_VENDOR); if (vendor == NULL || strstr(vendor, "ATI ") != NULL) { return false; } } const char *extensions = (const char *)glGetString(GL_EXTENSIONS); if (extensions == NULL) return false; int extlen = strlen(ext); const char *ptr = extensions; while (ptr && *ptr) { if (strncmp(ptr, ext, extlen) == 0 && (ptr[extlen] == ' ' || ptr[extlen] == '\0')) { return true; } ptr = strchr(ptr, ' '); if (ptr != NULL) ptr++; } return false; } void *GLExtensions::func_ptr(const char *function) { #if __linux__ void *ptr = (void *)glXGetProcAddressARB((GLubyte *)function); #else void *ptr = (void *)wglGetProcAddress(function); #endif /* * Some OpenGL drivers (like the Kyro2 drivers on Linux) expose stuff * like glDrawRangeElements but _not_ glDrawRangeElementsEXT, even * though they advertise the extension. Thus, if getting an -EXT or * -ARB function pointer fails (which it should _never_ do, since we * always check for extension availability first), we simply try * without the suffix before finally giving up. */ const char *suffix = function + strlen(function) - 3; /* ugly? ;-) */ if (ptr == NULL && (strcmp(suffix, "EXT") == 0 || strcmp(suffix, "ARB") == 0)) { char *tmp = strdup(function); tmp[strlen(tmp) - 3] = '\0'; #if __linux__ ptr = (void *)glXGetProcAddressARB((GLubyte *)tmp); #else ptr = (void *)wglGetProcAddress(tmp); #endif free(tmp); } if (ptr == NULL) { throw new FatalException(function, "Not found in OpenGL libraries!"); } return ptr; } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/Makefile.dep������������������������������������������������������������������������0100644�0000000�0000000�00000000532�07446472510�014455� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������DEPS = $(OBJS:.o=.d) DEPCXX=$(CXX) ifeq ($(DESTPLATFORM),linux) ifeq ($(LINUXVARIANT),icc) DEPCXX=g++-3.0 endif endif %.d: %.cpp @echo Remaking dependencies for $< \(in $@\)... @$(SHELL) -ec '$(DEPCXX) -MM $(CPPFLAGS) $< \ | sed '\''s,\($*\)\.o[ :]*,\1.o $@ : ,g'\'' > $@; \ [ -s $@ ] || rm -f $@' # 2>/dev/null -include $(DEPS) ����������������������������������������������������������������������������������������������������������������������������������������������������������������������amoeba-1.1.orig/exception.h�������������������������������������������������������������������������0100644�0000000�0000000�00000001660�07407525200�014410� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * generic exception class */ class Exception { public: Exception(const char *msg); Exception(const char *owner, const char *msg); ~Exception(); char *get_error(); int get_fatal(); protected: char *str; }; class FatalException : public Exception { public: FatalException(const char *msg); FatalException(const char *owner, const char *msg); // char *get_error(); int get_fatal(); }; class NonFatalException : public Exception { public: NonFatalException(const char *msg); NonFatalException(const char *owner, const char *msg); // char *get_error(); int get_fatal(); }; class ValueNotSpecifiedException : public FatalException { public: ValueNotSpecifiedException(const char *msg); ValueNotSpecifiedException(const char *owner, const char *msg); }; class FileNotFoundException : public NonFatalException { public: FileNotFoundException(const char *msg); FileNotFoundException(const char *owner, const char *msg); }; ��������������������������������������������������������������������������������amoeba-1.1.orig/demolib_prefs.h���������������������������������������������������������������������0100755�0000000�0000000�00000001737�07502417132�015234� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Compile-time prefs settings */ /* define for a `silent' demo (no enter/leave messages etc.) */ #define DEMOLIB_SILENT 1 /* these need their appropriate libs */ #define DEMOLIB_IMAGE_JPEG 1 #define DEMOLIB_IMAGE_PNG 1 /* general vector routines -- at least the 3D stuff _needs_ this */ #define DEMOLIB_MATH_VECTOR 1 #define DEMOLIB_DATA_DIR_NONMMAP 0 #define DEMOLIB_DATA_PAKFILE 1 /* this one is needed by the .ogg handler, specifically */ #define DEMOLIB_DATA_FILEREADER 1 /* this one reads raw zlib compressed files -- needs zlib, of course :-) */ #define DEMOLIB_DATA_ZLIB 1 #define DEMOLIB_TEXTURES 1 #define DEMOLIB_FPSCOUNTER 0 #define DEMOLIB_BLOBS 0 #define DEMOLIB_OPENGL_FONT_TTF 1 /* needs the expat XML parser :-D */ #define DEMOLIB_MAINLOOP 1 /* the sound system -- needs libvorbis/libvorbisfile/libogg ATM */ #define DEMOLIB_SOUND 1 /* define the wanted screen's X and Y aspects */ #define DEMOLIB_XASPECT 4.0f #define DEMOLIB_YASPECT 3.0f ���������������������������������amoeba-1.1.orig/COPYING�����������������������������������������������������������������������������0100644�0000000�0000000�00000043655�07502420066�013306� 0����������������������������������������������������������������������������������������������������ustar �root����������������������������root������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������