| 158 | y0 = 0 |
| 159 | x1 = w |
| 160 | y1 = h |
| 161 | } else { |
| 162 | for (y in r.y until r.y + r.height) { |
| 163 | buffer.limit(r.x * 4 + y * 4 * w + r.width * 4) |
| 164 | buffer.position(r.x * 4 + y * 4 * w) |
| 165 | sourceView.limit(r.x * 4 + y * 4 * w + r.width * 4) |
| 166 | sourceView.position(r.x * 4 + y * 4 * w) |
| 167 | sourceView.put(buffer) |
| 168 | } |
| 169 | // System.out.println("r= " + r); |
| 170 | x0 = Math.min(x0, r.x) |
| 171 | x1 = Math.max(x1, r.width + r.x) |
| 172 | y0 = Math.min(y0, r.y) |
| 173 | y1 = Math.max(y1, r.height + r.y) |
| 174 | } |
| 175 | } |
| 176 | sourceView.clear() |
| 177 | buffer.clear() |
| 178 | mod.incrementAndGet() |
| 179 | cb?.run() |
| 180 | } |
| 181 | |
| 182 | protected fun run() { |
| 183 | val now = System.currentTimeMillis() |
| 184 | if (now - timeSinceLastLoad > 2000 && pendingRequests.size > 0) { |
| 185 | requestDone = true |
| 186 | checkAndRunRequests() |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | companion object { |
| 191 | fun toTextureWhenReady(b: Future<ByteBuffer?>, m: Texture) { |
| 192 | m.attach(-1, Perform { |
| 193 | if (b.isDone) { |
| 194 | try { |
| 195 | // the buffer is done, but perhaps nobody has painted into it yet; which is clearly not what we want done to be |
| 196 | m.upload(b.get(), false) |
| 197 | } catch (e: InterruptedException) { |
| 198 | e.printStackTrace() |
| 199 | } catch (e: ExecutionException) { |
| 200 | e.printStackTrace() |
| 201 | } |
| 202 | false |
| 203 | } else { |
| 204 | true |
| 205 | } |
| 206 | }) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | init { |
| 211 | a = Ports.nextAvailable(9080) |
| 212 | b = Ports.nextAvailable(a + 1) |
| 213 | try { |
| 214 | s = Server(a, b) |
| 215 | } catch (e: IOException) { |
| 216 | e.printStackTrace() |
| 217 | } |