From f9969775e6d2f798a3bfea5c58fc5478dad07eae Mon Sep 17 00:00:00 2001 From: pixel Date: Sat, 27 Nov 2004 21:48:01 +0000 Subject: Large dos2unix commit... --- src/test.cc | 2616 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 1308 insertions(+), 1308 deletions(-) (limited to 'src/test.cc') diff --git a/src/test.cc b/src/test.cc index 410cfb2..3219004 100644 --- a/src/test.cc +++ b/src/test.cc @@ -1,1308 +1,1308 @@ -#include -#define _USE_MATH_DEFINES -#include -#include -#include -//#include -//#include -//#include -#ifdef HAVE_CONFIG_H -#include "config.h" -#else -#endif -//#include "gettext.h" -#include -#include -#include -#include -#include -#include -//#include -//#include -#include "glbase.h" -#include "texture.h" -#include "glfont.h" -#include "glwidgets.h" -#include "engine.h" -#include "glsprite.h" -#include "glshape.h" -#include "glwidgets.h" - -#if 1 - -#define TRTIME 1500 -#define SPIN .50 -#define TILT .20 - -#define NBSTARS 300 -#define STARSRATE 300.0 - -#define SPHERE - -int zoom = 1; - -#define centerx 320 -#define centery 240 - -struct tdvect { - double x, y, z; -}; - -std::vector points; -std::vector ppoints; - -#if 0 -static int myprint(lua_State * L) { - const char * t = lua_tostring(L, -1); - - Base::printm(M_INFO, "From LUA: %s\n", t); - - return 0; -} - -static int myluaputstar(lua_State * L) { - tdvect t; - - t.x = lua_tonumber(L, -3); - t.y = lua_tonumber(L, -2); - t.z = lua_tonumber(L, -1); - - points.push_back(t); - - return 0; -} - -int myluaerror(lua_State * L) { - int n = lua_gettop(L); - int i; - String t; - - Base::printm(M_ERROR, "Got an LUA error\n"); - Base::printm(M_ERROR, "Inspecting LUA stack\n"); - - if (n == 0) { - Base::printm(M_ERROR, "Stack empty\n"); - return 0; - } - - for (i = 1; i <= n; i++) { - switch(lua_type(L, i)) { - case LUA_TNONE: - t = "Invalid"; - break; - case LUA_TNIL: - t = "(Nil)"; - break; - case LUA_TNUMBER: - t.set("(Number) %f", lua_tonumber(L, i)); - break; - case LUA_TBOOLEAN: - t.set("(Bool) %s", lua_toboolean(L, i) ? "true" : "false"); - break; - case LUA_TSTRING: - t.set("(String) %s", lua_tostring(L, i)); - break; - case LUA_TTABLE: - t.set("(Table)"); - break; - case LUA_TFUNCTION: - t = "(Function)"; - break; - default: - t = "Unknown"; - } - - Base::printm(M_ERROR, String(i) + ": " + t + "\n"); - } - - return 0; - - getchar(); -} -#endif - -unsigned int swap32(unsigned int w) { - return (w >> 24) | ((w >> 8) & 0x0000ff00) | ((w << 8) & 0x00ff0000) | (w << 24); -} - -unsigned int readB32(FILE * f) { - unsigned int r; - fread(&r, 1, 4, f); - return swap32(r); -} - -unsigned short readB16(FILE * f) { - unsigned char t[2]; - fread(t, 1, 2, f); - return t[1] | (t[0] << 8); -} - -float tofloat(unsigned int w) { - return *((float *) &w); -} - -char * sread(FILE * f) { - char temp[256], * p = temp; - - do { - *p = fgetc(f); - } while (*(p++)); - - return strdup(temp); -} - -char * pname[16] = { - "Unknown (not a float)", - "ScalX", - "ScalY", - "ScalZ", - "Unknown (not a float)", - "Unknown (not a float)", - "TransX", - "TransY", - "TransZ", - "Unknown", - "Unknown", - "Unknown", - "Unknown", - "Unknown", - "Unknown", - "Unknown" -}; - -#define OUTPUT stdout - -unsigned short entries; -struct tdvect * mesh; - -int bdlload(char * name) { - FILE * bdl; - int i, j; - char sig[9], sec[5], ** bnames; - unsigned int length, fpos, namespos, tpos, npos, r; - unsigned short * unks; - float f; - - if (!(bdl = fopen(name, "rb"))) - exit(-1); - - fread(sig, 1, 8, bdl); - sig[8] = 0; - - if (strcmp(sig, "J3D2bdl4")) { - fprintf(OUTPUT, "File not bdl.\n"); - exit(-1); - } - - fprintf(OUTPUT, "Looking for section JNT1...\n"); - - fseek(bdl, 32, SEEK_SET); - - do { - fread(sec, 1, 4, bdl); - sec[4] = 0; - length = readB32(bdl); - fprintf(OUTPUT, "Found section `%s' @ %08x, size %08x\n", sec, ftell(bdl) - 8, length); - fseek(bdl, length - 8, SEEK_CUR); - } while (strcmp(sec, "JNT1")); - - fseek(bdl, -length, SEEK_CUR); - fpos = ftell(bdl); - - fprintf(OUTPUT, "Found it at 0x%08x\n", fpos); - - fseek(bdl, 8, SEEK_CUR); - - entries = readB16(bdl); - if (readB16(bdl) != 0xffff) { - fprintf(OUTPUT, "Something's wrong, not found FFFF\n"); - } - if (readB32(bdl) != 0x18) { - fprintf(OUTPUT, "Something's wrong, bones not at 0x18, can't go on.\n"); - exit(-1); - } - if (readB32(bdl) != (0x18 + entries * 0x40)) { - fprintf(OUTPUT, "Something's wrong, bone index not at expected place, can't go on.\n"); - exit(-1); - } - - namespos = readB32(bdl); - - fprintf(OUTPUT, "Reading names.\n"); - - bnames = (char **) malloc(entries * sizeof(char *)); - unks = (unsigned short *) malloc(entries * sizeof(unsigned short)); - mesh = (struct tdvect *) malloc(entries * sizeof(struct tdvect)); - - fseek(bdl, namespos + fpos + 4, SEEK_SET); - - for (i = 0; i < entries; i++) { - unks[i] = readB16(bdl); - npos = readB16(bdl) + fpos + namespos; - tpos = ftell(bdl); - fseek(bdl, npos, SEEK_SET); - bnames[i] = sread(bdl); - fseek(bdl, tpos, SEEK_SET); - } - for (i = 0; i < entries; i++) { - fprintf(OUTPUT, "%02x: (%04x) `%s'\n", i, unks[i], bnames[i]); - } - - fprintf(OUTPUT, "Dumping bones\n"); - - fseek(bdl, fpos + 0x18, SEEK_SET); - - for (i = 0; i < entries; i++) { - fprintf(OUTPUT, "Bone #%02x (%s):\n", i, bnames[i]); - for (j = 0; j < 16; j++) { - r = readB32(bdl); - f = tofloat(r); - fprintf(OUTPUT, "%x: %08x - %9.5f - %s\n", j, r, f, pname[j]); - switch(j) { - case 6: - mesh[i].x = f; - break; - case 7: - mesh[i].y = f; - break; - case 8: - mesh[i].z = f; - break; - } - } - } - - return 0; -} - - -CODE_BEGINS - -#if 0 -void checkluastack(lua_State * L) { - int n = lua_gettop(L); - int i, j; - String t; - - printm(M_INFO, "Inspecting LUA stack\n"); - - if (n == 0) { - printm(M_INFO, "Stack empty\n"); - return; - } - - for (i = 1; i <= n; i++) { - switch(lua_type(L, i)) { - case LUA_TNONE: - t = "Invalid"; - break; - case LUA_TNIL: - t = "(Nil)"; - break; - case LUA_TNUMBER: - t.set("(Number) %f", lua_tonumber(L, i)); - break; - case LUA_TBOOLEAN: - t.set("(Bool) %s", lua_toboolean(L, i) ? "true" : "false"); - break; - case LUA_TSTRING: - t.set("(String) %s", lua_tostring(L, i)); - break; - case LUA_TTABLE: - printm(M_INFO, String(i) + ": (Table) Exploring:\n"); - lua_pushnil(L); /* first key */ - j = 0; - while (lua_next(L, -2) != 0) { - /* `key' is at index -2 and `value' at index -1 */ - printm(M_INFO, " %s - %s\n", lua_typename(L, lua_type(L, -2)), - lua_typename(L, lua_type(L, -1))); - lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */ - } - t = ""; - break; - case LUA_TFUNCTION: - t = "(Function)"; - break; - default: - t = "Unknown"; - } - - if (t != "") - printm(M_INFO, String(i) + ": " + t + "\n"); - } -} -#endif - -void putstar(double x, double y, double z, mogltk::Sprite * s) { - double tx, ty, tz; - double spin, tilt; - - spin = (mogltk::engine::mouseX() - centerx) / 80.0; - tilt = (mogltk::engine::mouseY() - centery) / 80.0; - - // Spin --> around y - - tx = x * cos(spin) + z * sin(spin); - tz = -x * sin(spin) + z * cos(spin); - - x = tx; - z = tz; - - - // tilt --> around x - - ty = y * cos(tilt) + z * sin(tilt); - tz = -y * sin(tilt) + z * cos(tilt); - - y = ty; - z = tz; - - tdvect t; - t.x = x; - t.y = y; - t.z = z; - -// s->draw(centerx + t.x * zoom * mogltk::engine::mouseZ() - s->GetSX() / 2, centery + t.y * zoom * mogltk::engine::mouseZ() - s->GetSY() / 2); - ppoints.push_back(t); -} - -double t; - -#ifdef STARSCAPE -int starsx[NBSTARS]; -int starsy[NBSTARS]; -#endif - -#ifdef SPHERE -double starst[NBSTARS]; -double starso[NBSTARS]; -#endif - -//lua_State * L; - -void initstars() { - int i; -#ifdef STARSCAPE - for (i = 0; i < NBSTARS; i++) { - starsx[i] = rand() % 640; - starsy[i] = rand() % 480; - } - - t = 0; -#endif -#ifdef RING - t = 0; -#endif -#ifdef SPHERE - t = 0; - for (i = 0; i < NBSTARS; i++) { - starst[i] = -(rand() % 3000) / 1000.0; - starso[i] = 2 * ((rand() % 1000) / 1000.0) * M_PI; - } -#endif -#ifdef LUA - L = lua_open(); - luaopen_math(L); - lua_pop(L, 1); - lua_atpanic(L, myluaerror); - luaL_loadfile(L, "particules.lua"); - lua_call(L, 0, 0); - lua_pushstring(L, "putstar"); - lua_pushcfunction(L, myluaputstar); - lua_settable(L, LUA_GLOBALSINDEX); - lua_pushstring(L, "print"); - lua_pushcfunction(L, myprint); - lua_settable(L, LUA_GLOBALSINDEX); - lua_pushstring(L, "initstars"); - lua_gettable(L, LUA_GLOBALSINDEX); - lua_call(L, 0, 0); -#endif -} - -void displaystars(mogltk::Sprite * s) { - int i; - double x, y, z, st; - tdvect tv; - -#ifdef STARSCAPE - for (i = 0; i < NBSTARS; i++) { - s->draw(starsx[i], starsy[i]); - } -#endif -#ifdef RING - for (i = 0; i < NBSTARS; i++) { - putstar(cos(t + i * 2 * M_PI / NBSTARS), 0, sin(t + i * 2 * M_PI / NBSTARS), s); - } -#endif -#ifdef SPHERE - for (i = 0; i < NBSTARS; i++) { - st = t - starst[i]; - - y = st / 3.0; - - x = cos(st * 2 * M_PI + starso[i]) * sin(y * M_PI); - z = sin(st * 2 * M_PI + starso[i]) * sin(y * M_PI); - - y = cos(y * M_PI); - - putstar(x, y, z, s); - } -#endif -#ifdef LUA - lua_pushstring(L, "displaystars"); - lua_gettable(L, LUA_GLOBALSINDEX); - lua_call(L, 0, 0); - - for (std::vector::iterator i = points.begin(); i != points.end(); i++) { - tv = *i; - putstar(tv.x, tv.y, tv.z, s); - } - points.clear(); -#endif -#ifdef BDL - for (i = 0; i < entries; i++) { - putstar(mesh[i].x / 20, mesh[i].y / 20, mesh[i].z / 20, s); - } -#endif - while (!ppoints.empty()) { - std::vector::iterator m = ppoints.begin(); - for (std::vector::iterator i = ppoints.begin(); i != ppoints.end(); i++) { - if (i->z > m->z) - m = i; - } - tv = *m; - ppoints.erase(m); - // Only bare projecting... for now... - s->draw(centerx + tv.x * zoom * mogltk::engine::mouseZ() - s->GetSX() / 2, centery + tv.y * zoom * mogltk::engine::mouseZ() - s->GetSY() / 2); - } -} - -void incrementstars(double nt) { - int i; - -#ifdef STARSCAPE - while ((t + (1 / STARSRATE)) <= nt) { - t += 1 / STARSRATE; - - for (i = 0; i < NBSTARS; i++) { - if ((++starsx[i]) >= 640) { - starsx[i] = 0; - starsy[i] = rand() % 480; - } - } - } -#endif -#ifdef RING - t = nt; -#endif -#ifdef SPHERE - t = nt; - - for (i = 0; i < NBSTARS; i++) { - if ((starst[i] + 3) < t) { - starst[i] += 3.0; - starso[i] = 2 * ((rand() % 1000) / 1000.0) * M_PI; - } - } -#endif -#ifdef LUA - t = nt; - - lua_pushstring(L, "incstars"); - lua_gettable(L, LUA_GLOBALSINDEX); - lua_pushnumber(L, t); - lua_call(L, 1, 0); -#endif -} - -class testkey_t : public mogltk::engine::keyevent { - public: - virtual void down(SDL_keysym keysym) { - if (keysym.sym == SDLK_SPACE && !start_transit) { - start_transit = true; - transit_time = SDL_GetTicks(); - } else if (old_handler) - old_handler->down(keysym); - } - virtual void up(SDL_keysym keysym) { - if (old_handler) - old_handler->up(keysym); - } - bool start_transit; - Uint32 transit_time; -} * testkey; - -void affiche_grille(mogltk::shape * sh, mogltk::texture * tex, int grille[41][31][2]) { - int x, y, tx1, tx2, ty1, ty2; - static mogltk::ColorP w = WHITE; - - w.Bind(); - tex->Bind(); - -// sh->box(0, 0, 640, 480, BLACK); - for (y = 0; y < 30; y++) { - for (x = 0; x < 40; x++) { - tx1 = x * 20; - ty1 = y * 20; - tx2 = x * 20 + 20; - ty2 = y * 20 + 20; - -#if 1 - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2i(tx1, ty1); glVertex2i(grille[x ][y ][0], grille[x ][y ][1]); - glTexCoord2i(tx2, ty1); glVertex2i(grille[x + 1][y ][0], grille[x + 1][y ][1]); - glTexCoord2i(tx1, ty2); glVertex2i(grille[x ][y + 1][0], grille[x ][y + 1][1]); - glTexCoord2i(tx2, ty2); glVertex2i(grille[x + 1][y + 1][0], grille[x + 1][y + 1][1]); - glEnd(); -#else - sh->line(grille[x ][y ][0], grille[x ][y ][1], - grille[x + 1][y ][0], grille[x + 1][y ][1]); - sh->line(grille[x + 1][y ][0], grille[x + 1][y ][1], - grille[x + 1][y + 1][0], grille[x + 1][y + 1][1]); - sh->line(grille[x + 1][y + 1][0], grille[x + 1][y + 1][1], - grille[x ][y + 1][0], grille[x ][y + 1][1]); - sh->line(grille[x ][y + 1][0], grille[x ][y + 1][1], - grille[x ][y ][0], grille[x ][y ][1]); -#endif - } - } -} - -virtual int startup() throw (GeneralException) { - bool flag = false, flag2 = false; - mogltk::texture * sshot = 0, * plastex = new mogltk::texture(1024, 512); - int x, y, sx1, sx2, sy1, sy2, lastframe, curframe, px, py, lasttick = 0, curtick = 0, oldblend, seconds = 0, newseconds = 0; - double t = 0; - verbosity = M_INFO; - String str; - bool got_transit = false; - Uint8 * plasma = (Uint8 *) malloc(640 * 480), * pplasma; - int grille[41][31][2]; - double seeds[41][31]; - double speeds[41][31]; - -#if 0 - srand(25); - for (y = 0; y < 31; y++) { - for (x = 0; x < 41; x++) { - seeds[x][y] = 1.2 * (double) (rand() % 10000) / 10000; - speeds[x][y] = 2.6 * (double) (rand() % 10000) / 10000; - } - } -#endif - - testkey = new testkey_t(); - - mogltk::engine::setmouseZ(50); - -#if 0 - -#if 0 - Lua * l = new Lua(); - LuaInput::pushconstruct(l); - LuaOutput::pushconstruct(l); - LuaBuffer::pushconstruct(l); - l->open_math(); - l->declarefunc("print", myprint); -#if 0 - l->load(&Input("particules.lua"), false); - l->dump(&Output("particules.out")); - l->call(); -#else - l->load(&Input("particules.out")); -#endif -// l->call("testing"); - delete l; -#endif - -// bdlload("cl.bdl"); - -#endif - - Input pl("plasma.raw"); - pl.read(plasma, 640 * 480); - - pplasma = (Uint8 *) plastex->GetPixels(); - - for (y = 0; y < 480; y++) { - for (x = 0; x < 640; x++) { - pplasma[((y * 1024) + x) * 4 + 3] = 255 - plasma[(y * 640) + x]; - } - } - - new Archive("datas.paq"); - -#if 1 - mogltk::base * gl = new mogltk::glbase(); - mogltk::shape * sh = new mogltk::glshape(); - mogltk::font * font = new mogltk::glfont(&Input("font-2.bin")); - mogltk::glSprite * s = new mogltk::glSprite(&Input("cursor.rgba"), 25, 25); - mogltk::texture * sol = new mogltk::texture(&Input("sol.tex")); - mogltk::glSprite * logo = new mogltk::glSprite(&Input("logo.raw"), 165, 124); -#if 0 - mogltk::Sprite * p = new mogltk::glSprite(&Input("particule.rgba"), 16, 16); - mogltk::glSprite * spr = new mogltk::glSprite(&Input("015_Over-Mind.raw"), 347, 328); - mogltk::glSprite * eD1 = new mogltk::glSprite(&Input("elkyaD1.raw"), 53, 100); - mogltk::glSprite * eG1 = new mogltk::glSprite(&Input("elkyaG1.raw"), 53, 100); - mogltk::glSprite * eM1 = new mogltk::glSprite(&Input("elkyaM1.raw"), 53, 100); -// mogltk::glSprite * spr = new mogltk::glSprite(&Input("test.raw"), 200, 200); -#endif - mogltk::widget * w = new mogltk::widgets::Root(sh); -#else - mogltk::base * gl = new mogltk::base(); - mogltk::shape * sh = new mogltk::shape(); - mogltk::font * font = new mogltk::font(&Input("font-2.bin")); - mogltk::Sprite * s = new mogltk::Sprite(&Input("cursor.rgba"), 25, 25); - mogltk::Sprite * p = new mogltk::Sprite(&Input("particule.rgba"), 16, 16); - mogltk::Sprite * spr = new mogltk::Sprite(&Input("015_Over-Mind.raw"), 347, 328); - mogltk::widget * w = new mogltk::Root(sh); -#endif - - mogltk::texture * ttex = 0; - - font->setcolor(WHITE); - font->setshadow(2); -#if 0 - mogltk::rect textrect; - mogltk::texture * text = font->printtex(&textrect, - "PixelPawa!\n" - "It works!!\n" - "I can't believe it!\n" - ); - SDL_SaveBMP(text->GetSurface(), "test-font.bmp"); - textrect.x = 10; - textrect.y = 30; -#endif - - mogltk::engine::setcursorvisible(true); - mogltk::engine::setappactive(true); - -#if 0 - mogltk::texture * mytex = new mogltk::texture(&Input("pattern6.tex"), true); - - Color AlphaBlue(AQUA); - AlphaBlue.A = 50; - - mogltk::fill * f = sh->fcircle(320, 240, 50); - - initstars(); - - px = 200; - py = 350; -#endif -#if 0 - new mogltk::widgets::Button(0, sh, - new mogltk::widgets::SmartBox(sh, w, 120, 50, 100, 100, "Test"), - 12, 30, 50, 20, "Toto"); -#endif - new mogltk::widgets::Frame(sh, w, 10, 10, 600, 400); - //new mogltk::widgets::MsgBox(sh, w, "Test", "Blablabla\nCeci est un test de la\nclasse MsgBox."); - - class tLabel : public mogltk::widgets::Label { - public: - tLabel(mogltk::shape * sh, mogltk::widget * father) : Label(sh, father, 250, 200, 16, 16, "I"), tick(0) { set_timed_event(500); } - virtual bool process_event(int mx, int my, mogltk::event_t event) { - if (Label::process_event(mx, my, event)) - return true; - - if (event == mogltk::E_TIMER) { - set_timed_event(500); - tick = (tick + 1) % 4; - switch (tick) { - case 0: - caption = "I"; - break; - case 1: - caption = "/"; - break; - case 2: - caption = "-"; - break; - case 3: - caption = "\\"; - break; - } - } - } - private: - int tick; - }; - - mogltk::widgets::ContextMenu * c, * c2; - //c = new mogltk::widgets::ContextMenu(sh, w, 20, 20); - mogltk::widgets::Menu * sm; - - new mogltk::widgets::SmartBox(sh, w, 250, 300, 100, 70, "SmartBox"); - sm = new mogltk::widgets::Menu(sh, w); - - sm->addnode("Toto", 0); - sm->addnode("Titi", 0); - sm->addnode("Tutu", 0); - -#if 0 - c->addnode("Test", 0); - c->addnode("Test2", 0); - c->addline(); - c->addnode("Test3", 0); - c->addnode("Test of a long entry", 0); - - c2 = c->createsub("Sub"); - c2->addnode("A sub", 0); - c2->createsub("subsub")->addnode("Toto", 0); - c2->SetEnabled(0, false); -#endif - - c = sm->createsub("Sub Menu"); - c->addnode("Blah1", 0); - c->addnode("Blah2", 0); - c->addnode("Blah3", 0); - c->addline(); - c2 = c->createsub("SubBlah"); - c2->addnode("SubBlah1", 0); - c2->addnode("SubBlah2", 0); - - sm->MoveOnTop(); - - new tLabel(sh, w); - - w->mainloop(); - - while (!mogltk::engine::quitrequested()) { -#if 0 - sx1 = 320 + 320 * sin(0.983 * t + 3.15); - sx2 = 320 + 320 * sin(0.537 * t + 5.32); - sy1 = 240 + 240 * sin(0.692 * t + 8.21); - sy2 = 240 + 240 * sin(1.029 * t + 2.42); -#endif - - gl->Enter2DMode(); - -#if 1 - if (got_transit) - goto do_transit; -#endif - -#if 0 - w->fulldraw(); - - sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); - //sh->box(400, 100, 450, 150, BLACK, RED, LIME, BLUE); - - sh->box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); - mogltk::ColorP::Max.A = 100; - //sh->box(5, 5, 400, 300, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); - mogltk::ColorP::Max.A = 255; -#if 1 - font->setshadow(1); - font->putcursor(10, 30); - mogltk::ColorP::Max.A = sy1 / 2; - font->setcolor(Color(sy1 / 2, sy1 / 2, sy1 / 2, sy1 / 2)); - font->printf( - "PixelPawa!\n" - "It works!!\n" - "I can't believe it!\n" - ); - mogltk::ColorP::Max.A = 255; - font->setcolor(WHITE); -#else - sh->tbox(text, textrect.x, textrect.y, textrect.x + textrect.w, textrect.y + textrect.h); -#endif - - sh->box3d(50, 150, 150, 200); - sh->obox3d(50, 250, 150, 300); - sh->window(50, 350, 150, 400, "Titre plus beau ;)"); - sh->box3d(180, 130, 320, 220); - sh->button(200, 150, 300, 200, "Bouton"); - - sh->fdraw(f, BLUE); - sh->sdraw(f); - - eM1->drawrotate(500, 400, sx1); - - curtick = (SDL_GetTicks() / 250) % 4; - - if (curtick != lasttick) { - px -= 10; - py += 5; - - if (px < -53) - px = 640; - if (px > 640) - px = -53; - if (py > 480) - py = -100; - lasttick = curtick; - } - - switch(curtick) { - case 0: - eM1->draw(px, py, WHITE, 1, 1); - break; - case 1: - eD1->draw(px, py, WHITE, 1, 1); - break; - case 2: - eM1->draw(px, py, WHITE, 1, 1); - break; - case 3: - eG1->draw(px, py, WHITE, 1, 1); - break; - } - - sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); - mogltk::ColorP::Min.A = 200; - sh->obox(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); - mogltk::ColorP::Min.A = 0; - - p->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 8); - sh->line(320, 240, mogltk::engine::mouseX(), mogltk::engine::mouseY()); - - mogltk::ColorP::Min.A = 200; - p->draw(sx1 - 8, sy1 - 8, AlphaBlue); - p->draw(sx2 - 8, sy2 - 8, AlphaBlue); - - displaystars(p); - incrementstars(t); - - sh->box(0, 0, 640, 480, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); - -#endif -// sh->box(0, 0, 640, 480, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); - - int x, y; - -#if 0 - for (y = 0; y < 31; y++) { - for (x = 0; x < 41; x++) { - grille[x][y][0] = x * 16 + 8 * sin(t * 6 + (x + y) / 2.0); - grille[x][y][1] = y * 16 + 8 * cos(t * 6 + (x + y) / 2.0); - } - } -#endif - double dis, xdis, ydis, xpos, ypos, norm, tt, tt1; - - t += 48; - - tt = t - (((int) t) / 58) * 58; - - if (tt <= 20) { - flag = flag2 = false; - for (y = 0; y < 31; y++) { - for (x = 0; x < 41; x++) { - xpos = x - 20.5; - ypos = y - 15.5; - norm = sqrt(xpos * xpos + ypos * ypos); - xpos /= norm; - ypos /= norm; - dis = sin(t * 6 - norm); - xdis = dis * sin(xpos); - ydis = dis * sin(ypos); - grille[x][y][0] = (((x * 16 + 16 * xdis) - 320) * 1.08) + 320; - grille[x][y][1] = (((y * 16 + 16 * ydis) - 240) * 1.08) + 240; - } - } - - affiche_grille(sh, sol, grille); - if (tt < 4) - sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * ((4 - tt) / 4))); - else if (tt > 16) - sh->box(0, 0, 640, 480, Color(0, 0, 0, 255 * ((tt - 16) / 4))); - } else if (tt <= 23) { - tt -= 20; - sh->box(0, 0, 640, 480, BLACK); - for (y = 0; y < 31; y++) { - for (x = 0; x < 41; x++) { - grille[x][y][0] = ((((x * 16 + 8 * sin(t * 6 + (x + y) / 2.0)) - 320) * 1.08) + 320) * tt / 3; - grille[x][y][1] = ((((y * 16 + 8 * cos(t * 6 + (x + y) / 2.0)) - 200) * 1.08) + 200) * tt / 3; - } - } - affiche_grille(sh, sol, grille); - } else if (tt <= 36) { - for (y = 0; y < 31; y++) { - for (x = 0; x < 41; x++) { - grille[x][y][0] = (((x * 16 + 8 * sin(t * 6 + (x + y) / 2.0)) - 320) * 1.08) + 320; - grille[x][y][1] = (((y * 16 + 8 * cos(t * 6 + (x + y) / 2.0)) - 200) * 1.08) + 200; - } - } - affiche_grille(sh, sol, grille); - } else if (tt <= 38) { - tt -= 36; - if (!flag2) { - sshot = gl->GrabTexture(); - flag2 = true; - } - sh->tbox(sshot, 0, 0, 640, 480); - if (tt <= 0.1) { - sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * (tt / 0.1))); - } else if (tt < 0.5) { - tt -= 0.1; - sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * ((0.4 - tt) / 0.4))); - sh->box(0, 0, 640, 480, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127 * (tt / 0.4))); - } else { - sh->box(0, 0, 640, 480, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127)); - } - for (y = 0; y < 15; y++) { - for (x = 0; x < 20; x++) { - sh->obox(x * 32, y * 32, x * 32 + 32, y * 32 + 32, WHITE); - } - } - } else if (tt <= 42) { - int xx, yy, tyy; - double ttt; - tt -= 38; - sh->box(0, 0, 640, 480, BLACK); - for (y = 14; y >= 0; y--) { - for (x = 19; x >= 0; x--) { - double d = (33.0 - x - y) / 16.5; - xx = x * 32; - tyy = y * 32; - if (tt <= d) { - yy = y * 32; - } else { - ttt = tt - d; - yy = y * 32 + ttt * ttt * ttt * 60; - } - sh->tbox(sshot, xx, yy, xx + 32, yy + 32, xx, tyy, xx + 32, tyy + 32); - sh->box(xx, yy, xx + 32, yy + 32, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127)); - sh->obox(xx, yy, xx + 32, yy + 32, WHITE); - } - } - } else if (tt <= 43) { - sh->box(0, 0, 640, 480, BLACK); - } else if (tt <= 48) { - tt -= 43; - sh->tbox(sol, 0, 0, 640, 480, 0, 0, 800, 600); - glDisable(GL_BLEND); - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, tt / 5); - sh->tbox(plastex, 0, 0, 640, 480); - glDisable(GL_ALPHA_TEST); - glEnable(GL_BLEND); - } else if (tt <= 56) { - sh->tbox(sol, 0, 0, 640, 480, 0, 0, 800, 600); - } else if (tt <= 58) { - if (!flag) { - if (sshot) - delete sshot; - testkey->start_transit = true; - testkey->transit_time = SDL_GetTicks(); - flag = true; - } else { - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - sh->box(0, 0, 640, 480, Color(255, 255, 255, 1)); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - } - - logo->draw(10, 10, Color(255, 255, 255, 100)); - - - font->putcursor(530, 460); - font->printf("FPS: %.2f\n", mogltk::engine::FPS()); -// font->printf("mx: %i\n", mogltk::engine::mouseX()); -// font->printf("my: %i\n", mogltk::engine::mouseY()); -// font->printf("t: %.2fs\n", SDL_GetTicks() / 1000.0); -// mogltk::ColorP::Max.A = 50; -// s->draw(mogltk::engine::mouseX() - 6, mogltk::engine::mouseY() - 3, BLACK); -// mogltk::ColorP::Max.A = 255; -// s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6); - -do_transit: - mogltk::ColorP::Min.A = 0; - mogltk::ColorP::Max.A = 255; - if (testkey->start_transit) { - double t; - int x, y; - Uint8 * pixels; - if (!got_transit) { - lastframe = 0; - got_transit = true; - ttex = gl->GrabTexture(); - pixels = (Uint8 *) ttex->GetPixels(); - oldblend = 20; -#if 1 - for (y = 0; y < 480; y++) { - for (x = 0; x < 640; x++) { -#if 0 - pixels[(y * 1024 + x) * 4 + 0] ^= 255; - pixels[(y * 1024 + x) * 4 + 1] ^= 255; - pixels[(y * 1024 + x) * 4 + 2] ^= 255; -#endif -#if 0 - pixels[(y * 1024 + x) * 4 + 3] = plasma[y * 640 + x]; -#endif -#if 1 - pixels[(y * 1024 + x) * 4 + 3] = 30; -#endif -#if 0 - pixels[(y * 1024 + x) * 4 + 3] = 7; -#endif -#if 0 - pixels[(y * 1024 + x) * 4 + 3] = 1; -#endif - } - } -#endif - } - pixels = (Uint8 *) ttex->GetPixels(); - t = (double) (SDL_GetTicks() - testkey->transit_time) / TRTIME; - curframe = 45 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; - if (t >= 1.0) { - testkey->start_transit = false; - } -#if 0 - mogltk::ColorP::Max.A = 255 * (TRTIME - SDL_GetTicks() + testkey->transit_time) / TRTIME; - mogltk::ColorP::Min.R = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; - mogltk::ColorP::Min.G = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; - mogltk::ColorP::Min.B = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; - sh->tbox(ttex, 0, 0, 640, 480); - mogltk::ColorP::Max.A = 255; - mogltk::ColorP::Min.R = 0; - mogltk::ColorP::Min.G = 0; - mogltk::ColorP::Min.B = 0; -#endif -#if 0 - for (y = 0; y < 10; y++) { - for (x = 0; x < 10; x++) { - int cx, cy, tx1, ty1, tx2, ty2; - cx = x * 64 + 32; - cy = y * 48 + 24; - tx1 = x * 64; - ty1 = y * 48; - tx2 = x * 64 + 64; - ty2 = y * 48 + 48; - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glTranslated(cx, cy, 0); - glScaled((1 - t), (1 - t), 1); - glRotated((t + ((x + y) / 30)) * 400, 0, 0, 1); - sh->tbox(ttex, -32, -24, 32, 24, tx1, ty1, tx2, ty2); - glPopMatrix(); - } - } -#endif -#if 0 - glDisable(GL_BLEND); - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, t); - sh->tbox(ttex, 0, 0, 640, 480); - glDisable(GL_ALPHA_TEST); - glEnable(GL_BLEND); -#endif -#if 1 - if (curframe > lastframe) { -#if 1 - sh->box(0, 0, 640, 480, Color(40, 40, 40, 12)); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glPushMatrix(); - glTranslated(320, 240, 0); - glScaled(1 + 2 * t, 1 + 2 * t, 1); - glRotated(t * 100, 0, 0, 1); - sh->tbox(ttex, -320, -240, 320, 240); - glPopMatrix(); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -#endif -#if 0 - sh->box(0, 0, 640, 480, Color(25, 25, 25, 20)); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glPushMatrix(); - glTranslated(320, 240, 0); - glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); - glTranslated(0, curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); - glTranslated(-curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); - glTranslated(-curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); - glTranslated(0, -curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); - glTranslated(0, -curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); - glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); - glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); - glPopMatrix(); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -#endif -#if 0 - int x0 = 320, y0 = 240; - int x = 0; - int y = t * 15 - 1; - int d = 3 - 2 * t * 15; - int dI = 10 - 4 * t * 15; - int rI = 6; - - sh->box(0, 0, 640, 480, Color(25, 25, 25, oldblend)); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - oldblend = 0; - while (x <= y) { - oldblend += 16; - glPushMatrix(); glTranslated(x0 + x, y0 + y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); - glPushMatrix(); glTranslated(x0 - x, y0 + y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); - glPushMatrix(); glTranslated(x0 + x, y0 - y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); - glPushMatrix(); glTranslated(x0 - x, y0 - y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); - glPushMatrix(); glTranslated(x0 + y, y0 + x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); - glPushMatrix(); glTranslated(x0 - y, y0 + x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); - glPushMatrix(); glTranslated(x0 + y, y0 - x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); - glPushMatrix(); glTranslated(x0 - y, y0 - x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); - if (d >= 0) { - d += dI; - dI += 8; - y -= 1; - } else { - d += rI; - dI += 4; - } - rI += 4; - x += 1; - } - printm(M_INFO, "blends = %i\n", oldblend / 2); - oldblend += 10; - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -#endif -#if 0 - sh->box(0, 0, 640, 480, Color(40, 40, 40, 12)); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glPushMatrix(); - glTranslated(320, 240, 0); - glRotated(t * 25, 0, 0, 1); - sh->tbox(ttex, -320, -240, 320, 240); - glPopMatrix(); - glPushMatrix(); - glTranslated(320, 240, 0); - glRotated(-t * 25, 0, 0, 1); - sh->tbox(ttex, -320, -240, 320, 240); - glPopMatrix(); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -#endif - lastframe = curframe; - } -#endif - } - if (!testkey->start_transit && ttex) { - delete ttex; - ttex = 0; - got_transit = false; - } - - gl->Leave2DMode(); - - //gl->Flip(got_transit ? false : true); - gl->Flip(false); - t = (double) SDL_GetTicks() / 1000.0; - newseconds = t; - - if (newseconds != seconds) { - printm(M_INFO, "FPS: %.2f\n", mogltk::engine::FPS()); - seconds = newseconds; - } - } - -// delete mytex; - - return 0; -} -CODE_ENDS - -#else - -#if 0 -CODE_BEGINS -virtual int startup() throw (GeneralException) { - unsigned char palette[256][3], * pixels, c; - char outname[256]; - int width, height, x, y; - - if (argc != 2) - exit(-1); - Input i(argv[1]); - SDL_Init(SDL_INIT_VIDEO); - atexit(SDL_Quit); - width = i.readU16(); - height = i.readU16(); - i.seek(12, SEEK_CUR); - SDL_Surface * s = SDL_SetVideoMode(width, height, 24, 0); - pixels = (unsigned char *) s->pixels; - for (x = 0; x < 256; x++) { - for (y = 0; y < 3; y++) { - palette[x][y] = i.readU8(); - } - i.seek(1, SEEK_CUR); - } - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - c = i.readU8(); - pixels[(y * width + x) * 3 + 0] = palette[c][2]; - pixels[(y * width + x) * 3 + 1] = palette[c][1]; - pixels[(y * width + x) * 3 + 2] = palette[c][0]; - } - } - - *strchr(argv[1], '.') = 0; - - sprintf(outname, "%s.bmp", argv[1]); - - SDL_SaveBMP(s, outname); - - SDL_Flip(s); - - SDL_Event event; - - while(true) { - SDL_PollEvent(&event); - switch (event.type) { - case SDL_QUIT: - exit(0); - } - } - - return 0; -} -CODE_ENDS - -#else -CODE_BEGINS -virtual int startup() throw (GeneralException) { - unsigned char * pixels, c; - char outname[256]; - int width, height, x, y; - - if (argc != 2) - exit(-1); - Input i(argv[1]); - SDL_Init(SDL_INIT_VIDEO); - atexit(SDL_Quit); - i.seek(4, SEEK_SET); - i.read(&width, 4); - i.read(&height, 4); - i.seek(4, SEEK_CUR); - SDL_Surface * _s = SDL_SetVideoMode(width, height, 32, 0); - SDL_Surface * s = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, - 0x000000ff, - 0x0000ff00, - 0x00ff0000, - 0xff000000); - - pixels = (unsigned char *) s->pixels; - *strchr(argv[1], '.') = 0; - - i.read(pixels, width * height * 4); - - sprintf(outname, "%s.bmp", argv[1]); - - SDL_SaveBMP(s, outname); - SDL_BlitSurface(s, 0, _s, 0); - - SDL_Flip(_s); - - SDL_Event event; - - while(true) { - SDL_PollEvent(&event); - switch (event.type) { - case SDL_QUIT: - exit(0); - } - } - - return 0; -} -CODE_ENDS - -#endif - -#endif +#include +#define _USE_MATH_DEFINES +#include +#include +#include +//#include +//#include +//#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#else +#endif +//#include "gettext.h" +#include +#include +#include +#include +#include +#include +//#include +//#include +#include "glbase.h" +#include "texture.h" +#include "glfont.h" +#include "glwidgets.h" +#include "engine.h" +#include "glsprite.h" +#include "glshape.h" +#include "glwidgets.h" + +#if 1 + +#define TRTIME 1500 +#define SPIN .50 +#define TILT .20 + +#define NBSTARS 300 +#define STARSRATE 300.0 + +#define SPHERE + +int zoom = 1; + +#define centerx 320 +#define centery 240 + +struct tdvect { + double x, y, z; +}; + +std::vector points; +std::vector ppoints; + +#if 0 +static int myprint(lua_State * L) { + const char * t = lua_tostring(L, -1); + + Base::printm(M_INFO, "From LUA: %s\n", t); + + return 0; +} + +static int myluaputstar(lua_State * L) { + tdvect t; + + t.x = lua_tonumber(L, -3); + t.y = lua_tonumber(L, -2); + t.z = lua_tonumber(L, -1); + + points.push_back(t); + + return 0; +} + +int myluaerror(lua_State * L) { + int n = lua_gettop(L); + int i; + String t; + + Base::printm(M_ERROR, "Got an LUA error\n"); + Base::printm(M_ERROR, "Inspecting LUA stack\n"); + + if (n == 0) { + Base::printm(M_ERROR, "Stack empty\n"); + return 0; + } + + for (i = 1; i <= n; i++) { + switch(lua_type(L, i)) { + case LUA_TNONE: + t = "Invalid"; + break; + case LUA_TNIL: + t = "(Nil)"; + break; + case LUA_TNUMBER: + t.set("(Number) %f", lua_tonumber(L, i)); + break; + case LUA_TBOOLEAN: + t.set("(Bool) %s", lua_toboolean(L, i) ? "true" : "false"); + break; + case LUA_TSTRING: + t.set("(String) %s", lua_tostring(L, i)); + break; + case LUA_TTABLE: + t.set("(Table)"); + break; + case LUA_TFUNCTION: + t = "(Function)"; + break; + default: + t = "Unknown"; + } + + Base::printm(M_ERROR, String(i) + ": " + t + "\n"); + } + + return 0; + + getchar(); +} +#endif + +unsigned int swap32(unsigned int w) { + return (w >> 24) | ((w >> 8) & 0x0000ff00) | ((w << 8) & 0x00ff0000) | (w << 24); +} + +unsigned int readB32(FILE * f) { + unsigned int r; + fread(&r, 1, 4, f); + return swap32(r); +} + +unsigned short readB16(FILE * f) { + unsigned char t[2]; + fread(t, 1, 2, f); + return t[1] | (t[0] << 8); +} + +float tofloat(unsigned int w) { + return *((float *) &w); +} + +char * sread(FILE * f) { + char temp[256], * p = temp; + + do { + *p = fgetc(f); + } while (*(p++)); + + return strdup(temp); +} + +char * pname[16] = { + "Unknown (not a float)", + "ScalX", + "ScalY", + "ScalZ", + "Unknown (not a float)", + "Unknown (not a float)", + "TransX", + "TransY", + "TransZ", + "Unknown", + "Unknown", + "Unknown", + "Unknown", + "Unknown", + "Unknown", + "Unknown" +}; + +#define OUTPUT stdout + +unsigned short entries; +struct tdvect * mesh; + +int bdlload(char * name) { + FILE * bdl; + int i, j; + char sig[9], sec[5], ** bnames; + unsigned int length, fpos, namespos, tpos, npos, r; + unsigned short * unks; + float f; + + if (!(bdl = fopen(name, "rb"))) + exit(-1); + + fread(sig, 1, 8, bdl); + sig[8] = 0; + + if (strcmp(sig, "J3D2bdl4")) { + fprintf(OUTPUT, "File not bdl.\n"); + exit(-1); + } + + fprintf(OUTPUT, "Looking for section JNT1...\n"); + + fseek(bdl, 32, SEEK_SET); + + do { + fread(sec, 1, 4, bdl); + sec[4] = 0; + length = readB32(bdl); + fprintf(OUTPUT, "Found section `%s' @ %08x, size %08x\n", sec, ftell(bdl) - 8, length); + fseek(bdl, length - 8, SEEK_CUR); + } while (strcmp(sec, "JNT1")); + + fseek(bdl, -length, SEEK_CUR); + fpos = ftell(bdl); + + fprintf(OUTPUT, "Found it at 0x%08x\n", fpos); + + fseek(bdl, 8, SEEK_CUR); + + entries = readB16(bdl); + if (readB16(bdl) != 0xffff) { + fprintf(OUTPUT, "Something's wrong, not found FFFF\n"); + } + if (readB32(bdl) != 0x18) { + fprintf(OUTPUT, "Something's wrong, bones not at 0x18, can't go on.\n"); + exit(-1); + } + if (readB32(bdl) != (0x18 + entries * 0x40)) { + fprintf(OUTPUT, "Something's wrong, bone index not at expected place, can't go on.\n"); + exit(-1); + } + + namespos = readB32(bdl); + + fprintf(OUTPUT, "Reading names.\n"); + + bnames = (char **) malloc(entries * sizeof(char *)); + unks = (unsigned short *) malloc(entries * sizeof(unsigned short)); + mesh = (struct tdvect *) malloc(entries * sizeof(struct tdvect)); + + fseek(bdl, namespos + fpos + 4, SEEK_SET); + + for (i = 0; i < entries; i++) { + unks[i] = readB16(bdl); + npos = readB16(bdl) + fpos + namespos; + tpos = ftell(bdl); + fseek(bdl, npos, SEEK_SET); + bnames[i] = sread(bdl); + fseek(bdl, tpos, SEEK_SET); + } + for (i = 0; i < entries; i++) { + fprintf(OUTPUT, "%02x: (%04x) `%s'\n", i, unks[i], bnames[i]); + } + + fprintf(OUTPUT, "Dumping bones\n"); + + fseek(bdl, fpos + 0x18, SEEK_SET); + + for (i = 0; i < entries; i++) { + fprintf(OUTPUT, "Bone #%02x (%s):\n", i, bnames[i]); + for (j = 0; j < 16; j++) { + r = readB32(bdl); + f = tofloat(r); + fprintf(OUTPUT, "%x: %08x - %9.5f - %s\n", j, r, f, pname[j]); + switch(j) { + case 6: + mesh[i].x = f; + break; + case 7: + mesh[i].y = f; + break; + case 8: + mesh[i].z = f; + break; + } + } + } + + return 0; +} + + +CODE_BEGINS + +#if 0 +void checkluastack(lua_State * L) { + int n = lua_gettop(L); + int i, j; + String t; + + printm(M_INFO, "Inspecting LUA stack\n"); + + if (n == 0) { + printm(M_INFO, "Stack empty\n"); + return; + } + + for (i = 1; i <= n; i++) { + switch(lua_type(L, i)) { + case LUA_TNONE: + t = "Invalid"; + break; + case LUA_TNIL: + t = "(Nil)"; + break; + case LUA_TNUMBER: + t.set("(Number) %f", lua_tonumber(L, i)); + break; + case LUA_TBOOLEAN: + t.set("(Bool) %s", lua_toboolean(L, i) ? "true" : "false"); + break; + case LUA_TSTRING: + t.set("(String) %s", lua_tostring(L, i)); + break; + case LUA_TTABLE: + printm(M_INFO, String(i) + ": (Table) Exploring:\n"); + lua_pushnil(L); /* first key */ + j = 0; + while (lua_next(L, -2) != 0) { + /* `key' is at index -2 and `value' at index -1 */ + printm(M_INFO, " %s - %s\n", lua_typename(L, lua_type(L, -2)), + lua_typename(L, lua_type(L, -1))); + lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */ + } + t = ""; + break; + case LUA_TFUNCTION: + t = "(Function)"; + break; + default: + t = "Unknown"; + } + + if (t != "") + printm(M_INFO, String(i) + ": " + t + "\n"); + } +} +#endif + +void putstar(double x, double y, double z, mogltk::Sprite * s) { + double tx, ty, tz; + double spin, tilt; + + spin = (mogltk::engine::mouseX() - centerx) / 80.0; + tilt = (mogltk::engine::mouseY() - centery) / 80.0; + + // Spin --> around y + + tx = x * cos(spin) + z * sin(spin); + tz = -x * sin(spin) + z * cos(spin); + + x = tx; + z = tz; + + + // tilt --> around x + + ty = y * cos(tilt) + z * sin(tilt); + tz = -y * sin(tilt) + z * cos(tilt); + + y = ty; + z = tz; + + tdvect t; + t.x = x; + t.y = y; + t.z = z; + +// s->draw(centerx + t.x * zoom * mogltk::engine::mouseZ() - s->GetSX() / 2, centery + t.y * zoom * mogltk::engine::mouseZ() - s->GetSY() / 2); + ppoints.push_back(t); +} + +double t; + +#ifdef STARSCAPE +int starsx[NBSTARS]; +int starsy[NBSTARS]; +#endif + +#ifdef SPHERE +double starst[NBSTARS]; +double starso[NBSTARS]; +#endif + +//lua_State * L; + +void initstars() { + int i; +#ifdef STARSCAPE + for (i = 0; i < NBSTARS; i++) { + starsx[i] = rand() % 640; + starsy[i] = rand() % 480; + } + + t = 0; +#endif +#ifdef RING + t = 0; +#endif +#ifdef SPHERE + t = 0; + for (i = 0; i < NBSTARS; i++) { + starst[i] = -(rand() % 3000) / 1000.0; + starso[i] = 2 * ((rand() % 1000) / 1000.0) * M_PI; + } +#endif +#ifdef LUA + L = lua_open(); + luaopen_math(L); + lua_pop(L, 1); + lua_atpanic(L, myluaerror); + luaL_loadfile(L, "particules.lua"); + lua_call(L, 0, 0); + lua_pushstring(L, "putstar"); + lua_pushcfunction(L, myluaputstar); + lua_settable(L, LUA_GLOBALSINDEX); + lua_pushstring(L, "print"); + lua_pushcfunction(L, myprint); + lua_settable(L, LUA_GLOBALSINDEX); + lua_pushstring(L, "initstars"); + lua_gettable(L, LUA_GLOBALSINDEX); + lua_call(L, 0, 0); +#endif +} + +void displaystars(mogltk::Sprite * s) { + int i; + double x, y, z, st; + tdvect tv; + +#ifdef STARSCAPE + for (i = 0; i < NBSTARS; i++) { + s->draw(starsx[i], starsy[i]); + } +#endif +#ifdef RING + for (i = 0; i < NBSTARS; i++) { + putstar(cos(t + i * 2 * M_PI / NBSTARS), 0, sin(t + i * 2 * M_PI / NBSTARS), s); + } +#endif +#ifdef SPHERE + for (i = 0; i < NBSTARS; i++) { + st = t - starst[i]; + + y = st / 3.0; + + x = cos(st * 2 * M_PI + starso[i]) * sin(y * M_PI); + z = sin(st * 2 * M_PI + starso[i]) * sin(y * M_PI); + + y = cos(y * M_PI); + + putstar(x, y, z, s); + } +#endif +#ifdef LUA + lua_pushstring(L, "displaystars"); + lua_gettable(L, LUA_GLOBALSINDEX); + lua_call(L, 0, 0); + + for (std::vector::iterator i = points.begin(); i != points.end(); i++) { + tv = *i; + putstar(tv.x, tv.y, tv.z, s); + } + points.clear(); +#endif +#ifdef BDL + for (i = 0; i < entries; i++) { + putstar(mesh[i].x / 20, mesh[i].y / 20, mesh[i].z / 20, s); + } +#endif + while (!ppoints.empty()) { + std::vector::iterator m = ppoints.begin(); + for (std::vector::iterator i = ppoints.begin(); i != ppoints.end(); i++) { + if (i->z > m->z) + m = i; + } + tv = *m; + ppoints.erase(m); + // Only bare projecting... for now... + s->draw(centerx + tv.x * zoom * mogltk::engine::mouseZ() - s->GetSX() / 2, centery + tv.y * zoom * mogltk::engine::mouseZ() - s->GetSY() / 2); + } +} + +void incrementstars(double nt) { + int i; + +#ifdef STARSCAPE + while ((t + (1 / STARSRATE)) <= nt) { + t += 1 / STARSRATE; + + for (i = 0; i < NBSTARS; i++) { + if ((++starsx[i]) >= 640) { + starsx[i] = 0; + starsy[i] = rand() % 480; + } + } + } +#endif +#ifdef RING + t = nt; +#endif +#ifdef SPHERE + t = nt; + + for (i = 0; i < NBSTARS; i++) { + if ((starst[i] + 3) < t) { + starst[i] += 3.0; + starso[i] = 2 * ((rand() % 1000) / 1000.0) * M_PI; + } + } +#endif +#ifdef LUA + t = nt; + + lua_pushstring(L, "incstars"); + lua_gettable(L, LUA_GLOBALSINDEX); + lua_pushnumber(L, t); + lua_call(L, 1, 0); +#endif +} + +class testkey_t : public mogltk::engine::keyevent { + public: + virtual void down(SDL_keysym keysym) { + if (keysym.sym == SDLK_SPACE && !start_transit) { + start_transit = true; + transit_time = SDL_GetTicks(); + } else if (old_handler) + old_handler->down(keysym); + } + virtual void up(SDL_keysym keysym) { + if (old_handler) + old_handler->up(keysym); + } + bool start_transit; + Uint32 transit_time; +} * testkey; + +void affiche_grille(mogltk::shape * sh, mogltk::texture * tex, int grille[41][31][2]) { + int x, y, tx1, tx2, ty1, ty2; + static mogltk::ColorP w = WHITE; + + w.Bind(); + tex->Bind(); + +// sh->box(0, 0, 640, 480, BLACK); + for (y = 0; y < 30; y++) { + for (x = 0; x < 40; x++) { + tx1 = x * 20; + ty1 = y * 20; + tx2 = x * 20 + 20; + ty2 = y * 20 + 20; + +#if 1 + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2i(tx1, ty1); glVertex2i(grille[x ][y ][0], grille[x ][y ][1]); + glTexCoord2i(tx2, ty1); glVertex2i(grille[x + 1][y ][0], grille[x + 1][y ][1]); + glTexCoord2i(tx1, ty2); glVertex2i(grille[x ][y + 1][0], grille[x ][y + 1][1]); + glTexCoord2i(tx2, ty2); glVertex2i(grille[x + 1][y + 1][0], grille[x + 1][y + 1][1]); + glEnd(); +#else + sh->line(grille[x ][y ][0], grille[x ][y ][1], + grille[x + 1][y ][0], grille[x + 1][y ][1]); + sh->line(grille[x + 1][y ][0], grille[x + 1][y ][1], + grille[x + 1][y + 1][0], grille[x + 1][y + 1][1]); + sh->line(grille[x + 1][y + 1][0], grille[x + 1][y + 1][1], + grille[x ][y + 1][0], grille[x ][y + 1][1]); + sh->line(grille[x ][y + 1][0], grille[x ][y + 1][1], + grille[x ][y ][0], grille[x ][y ][1]); +#endif + } + } +} + +virtual int startup() throw (GeneralException) { + bool flag = false, flag2 = false; + mogltk::texture * sshot = 0, * plastex = new mogltk::texture(1024, 512); + int x, y, sx1, sx2, sy1, sy2, lastframe, curframe, px, py, lasttick = 0, curtick = 0, oldblend, seconds = 0, newseconds = 0; + double t = 0; + verbosity = M_INFO; + String str; + bool got_transit = false; + Uint8 * plasma = (Uint8 *) malloc(640 * 480), * pplasma; + int grille[41][31][2]; + double seeds[41][31]; + double speeds[41][31]; + +#if 0 + srand(25); + for (y = 0; y < 31; y++) { + for (x = 0; x < 41; x++) { + seeds[x][y] = 1.2 * (double) (rand() % 10000) / 10000; + speeds[x][y] = 2.6 * (double) (rand() % 10000) / 10000; + } + } +#endif + + testkey = new testkey_t(); + + mogltk::engine::setmouseZ(50); + +#if 0 + +#if 0 + Lua * l = new Lua(); + LuaInput::pushconstruct(l); + LuaOutput::pushconstruct(l); + LuaBuffer::pushconstruct(l); + l->open_math(); + l->declarefunc("print", myprint); +#if 0 + l->load(&Input("particules.lua"), false); + l->dump(&Output("particules.out")); + l->call(); +#else + l->load(&Input("particules.out")); +#endif +// l->call("testing"); + delete l; +#endif + +// bdlload("cl.bdl"); + +#endif + + Input pl("plasma.raw"); + pl.read(plasma, 640 * 480); + + pplasma = (Uint8 *) plastex->GetPixels(); + + for (y = 0; y < 480; y++) { + for (x = 0; x < 640; x++) { + pplasma[((y * 1024) + x) * 4 + 3] = 255 - plasma[(y * 640) + x]; + } + } + + new Archive("datas.paq"); + +#if 1 + mogltk::base * gl = new mogltk::glbase(); + mogltk::shape * sh = new mogltk::glshape(); + mogltk::font * font = new mogltk::glfont(&Input("font-2.bin")); + mogltk::glSprite * s = new mogltk::glSprite(&Input("cursor.rgba"), 25, 25); + mogltk::texture * sol = new mogltk::texture(&Input("sol.tex")); + mogltk::glSprite * logo = new mogltk::glSprite(&Input("logo.raw"), 165, 124); +#if 0 + mogltk::Sprite * p = new mogltk::glSprite(&Input("particule.rgba"), 16, 16); + mogltk::glSprite * spr = new mogltk::glSprite(&Input("015_Over-Mind.raw"), 347, 328); + mogltk::glSprite * eD1 = new mogltk::glSprite(&Input("elkyaD1.raw"), 53, 100); + mogltk::glSprite * eG1 = new mogltk::glSprite(&Input("elkyaG1.raw"), 53, 100); + mogltk::glSprite * eM1 = new mogltk::glSprite(&Input("elkyaM1.raw"), 53, 100); +// mogltk::glSprite * spr = new mogltk::glSprite(&Input("test.raw"), 200, 200); +#endif + mogltk::widget * w = new mogltk::widgets::Root(sh); +#else + mogltk::base * gl = new mogltk::base(); + mogltk::shape * sh = new mogltk::shape(); + mogltk::font * font = new mogltk::font(&Input("font-2.bin")); + mogltk::Sprite * s = new mogltk::Sprite(&Input("cursor.rgba"), 25, 25); + mogltk::Sprite * p = new mogltk::Sprite(&Input("particule.rgba"), 16, 16); + mogltk::Sprite * spr = new mogltk::Sprite(&Input("015_Over-Mind.raw"), 347, 328); + mogltk::widget * w = new mogltk::Root(sh); +#endif + + mogltk::texture * ttex = 0; + + font->setcolor(WHITE); + font->setshadow(2); +#if 0 + mogltk::rect textrect; + mogltk::texture * text = font->printtex(&textrect, + "PixelPawa!\n" + "It works!!\n" + "I can't believe it!\n" + ); + SDL_SaveBMP(text->GetSurface(), "test-font.bmp"); + textrect.x = 10; + textrect.y = 30; +#endif + + mogltk::engine::setcursorvisible(true); + mogltk::engine::setappactive(true); + +#if 0 + mogltk::texture * mytex = new mogltk::texture(&Input("pattern6.tex"), true); + + Color AlphaBlue(AQUA); + AlphaBlue.A = 50; + + mogltk::fill * f = sh->fcircle(320, 240, 50); + + initstars(); + + px = 200; + py = 350; +#endif +#if 0 + new mogltk::widgets::Button(0, sh, + new mogltk::widgets::SmartBox(sh, w, 120, 50, 100, 100, "Test"), + 12, 30, 50, 20, "Toto"); +#endif + new mogltk::widgets::Frame(sh, w, 10, 10, 600, 400); + //new mogltk::widgets::MsgBox(sh, w, "Test", "Blablabla\nCeci est un test de la\nclasse MsgBox."); + + class tLabel : public mogltk::widgets::Label { + public: + tLabel(mogltk::shape * sh, mogltk::widget * father) : Label(sh, father, 250, 200, 16, 16, "I"), tick(0) { set_timed_event(500); } + virtual bool process_event(int mx, int my, mogltk::event_t event) { + if (Label::process_event(mx, my, event)) + return true; + + if (event == mogltk::E_TIMER) { + set_timed_event(500); + tick = (tick + 1) % 4; + switch (tick) { + case 0: + caption = "I"; + break; + case 1: + caption = "/"; + break; + case 2: + caption = "-"; + break; + case 3: + caption = "\\"; + break; + } + } + } + private: + int tick; + }; + + mogltk::widgets::ContextMenu * c, * c2; + //c = new mogltk::widgets::ContextMenu(sh, w, 20, 20); + mogltk::widgets::Menu * sm; + + new mogltk::widgets::SmartBox(sh, w, 250, 300, 100, 70, "SmartBox"); + sm = new mogltk::widgets::Menu(sh, w); + + sm->addnode("Toto", 0); + sm->addnode("Titi", 0); + sm->addnode("Tutu", 0); + +#if 0 + c->addnode("Test", 0); + c->addnode("Test2", 0); + c->addline(); + c->addnode("Test3", 0); + c->addnode("Test of a long entry", 0); + + c2 = c->createsub("Sub"); + c2->addnode("A sub", 0); + c2->createsub("subsub")->addnode("Toto", 0); + c2->SetEnabled(0, false); +#endif + + c = sm->createsub("Sub Menu"); + c->addnode("Blah1", 0); + c->addnode("Blah2", 0); + c->addnode("Blah3", 0); + c->addline(); + c2 = c->createsub("SubBlah"); + c2->addnode("SubBlah1", 0); + c2->addnode("SubBlah2", 0); + + sm->MoveOnTop(); + + new tLabel(sh, w); + + w->mainloop(); + + while (!mogltk::engine::quitrequested()) { +#if 0 + sx1 = 320 + 320 * sin(0.983 * t + 3.15); + sx2 = 320 + 320 * sin(0.537 * t + 5.32); + sy1 = 240 + 240 * sin(0.692 * t + 8.21); + sy2 = 240 + 240 * sin(1.029 * t + 2.42); +#endif + + gl->Enter2DMode(); + +#if 1 + if (got_transit) + goto do_transit; +#endif + +#if 0 + w->fulldraw(); + + sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); + //sh->box(400, 100, 450, 150, BLACK, RED, LIME, BLUE); + + sh->box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + mogltk::ColorP::Max.A = 100; + //sh->box(5, 5, 400, 300, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + mogltk::ColorP::Max.A = 255; +#if 1 + font->setshadow(1); + font->putcursor(10, 30); + mogltk::ColorP::Max.A = sy1 / 2; + font->setcolor(Color(sy1 / 2, sy1 / 2, sy1 / 2, sy1 / 2)); + font->printf( + "PixelPawa!\n" + "It works!!\n" + "I can't believe it!\n" + ); + mogltk::ColorP::Max.A = 255; + font->setcolor(WHITE); +#else + sh->tbox(text, textrect.x, textrect.y, textrect.x + textrect.w, textrect.y + textrect.h); +#endif + + sh->box3d(50, 150, 150, 200); + sh->obox3d(50, 250, 150, 300); + sh->window(50, 350, 150, 400, "Titre plus beau ;)"); + sh->box3d(180, 130, 320, 220); + sh->button(200, 150, 300, 200, "Bouton"); + + sh->fdraw(f, BLUE); + sh->sdraw(f); + + eM1->drawrotate(500, 400, sx1); + + curtick = (SDL_GetTicks() / 250) % 4; + + if (curtick != lasttick) { + px -= 10; + py += 5; + + if (px < -53) + px = 640; + if (px > 640) + px = -53; + if (py > 480) + py = -100; + lasttick = curtick; + } + + switch(curtick) { + case 0: + eM1->draw(px, py, WHITE, 1, 1); + break; + case 1: + eD1->draw(px, py, WHITE, 1, 1); + break; + case 2: + eM1->draw(px, py, WHITE, 1, 1); + break; + case 3: + eG1->draw(px, py, WHITE, 1, 1); + break; + } + + sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); + mogltk::ColorP::Min.A = 200; + sh->obox(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); + mogltk::ColorP::Min.A = 0; + + p->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 8); + sh->line(320, 240, mogltk::engine::mouseX(), mogltk::engine::mouseY()); + + mogltk::ColorP::Min.A = 200; + p->draw(sx1 - 8, sy1 - 8, AlphaBlue); + p->draw(sx2 - 8, sy2 - 8, AlphaBlue); + + displaystars(p); + incrementstars(t); + + sh->box(0, 0, 640, 480, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + +#endif +// sh->box(0, 0, 640, 480, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + + int x, y; + +#if 0 + for (y = 0; y < 31; y++) { + for (x = 0; x < 41; x++) { + grille[x][y][0] = x * 16 + 8 * sin(t * 6 + (x + y) / 2.0); + grille[x][y][1] = y * 16 + 8 * cos(t * 6 + (x + y) / 2.0); + } + } +#endif + double dis, xdis, ydis, xpos, ypos, norm, tt, tt1; + + t += 48; + + tt = t - (((int) t) / 58) * 58; + + if (tt <= 20) { + flag = flag2 = false; + for (y = 0; y < 31; y++) { + for (x = 0; x < 41; x++) { + xpos = x - 20.5; + ypos = y - 15.5; + norm = sqrt(xpos * xpos + ypos * ypos); + xpos /= norm; + ypos /= norm; + dis = sin(t * 6 - norm); + xdis = dis * sin(xpos); + ydis = dis * sin(ypos); + grille[x][y][0] = (((x * 16 + 16 * xdis) - 320) * 1.08) + 320; + grille[x][y][1] = (((y * 16 + 16 * ydis) - 240) * 1.08) + 240; + } + } + + affiche_grille(sh, sol, grille); + if (tt < 4) + sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * ((4 - tt) / 4))); + else if (tt > 16) + sh->box(0, 0, 640, 480, Color(0, 0, 0, 255 * ((tt - 16) / 4))); + } else if (tt <= 23) { + tt -= 20; + sh->box(0, 0, 640, 480, BLACK); + for (y = 0; y < 31; y++) { + for (x = 0; x < 41; x++) { + grille[x][y][0] = ((((x * 16 + 8 * sin(t * 6 + (x + y) / 2.0)) - 320) * 1.08) + 320) * tt / 3; + grille[x][y][1] = ((((y * 16 + 8 * cos(t * 6 + (x + y) / 2.0)) - 200) * 1.08) + 200) * tt / 3; + } + } + affiche_grille(sh, sol, grille); + } else if (tt <= 36) { + for (y = 0; y < 31; y++) { + for (x = 0; x < 41; x++) { + grille[x][y][0] = (((x * 16 + 8 * sin(t * 6 + (x + y) / 2.0)) - 320) * 1.08) + 320; + grille[x][y][1] = (((y * 16 + 8 * cos(t * 6 + (x + y) / 2.0)) - 200) * 1.08) + 200; + } + } + affiche_grille(sh, sol, grille); + } else if (tt <= 38) { + tt -= 36; + if (!flag2) { + sshot = gl->GrabTexture(); + flag2 = true; + } + sh->tbox(sshot, 0, 0, 640, 480); + if (tt <= 0.1) { + sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * (tt / 0.1))); + } else if (tt < 0.5) { + tt -= 0.1; + sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * ((0.4 - tt) / 0.4))); + sh->box(0, 0, 640, 480, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127 * (tt / 0.4))); + } else { + sh->box(0, 0, 640, 480, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127)); + } + for (y = 0; y < 15; y++) { + for (x = 0; x < 20; x++) { + sh->obox(x * 32, y * 32, x * 32 + 32, y * 32 + 32, WHITE); + } + } + } else if (tt <= 42) { + int xx, yy, tyy; + double ttt; + tt -= 38; + sh->box(0, 0, 640, 480, BLACK); + for (y = 14; y >= 0; y--) { + for (x = 19; x >= 0; x--) { + double d = (33.0 - x - y) / 16.5; + xx = x * 32; + tyy = y * 32; + if (tt <= d) { + yy = y * 32; + } else { + ttt = tt - d; + yy = y * 32 + ttt * ttt * ttt * 60; + } + sh->tbox(sshot, xx, yy, xx + 32, yy + 32, xx, tyy, xx + 32, tyy + 32); + sh->box(xx, yy, xx + 32, yy + 32, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127)); + sh->obox(xx, yy, xx + 32, yy + 32, WHITE); + } + } + } else if (tt <= 43) { + sh->box(0, 0, 640, 480, BLACK); + } else if (tt <= 48) { + tt -= 43; + sh->tbox(sol, 0, 0, 640, 480, 0, 0, 800, 600); + glDisable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, tt / 5); + sh->tbox(plastex, 0, 0, 640, 480); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + } else if (tt <= 56) { + sh->tbox(sol, 0, 0, 640, 480, 0, 0, 800, 600); + } else if (tt <= 58) { + if (!flag) { + if (sshot) + delete sshot; + testkey->start_transit = true; + testkey->transit_time = SDL_GetTicks(); + flag = true; + } else { + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + sh->box(0, 0, 640, 480, Color(255, 255, 255, 1)); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + } + + logo->draw(10, 10, Color(255, 255, 255, 100)); + + + font->putcursor(530, 460); + font->printf("FPS: %.2f\n", mogltk::engine::FPS()); +// font->printf("mx: %i\n", mogltk::engine::mouseX()); +// font->printf("my: %i\n", mogltk::engine::mouseY()); +// font->printf("t: %.2fs\n", SDL_GetTicks() / 1000.0); +// mogltk::ColorP::Max.A = 50; +// s->draw(mogltk::engine::mouseX() - 6, mogltk::engine::mouseY() - 3, BLACK); +// mogltk::ColorP::Max.A = 255; +// s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6); + +do_transit: + mogltk::ColorP::Min.A = 0; + mogltk::ColorP::Max.A = 255; + if (testkey->start_transit) { + double t; + int x, y; + Uint8 * pixels; + if (!got_transit) { + lastframe = 0; + got_transit = true; + ttex = gl->GrabTexture(); + pixels = (Uint8 *) ttex->GetPixels(); + oldblend = 20; +#if 1 + for (y = 0; y < 480; y++) { + for (x = 0; x < 640; x++) { +#if 0 + pixels[(y * 1024 + x) * 4 + 0] ^= 255; + pixels[(y * 1024 + x) * 4 + 1] ^= 255; + pixels[(y * 1024 + x) * 4 + 2] ^= 255; +#endif +#if 0 + pixels[(y * 1024 + x) * 4 + 3] = plasma[y * 640 + x]; +#endif +#if 1 + pixels[(y * 1024 + x) * 4 + 3] = 30; +#endif +#if 0 + pixels[(y * 1024 + x) * 4 + 3] = 7; +#endif +#if 0 + pixels[(y * 1024 + x) * 4 + 3] = 1; +#endif + } + } +#endif + } + pixels = (Uint8 *) ttex->GetPixels(); + t = (double) (SDL_GetTicks() - testkey->transit_time) / TRTIME; + curframe = 45 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; + if (t >= 1.0) { + testkey->start_transit = false; + } +#if 0 + mogltk::ColorP::Max.A = 255 * (TRTIME - SDL_GetTicks() + testkey->transit_time) / TRTIME; + mogltk::ColorP::Min.R = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; + mogltk::ColorP::Min.G = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; + mogltk::ColorP::Min.B = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; + sh->tbox(ttex, 0, 0, 640, 480); + mogltk::ColorP::Max.A = 255; + mogltk::ColorP::Min.R = 0; + mogltk::ColorP::Min.G = 0; + mogltk::ColorP::Min.B = 0; +#endif +#if 0 + for (y = 0; y < 10; y++) { + for (x = 0; x < 10; x++) { + int cx, cy, tx1, ty1, tx2, ty2; + cx = x * 64 + 32; + cy = y * 48 + 24; + tx1 = x * 64; + ty1 = y * 48; + tx2 = x * 64 + 64; + ty2 = y * 48 + 48; + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslated(cx, cy, 0); + glScaled((1 - t), (1 - t), 1); + glRotated((t + ((x + y) / 30)) * 400, 0, 0, 1); + sh->tbox(ttex, -32, -24, 32, 24, tx1, ty1, tx2, ty2); + glPopMatrix(); + } + } +#endif +#if 0 + glDisable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, t); + sh->tbox(ttex, 0, 0, 640, 480); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); +#endif +#if 1 + if (curframe > lastframe) { +#if 1 + sh->box(0, 0, 640, 480, Color(40, 40, 40, 12)); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glPushMatrix(); + glTranslated(320, 240, 0); + glScaled(1 + 2 * t, 1 + 2 * t, 1); + glRotated(t * 100, 0, 0, 1); + sh->tbox(ttex, -320, -240, 320, 240); + glPopMatrix(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif +#if 0 + sh->box(0, 0, 640, 480, Color(25, 25, 25, 20)); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glPushMatrix(); + glTranslated(320, 240, 0); + glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); + glTranslated(0, curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); + glTranslated(-curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); + glTranslated(-curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); + glTranslated(0, -curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); + glTranslated(0, -curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); + glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); + glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); + glPopMatrix(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif +#if 0 + int x0 = 320, y0 = 240; + int x = 0; + int y = t * 15 - 1; + int d = 3 - 2 * t * 15; + int dI = 10 - 4 * t * 15; + int rI = 6; + + sh->box(0, 0, 640, 480, Color(25, 25, 25, oldblend)); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + oldblend = 0; + while (x <= y) { + oldblend += 16; + glPushMatrix(); glTranslated(x0 + x, y0 + y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); + glPushMatrix(); glTranslated(x0 - x, y0 + y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); + glPushMatrix(); glTranslated(x0 + x, y0 - y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); + glPushMatrix(); glTranslated(x0 - x, y0 - y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); + glPushMatrix(); glTranslated(x0 + y, y0 + x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); + glPushMatrix(); glTranslated(x0 - y, y0 + x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); + glPushMatrix(); glTranslated(x0 + y, y0 - x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); + glPushMatrix(); glTranslated(x0 - y, y0 - x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); + if (d >= 0) { + d += dI; + dI += 8; + y -= 1; + } else { + d += rI; + dI += 4; + } + rI += 4; + x += 1; + } + printm(M_INFO, "blends = %i\n", oldblend / 2); + oldblend += 10; + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif +#if 0 + sh->box(0, 0, 640, 480, Color(40, 40, 40, 12)); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glPushMatrix(); + glTranslated(320, 240, 0); + glRotated(t * 25, 0, 0, 1); + sh->tbox(ttex, -320, -240, 320, 240); + glPopMatrix(); + glPushMatrix(); + glTranslated(320, 240, 0); + glRotated(-t * 25, 0, 0, 1); + sh->tbox(ttex, -320, -240, 320, 240); + glPopMatrix(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif + lastframe = curframe; + } +#endif + } + if (!testkey->start_transit && ttex) { + delete ttex; + ttex = 0; + got_transit = false; + } + + gl->Leave2DMode(); + + //gl->Flip(got_transit ? false : true); + gl->Flip(false); + t = (double) SDL_GetTicks() / 1000.0; + newseconds = t; + + if (newseconds != seconds) { + printm(M_INFO, "FPS: %.2f\n", mogltk::engine::FPS()); + seconds = newseconds; + } + } + +// delete mytex; + + return 0; +} +CODE_ENDS + +#else + +#if 0 +CODE_BEGINS +virtual int startup() throw (GeneralException) { + unsigned char palette[256][3], * pixels, c; + char outname[256]; + int width, height, x, y; + + if (argc != 2) + exit(-1); + Input i(argv[1]); + SDL_Init(SDL_INIT_VIDEO); + atexit(SDL_Quit); + width = i.readU16(); + height = i.readU16(); + i.seek(12, SEEK_CUR); + SDL_Surface * s = SDL_SetVideoMode(width, height, 24, 0); + pixels = (unsigned char *) s->pixels; + for (x = 0; x < 256; x++) { + for (y = 0; y < 3; y++) { + palette[x][y] = i.readU8(); + } + i.seek(1, SEEK_CUR); + } + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + c = i.readU8(); + pixels[(y * width + x) * 3 + 0] = palette[c][2]; + pixels[(y * width + x) * 3 + 1] = palette[c][1]; + pixels[(y * width + x) * 3 + 2] = palette[c][0]; + } + } + + *strchr(argv[1], '.') = 0; + + sprintf(outname, "%s.bmp", argv[1]); + + SDL_SaveBMP(s, outname); + + SDL_Flip(s); + + SDL_Event event; + + while(true) { + SDL_PollEvent(&event); + switch (event.type) { + case SDL_QUIT: + exit(0); + } + } + + return 0; +} +CODE_ENDS + +#else +CODE_BEGINS +virtual int startup() throw (GeneralException) { + unsigned char * pixels, c; + char outname[256]; + int width, height, x, y; + + if (argc != 2) + exit(-1); + Input i(argv[1]); + SDL_Init(SDL_INIT_VIDEO); + atexit(SDL_Quit); + i.seek(4, SEEK_SET); + i.read(&width, 4); + i.read(&height, 4); + i.seek(4, SEEK_CUR); + SDL_Surface * _s = SDL_SetVideoMode(width, height, 32, 0); + SDL_Surface * s = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, + 0x000000ff, + 0x0000ff00, + 0x00ff0000, + 0xff000000); + + pixels = (unsigned char *) s->pixels; + *strchr(argv[1], '.') = 0; + + i.read(pixels, width * height * 4); + + sprintf(outname, "%s.bmp", argv[1]); + + SDL_SaveBMP(s, outname); + SDL_BlitSurface(s, 0, _s, 0); + + SDL_Flip(_s); + + SDL_Event event; + + while(true) { + SDL_PollEvent(&event); + switch (event.type) { + case SDL_QUIT: + exit(0); + } + } + + return 0; +} +CODE_ENDS + +#endif + +#endif -- cgit v1.2.3