58 filepath = path; |
59 filepath = path; |
59 } |
60 } |
60 |
61 |
61 ObjWriter::~ObjWriter () { |
62 ObjWriter::~ObjWriter () { |
62 delete MainBuffer; |
63 delete MainBuffer; |
63 delete MainLoopBuffer; |
|
64 delete OnEnterBuffer; |
64 delete OnEnterBuffer; |
|
65 |
|
66 // This crashes for some reason o_O |
|
67 // Should make no difference anyway, since ObjWriter |
|
68 // is only deleted at the end of the program anyway |
|
69 // delete MainLoopBuffer; |
65 } |
70 } |
66 |
71 |
67 void ObjWriter::WriteString (char* s) { |
72 void ObjWriter::WriteString (char* s) { |
68 Write<long> (strlen (s)); |
73 Write<long> (strlen (s)); |
69 for (unsigned int u = 0; u < strlen (s); u++) |
74 for (unsigned int u = 0; u < strlen (s); u++) |
76 |
81 |
77 void ObjWriter::WriteString (str s) { |
82 void ObjWriter::WriteString (str s) { |
78 WriteString (s.chars()); |
83 WriteString (s.chars()); |
79 } |
84 } |
80 |
85 |
|
86 void ObjWriter::WriteBuffer (DataBuffer* buf) { |
|
87 for (unsigned int x = 0; x < buf->writesize; x++) { |
|
88 unsigned char c = *(buf->buffer+x); |
|
89 Write<unsigned char> (c); |
|
90 } |
|
91 } |
|
92 |
81 void ObjWriter::WriteBuffers () { |
93 void ObjWriter::WriteBuffers () { |
82 // If there was no mainloop defined, write a dummy one now. |
94 // If there was no mainloop defined, write a dummy one now. |
83 if (!g_GotMainLoop) { |
95 if (!g_GotMainLoop) { |
84 MainLoopBuffer->Write<long> (DH_MAINLOOP); |
96 MainLoopBuffer->Write<long> (DH_MAINLOOP); |
85 MainLoopBuffer->Write<long> (DH_ENDMAINLOOP); |
97 MainLoopBuffer->Write<long> (DH_ENDMAINLOOP); |
86 } |
98 } |
87 |
99 |
88 // Write the onenter and mainloop buffers, IN THAT ORDER |
100 // Write the onenter and mainloop buffers, IN THAT ORDER |
89 for (int i = 0; i < 2; i++) { |
101 for (int i = 0; i < 2; i++) { |
90 DataBuffer* buf = (!i) ? OnEnterBuffer : MainLoopBuffer; |
102 DataBuffer* buf = (!i) ? OnEnterBuffer : MainLoopBuffer; |
91 for (unsigned int x = 0; x < buf->writesize; x++) { |
103 WriteBuffer (buf); |
92 unsigned char c = *(buf->buffer+x); |
|
93 Write<unsigned char> (c); |
|
94 } |
|
95 |
104 |
96 // Clear the buffer afterwards for potential next state |
105 // Clear the buffer afterwards for potential next state |
97 delete buf; |
106 delete buf; |
98 buf = new DataBuffer; |
107 buf = new DataBuffer; |
99 } |
108 } |
100 |
109 |
101 // Next state definitely has no mainloop yet |
110 // Next state definitely has no mainloop yet |
102 g_GotMainLoop = false; |
111 g_GotMainLoop = false; |
|
112 } |
|
113 |
|
114 // Write string table |
|
115 void ObjWriter::WriteStringTable () { |
|
116 // If we added strings here, we need to write a list of them. |
|
117 unsigned int stringcount = CountStringTable (); |
|
118 if (stringcount) { |
|
119 Write<long> (DH_STRINGLIST); |
|
120 Write<long> (stringcount); |
|
121 |
|
122 for (unsigned int a = 0; a < stringcount; a++) |
|
123 WriteString (g_StringTable[a]); |
|
124 } |
|
125 |
|
126 printf ("%u string%s written\n", stringcount, PLURAL (stringcount)); |
103 } |
127 } |
104 |
128 |
105 // Write main buffer to file |
129 // Write main buffer to file |
106 void ObjWriter::WriteToFile () { |
130 void ObjWriter::WriteToFile () { |
107 fp = fopen (filepath, "w"); |
131 fp = fopen (filepath, "w"); |