int saveHSI (char * filename) { FILE * writer = fopen (filename, "wb"); int x, y, lookAhead; unsigned short int * fromHere; unsigned short int * lookPointer; if (! writer) return 0; put2bytes (HORZ_RES, writer); put2bytes (VERT_RES, writer); for (y = 0; y < VERT_RES; y ++) { fromHere = backDropImage[y]; x = 0; while (x < HORZ_RES) { lookPointer = fromHere + 1; for (lookAhead = x + 1; lookAhead < HORZ_RES; lookAhead ++) { if (lookAhead - x == 256) break; if (* fromHere != * lookPointer) break; lookPointer ++; } if (lookAhead == x + 1) { put2bytes (* fromHere, writer); } else { put2bytes (* fromHere | 32, writer); fputc (lookAhead - x - 1, writer); } fromHere = lookPointer; x = lookAhead; } } int i = ftell (writer); fclose (writer); return i; }
void saveParallaxRecursive (parallaxLayer * me, FILE * fp) { if (me) { saveParallaxRecursive (me -> next, fp); fputc (1, fp); put2bytes (me->fileNum, fp); put2bytes (me ->fractionX, fp); put2bytes (me->fractionY, fp); } }
void saveSounds (FILE * fp) { if (soundOK) { for (int i = 0; i < MAX_SAMPLES; i ++) { if (soundCache[i].looping) { fputc (1, fp); put2bytes (soundCache[i].fileLoaded, fp); put2bytes (soundCache[i].vol, fp); } } } fputc (0, fp); put2bytes (defSoundVol, fp); put2bytes (defVol, fp); }
void writeString (const char * txt, FILE * fp) { int a, n = strlen (txt); put2bytes (n, fp); for (a = 0; a < n; a ++) { fputc (txt[a] + MOVETEXT, fp); } }
/* void debugCostume (char * message, persona * cossy) { FILE * db = fopen ("debuTURN.txt", "at"); fprintf (db, " %s costume with %i directions...\n", message, cossy -> numDirections); for (int a = 0; a < cossy -> numDirections * 3; a ++) { fprintf (db, " %i frames:", cossy -> animation[a] -> numFrames); for (int b = 0; b < cossy -> animation[a] -> numFrames; b ++) { fprintf (db, " %i", cossy -> animation[a] -> frames[b]); } fprintf (db, "\n"); } fclose (db); } */ bool saveCostume (persona * cossy, FILE * fp) { int a; put2bytes (cossy -> numDirections, fp); for (a = 0; a < cossy -> numDirections * 3; a ++) { if (! saveAnim (cossy -> animation[a], fp)) return false; } // debugCostume ("Saved", cossy); return true; }
void saveHandlers (FILE * fp) { put2bytes (currentEvents -> leftMouseFunction, fp); put2bytes (currentEvents -> leftMouseUpFunction, fp); put2bytes (currentEvents -> rightMouseFunction, fp); put2bytes (currentEvents -> rightMouseUpFunction, fp); put2bytes (currentEvents -> moveMouseFunction, fp); put2bytes (currentEvents -> focusFunction, fp); put2bytes (currentEvents -> spaceFunction, fp); }
bool saveAnim (personaAnimation * p, FILE * fp) { put2bytes (p -> numFrames, fp); if (p -> numFrames) { put4bytes (p -> theSprites -> ID, fp); for (int a = 0; a < p -> numFrames; a ++) { put4bytes (p -> frames[a].frameNum, fp); put4bytes (p -> frames[a].howMany, fp); put4bytes (p -> frames[a].noise, fp); } } return true; }
void saveRegions (FILE * fp) { int numRegions = 0; screenRegion * thisRegion = allScreenRegions; while (thisRegion) { thisRegion = thisRegion -> next; numRegions ++; } put2bytes (numRegions, fp); thisRegion = allScreenRegions; while (thisRegion) { put2bytes (thisRegion -> x1, fp); put2bytes (thisRegion -> y1, fp); put2bytes (thisRegion -> x2, fp); put2bytes (thisRegion -> y2, fp); put2bytes (thisRegion -> sX, fp); put2bytes (thisRegion -> sY, fp); put2bytes (thisRegion -> di, fp); saveObjectRef (thisRegion -> thisType, fp); thisRegion = thisRegion -> next; } }
void saveCoreHSI (FILE * writer, GLuint texture, int w, int h) { GLint tw, th; glBindTexture (GL_TEXTURE_2D, texture); getTextureDimensions(texture, &tw, &th); GLushort* image = new GLushort [tw*th]; if (! checkNew (image)) return; glPixelStorei (GL_PACK_ALIGNMENT, 1); // glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image); setPixelCoords (true); //glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); const GLfloat texCoords[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; int xoffset = 0; while (xoffset < tw) { int w = (tw-xoffset < viewportWidth) ? tw-xoffset : viewportWidth; int yoffset = 0; while (yoffset < th) { int h = (th-yoffset < viewportHeight) ? th-yoffset : viewportHeight; glClear(GL_COLOR_BUFFER_BIT); // Clear The Screen const GLfloat vertices[] = { (GLfloat)-xoffset, (GLfloat)-yoffset, 0., (GLfloat)w-xoffset, (GLfloat)-yoffset, 0., (GLfloat)-xoffset, (GLfloat)-yoffset+h, 0., (GLfloat)w-xoffset, (GLfloat)-yoffset+h, 0. }; glUseProgram(shader.texture); setPMVMatrix(shader.texture); drawQuad(shader.texture, vertices, 1, texCoords); glUseProgram(0); for (int i = 0; i<h; i++) { glReadPixels(viewportOffsetX, viewportOffsetY+i, w, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image+xoffset+(yoffset+i)*tw); } yoffset += viewportHeight; } xoffset += viewportWidth; } //glReadPixels(viewportOffsetX, viewportOffsetY, tw, th, GL_RGBA, GL_UNSIGNED_BYTE, data); setPixelCoords (false); int x, y, lookAhead; unsigned short int * fromHere, * lookPointer; put2bytes (w, writer); put2bytes (h, writer); for (y = 0; y < h; y ++) { fromHere = image +(y*tw); x = 0; while (x < w) { lookPointer = fromHere + 1; for (lookAhead = x + 1; lookAhead < w; lookAhead ++) { if (lookAhead - x == 256) break; if (* fromHere != * lookPointer) break; lookPointer ++; } if (lookAhead == x + 1) { put2bytes ((* fromHere) & 65503, writer); } else { put2bytes (* fromHere | 32, writer); fputc (lookAhead - x - 1, writer); } fromHere = lookPointer; x = lookAhead; } } delete [] image; image = NULL; }
bool saveSpriteBank (const char * filename, spriteBank *sprites) { int i; FILE * fp = fopen (filename, "wb"); if (! fp) { return false; } if (sprites->type < 2) { // This is version 2 of the DUC format put2bytes(0, fp); fputc (2, fp); } else { // This is version 3 of the DUC format - in 32-bit glory! put2bytes(0, fp); fputc (3, fp); put2bytes (sprites->total, fp); for (i = 0; i < sprites->total; i ++) { putSigned (sprites->sprites[i].xhot, fp); putSigned (sprites->sprites[i].yhot, fp); if (!savePNGSprite (fp, sprites, i, false)) { fclose(fp); return false; } } fclose(fp); return true; } put2bytes (sprites->total, fp); // Number of colours used, except 0 because that gets added (or ignored) by the engine. fputc (sprites->myPalette.total-1, fp); for (i = 0; i < sprites->total; i ++) { put2bytes (sprites->sprites[i].width, fp); put2bytes (sprites->sprites[i].height, fp); putSigned (sprites->sprites[i].xhot, fp); putSigned (sprites->sprites[i].yhot, fp); // Run Length compressed data go here unsigned char * data = sprites->sprites[i].data; unsigned char * lookPointer; unsigned int size = sprites->sprites[i].width * sprites->sprites[i].height; int lookAhead; int x = 0; while (x < size) { lookPointer = data + 1; for (lookAhead = x+1; lookAhead < size; lookAhead++) { if (*data + sprites->myPalette.total > 255) break; if (lookAhead-x > 255) break; if (*data != * lookPointer) break; lookPointer++; } if (lookAhead == x+1) { fputc ((* data), fp); } else { fputc (*data + sprites->myPalette.total, fp); fputc (lookAhead - x - 1, fp); } data = lookPointer; x = lookAhead; } } for (i = 1; i < sprites->myPalette.total; i ++) { fputc (sprites->myPalette.r[i], fp); fputc (sprites->myPalette.g[i], fp); fputc (sprites->myPalette.b[i], fp); } fclose (fp); return true; }
void saveSounds (FILE * fp) { fputc (0, fp); put2bytes (defSoundVol, fp); put2bytes (defVol, fp); }
void sub_imm8_addr(int size, void *addr) { put2bytes(0x832d); put_addr(addr); putbyte(size); }
void add_imm8_addr(int size, void *addr) { put2bytes(0x8305); put_addr(addr); putbyte(size); }
bool savePeople (FILE * fp) { onScreenPerson * me = allPeople; int countPeople = 0, a; putSigned (scaleHorizon, fp); putSigned (scaleDivide, fp); while (me) { countPeople ++; me = me -> next; } put2bytes (countPeople, fp); me = allPeople; for (a = 0; a < countPeople; a ++) { putFloat (me -> x, fp); putFloat (me -> y, fp); saveCostume (me -> myPersona, fp); saveAnim (me -> myAnim, fp); fputc (me -> myAnim == me -> lastUsedAnim, fp); putFloat (me -> scale, fp); put2bytes (me -> extra, fp); put2bytes (me -> height, fp); put2bytes (me -> walkToX, fp); put2bytes (me -> walkToY, fp); put2bytes (me -> thisStepX, fp); put2bytes (me -> thisStepY, fp); put2bytes (me -> frameNum, fp); put2bytes (me -> frameTick, fp); put2bytes (me -> walkSpeed, fp); put2bytes (me -> spinSpeed, fp); putSigned (me -> floaty, fp); fputc (me -> show, fp); fputc (me -> walking, fp); fputc (me -> spinning, fp); if (me -> continueAfterWalking) { fputc (1, fp); saveFunction (me -> continueAfterWalking, fp); } else { fputc (0, fp); } put2bytes (me -> direction, fp); put2bytes (me -> angle, fp); put2bytes (me -> angleOffset, fp); put2bytes (me -> wantAngle, fp); putSigned (me -> directionWhenDoneWalking, fp); putSigned (me -> inPoly, fp); putSigned (me -> walkToPoly, fp); fputc (me -> r, fp); fputc (me -> g, fp); fputc (me -> b, fp); fputc (me -> colourmix, fp); fputc (me -> transparency, fp); saveObjectRef (me -> thisType, fp); me = me -> next; } return true; }