CommunicationObjectType* CommunicationObject::ClearDataIndex(const unsigned int index) { CommunicationObjectType* copy = GetDataIndex(index); if (copy != NULL) { RemoveDataIndex(index); } return copy; }
inline void SetInDTWMatrix(size_t x, size_t y, double val) { data_[GetDataIndex(x, y)] = val; }
short ResourceCommands() { char *filemem; int filelen; int n,v; SkipWhiteSpace(); //--------------------------------------------------------- if (QToken(".library")) { SkipLine(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".lfile")) { SkipWhiteSpace(); GetLFileName(); GetRelPath(Name); return 1; } if (QToken(".localscope")) { SkipWhiteSpace(); NeedToken("+"); // LocalScope++; return 1; } if (QToken(".res")) { // If there is previous data to be written out // do it here !! if (ResType != 0) { FinalizeResource(); } SkipWhiteSpace(); ResName[0] = 0; Name[0] = 0; if (isalpha(*FilePtr)) { GetName(); // Get the new type Name strcpy(ResName, Name); } // Clear index table IndexCount = 0; IndexWidth = 0; MakeNewResource(Name); // Make this symbolic return 1; } //------------------------------------ // //------------------------------------ if (QToken(".index")) { int IndexOffset = GetDataIndex(); SkipWhiteSpace(); Name[0] = 0; if (isalpha(*FilePtr)) GetName(); // Get the index ref name // add index to table IndexTable[IndexCount] = IndexOffset; // MakeIndexedResource(IndexName, IndexCount); infoprintf("%d: index = %d ('%s')\n",IndexCount, IndexOffset, Name); if (Pass == 2) if (Name[0]) fprintf(HeaderFile,"#define idx_%s %d\n", Name, IndexCount); IndexCount++; return 1; } //------------------------------------ // //------------------------------------ if (QToken(".wideindex")) { IndexWidth = 1; SkipWhiteSpace(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".extension")) { SkipWhiteSpace(); v = GetExpression(); // x ResType = v; infoprintf("%d: Prototype = %d\n",CurrentResource, ResType); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".dispose")) { SkipWhiteSpace(); ResDispose = 1; return 1; } //------------------------------------ // //------------------------------------ if (QToken(".placeholder")) { ResType = ResType_PlaceHolder; infoprintf("%d: Placeholder\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".skip")) { ResType = ResType_Skip; infoprintf("%d: Skip\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".bin")) { ResType = ResType_Binary; infoprintf("%d: Binary\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".ubin")) { ResType = ResType_UBinary; infoprintf("%d: UBinary\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".media")) { int slen; SkipWhiteSpace(); ResType = ResType_Binary; //ResType_Media; GetStringName(128); slen = strlen(Name) + 1; for (n=0;n<slen;n++) WriteByte(Name[n]); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); GetStringName(128); if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading data file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) { WriteByte(filemem[n]); } Free_File(filemem); infoprintf("%d: Media Binary\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".umedia")) { int slen; SkipWhiteSpace(); ResType = ResType_UBinary; //ResType_UMedia; GetStringName(128); slen = strlen(Name) + 1; for (n=0;n<slen;n++) WriteByte(Name[n]); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); GetStringName(128); if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading data file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) { WriteByte(filemem[n]); } Free_File(filemem); infoprintf("%d: Media Binary\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ /* if (QToken(".file")) { SkipWhiteSpace(); ResType = ResType_File; GetStringName(128); filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error("Error reading data file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) { WriteByte(filemem[n]); } Free_File(filemem); printf("%d: File '%s' size %d\n", CurrentResource, Name, filelen); return 1; } */ //------------------------------------ // //------------------------------------ if (QToken(".label")) // filename { int slen; SkipWhiteSpace(); ResType = ResType_Label; GetStringName(128); slen = strlen(Name) + 1; for (n=0;n<slen;n++) WriteByte(Name[n]); return 1; } //------------------------------------ // //------------------------------------ // ResType_TileSet = 7 // ushort xsize, ysize // bytes png_image if (QToken(".tileset")) // filename { int xsize,ysize; SkipWhiteSpace(); ResType = ResType_TileSet; GetStringName(128); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); xsize = GetExpression(); // xsize SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); ysize = GetExpression(); // ysize WriteWord(xsize); WriteWord(ysize); if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading tileset file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) WriteByte(filemem[n]); Free_File(filemem); infoprintf("%d: Tileset '%s' cxy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen); return 1; } //------------------------------------ // //------------------------------------ // ResType_TileMap = 8 // ushort mapWidth, mapHeight // ushort map[mapWidth*mapHeight] if (QToken(".tilemap")) // filename { int xsize,ysize; SkipWhiteSpace(); ResType = ResType_TileMap; GetStringName(128); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); xsize = GetExpression(); // xsize SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); ysize = GetExpression(); // ysize if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading tilemap file '%s'", Name); return 1; } filelen = FileAlloc_Len(); if (filelen != (xsize * ysize * 2)) { Error(Error_Fatal, "%d: Tilemap '%s' xy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen); return 1; } WriteWord(xsize); WriteWord(ysize); for (n=0;n<filelen;n++) WriteByte(filemem[n]); Free_File(filemem); infoprintf("%d: Tilemap '%s' cxy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".image")) // filename { SkipWhiteSpace(); ResType = ResType_Image; GetStringName(128); /* spr_cx = spr_cy = 0; SkipWhiteSpace(); if (QToken(",")) { spr_cx = GetExpression(); // cx SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_cy = GetExpression(); // cy } WriteWord(spr_cx); WriteWord(spr_cy); */ if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading image file '%s'", Name); return 1; } filelen = FileAlloc_Len(); // write the length //WriteEncodedInt(filelen); for (n=0;n<filelen;n++) WriteByte(filemem[n]); Free_File(filemem); infoprintf("%d: Image '%s' cxy %d,%d size %d\n", CurrentResource, Name, spr_cx, spr_cy, filelen); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".sprite")) // index, x,y,w,h,cx,cy { ResType = ResType_Sprite; SkipWhiteSpace(); spr_ind = v = GetExpression(); // ind WriteWord(v); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_x = v = GetExpression(); // x WriteWord(v); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_y = v = GetExpression(); // y WriteWord(v); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_w = v = GetExpression(); // w WriteWord(v); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_h = v = GetExpression(); // h WriteWord(v); spr_cx = spr_cy = 0; SkipWhiteSpace(); if (QToken(",")) { spr_cx = (short)GetExpression(); // cx SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_cy = (short)GetExpression(); // cy } WriteWord(spr_cx); WriteWord(spr_cy); infoprintf("%d: Sprite ind %d, xy %d,%d, wh %d,%d cxy %d,%d\n", CurrentResource, spr_ind, spr_x, spr_y, spr_w, spr_h, spr_cx, spr_cy); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".end")) { SkipLine(); // EndComp = 1; return 1; } //------------------------------------ // //------------------------------------ if (QToken(".eof")) { SkipLine(); EndComp = 1; return 1; } //------------------------------------ // //------------------------------------ if (QToken(".parseheader")) { GetStringName(128); ReadAndParseHeaders(Name); return 1; } //------------------------------------ // Other directives //------------------------------------ if (QToken(".set")) { if (QToken("$")) { char VarName[256]; // Accept a string GetName(); // Get the new type Name strcpy(VarName, Name); NeedToken("="); GetStringName(128); printf("string set %s = '%s'\n", VarName, Name); RedefENumString(VarName, Name); return 1; } GetName(); // Get the new type Name NeedToken("="); RedefENum(Name, GetExpression()); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".debug")) { DEBUG = (short)GetExpression(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".info")) { INFO = (short)GetExpression(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".list")) { LIST = (short)GetExpression(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".show")) { int exp = GetExpression(); printf("%d",exp); if (!Token(";")) printf("\n"); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".print") || QToken(".?")) { int exp; char c; if (Token("\"")) { while(1) { c = *FilePtr; if (c == 0 || c == '"') break; printf("%c",c); FilePtr++; } NeedToken("\""); if (!Token(";")) printf("\n"); return 1; } exp = GetExpression(); printf("%d",exp); if (!Token(";")) printf("\n"); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".if")) { if (!GetExpression()) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //------------------------------------ // //------------------------------------ if (QToken(".ifdef")) { GetName(); // Get the new type Name SkipWhiteSpace(); if (!SymbolExists(Name, section_Script, -1)) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //------------------------------------ // //------------------------------------ if (QToken(".ifndef")) { GetName(); // Get the new type Name SkipWhiteSpace(); if (SymbolExists(Name, section_Script, -1)) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //------------------------------------ // //------------------------------------ if (QToken(".while")) { if (GetExpression()) { FilePtr = SearchScope(FilePtr); } return 1; } //------------------------------------ // //------------------------------------ if (QToken(".enum")) { AsmEnums(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".include")) // filename { SkipWhiteSpace(); GetStringName(128); if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading include file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) WriteByte(filemem[n]); Free_File(filemem); infoprintf("bin include '%s' size %d\n", Name, filelen); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".varint")) { do { imm = GetExpression(); // Get the number WriteEncodedInt(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".varsint")) { do { imm = GetExpression(); // Get the number WriteEncodedSignedInt(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".byte")) { do { imm = GetExpression(); // Get the number WriteByte(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".half")) { do { imm = GetExpression(); // Get the number WriteWord(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".word")) { do { imm = GetExpression(); // Get the number WriteLong(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".fill")) { imm = GetExpression(); // Get the number if (!imm) return 1; NeedToken(","); v = GetExpression(); do { WriteByte(v); } while(--imm); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".pstring")) { int dataStart; int len; // Write length byte WriteByte(0); // Get current data location dataStart = DataIP; // read string to mem GetStrings(); // find the string length len = DataIP - dataStart; if (len > 255) { Error(Error_Skip, "pstring is longer that 255 chars\n"); return 1; } // Patch the string length ArraySet(&DataMemArray, dataStart-1, len); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".cstring")) { GetStrings(); WriteByte(0); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".string")) { GetStrings(); return 1; } //------------------------------------ // //------------------------------------ // Error GetAsmName(); Error(Error_Fatal, "Illegal resource directive '%s'",Name); return 0; }
inline double GetFromDTWMatrix(size_t x, size_t y) { return data_[GetDataIndex(x, y)]; }