void boxDrawDBG(SGEntity* entity) { if(entity == NULL) return; Box* box = entity->data; if(box->numcoll) { sgDrawColor4f(1.0, 0.0, 0.0, 1.0); sgEntityDraw(entity); } else { sgDrawColor4f(1.0, 1.0, 1.0, 1.0); sgEntityDraw(entity); } //sgDrawLineSetWidth(2.0); sgDrawPointSetSize(2.0); /*SGVec2 pos; sgEntityGetPos(entity, &pos.x, &pos.y);*/ sgDrawColor4f(1.0, 0.0, 0.0, 1.0); size_t i, j; for(i = 0; i < SG_MIN(box->numcoll, MAXCOLLS); i++) { for(j = 0; j < box->numcontacts[i]; j++) { //sgDrawColor4f(1.0, 0.0, 0.0, 1.0); sgDrawPoint(box->points[i][j].x, box->points[i][j].y); //sgDrawColor4f(0.0, 1.0, 0.0, 1.0); //sgDrawLine(box->points[i][j].x, box->points[i][j].y, box->points[i][j].x + box->normals[i][j].x, box->points[i][j].y + box->normals[i][j].y); //sgDrawColor4f(0.0, 0.0, 1.0, 1.0); //sgDrawLine(pos.x, pos.y, pos.x + box->impulse[i][j].x, pos.y + box->impulse[i][j].y); } } //sgDrawLineSetWidth(1.0); sgDrawPointSetSize(1.0); sgPhysicsShapeDrawDBG(box->shape); }
static void my_dump_id(SG_context * pCtx, const char* psz_hid, SG_uint32 nrDigits, SG_uint32 indent, SG_string * pStringOutput) { char buf[4000]; // we can abbreviate the full IDs. nrDigits = SG_MIN(nrDigits, SG_HID_MAX_BUFFER_LENGTH); nrDigits = SG_MAX(nrDigits, 4); // create: // Dagnode[addr]: <child_id> <gen> [<parent_id>...] SG_ERR_CHECK_RETURN( SG_sprintf(pCtx,buf,SG_NrElements(buf),"%*c ",indent,' ') ); SG_ERR_CHECK_RETURN( SG_string__append__sz(pCtx,pStringOutput,buf) ); SG_ERR_CHECK_RETURN( SG_string__append__buf_len(pCtx,pStringOutput,(SG_byte *)(psz_hid),nrDigits) ); SG_ERR_CHECK_RETURN( SG_string__append__sz(pCtx,pStringOutput,"\n") ); }
char* SG_EXPORT _sgJSONParseString(SGJSONValue* into, char* input, char** error) { char startc; into->type = SG_JSON_TYPE_STRING; SGbool escape = SG_FALSE; startc = *input; if(startc != '"' && startc != '\'' && startc != '`') // ' and ` are extensions return input; input++; size_t len = 0; size_t mem = 32; into->v.string = malloc(mem); size_t maxspan; size_t span; char convbuf[5]; convbuf[4] = 0; unsigned long ul; while(*input) { /* * We need 2+1 additional memory: * Plus 2 potential chars (for \u) and null-termination. */ if(len + 2 >= mem) { mem <<= 1; into->v.string = realloc(into->v.string, mem); } if(escape) { switch(*input) { case '"': case '\'': case '`': case '\\': case '/': into->v.string[len++] = *input; input++; break; case 'b': into->v.string[len++] = '\b'; input++; break; case 'f': into->v.string[len++] = '\f'; input++; break; case 'n': into->v.string[len++] = '\n'; input++; break; case 'r': into->v.string[len++] = '\r'; input++; break; case 't': into->v.string[len++] = '\t'; input++; break; case 'a': into->v.string[len++] = '\a'; input++; break; // extension case 'e': into->v.string[len++] = '\033'; input++; break; // extension case 'x': // extension case 'u': maxspan = (*input == 'x') ? 2 : 4; input++; span = SG_MIN(strspn(input, SG_HEXDIGITS), maxspan); /* * It is fine to report an error, despite the extension - * \xXX is illegal in JSON in either case without it. */ if(span < maxspan) { *error = "Invalid \\xXX or \\uXXXX escape sequence!"; return NULL; } memcpy(convbuf, input, span); convbuf[span] = 0; input += span; // 2-4 hex digits ul = strtoul(convbuf, NULL, 16); if(maxspan == 4) into->v.string[len++] = ul >> 8; // hi part into->v.string[len++] = ul; break; default: // extension: \ooo octal escape input++; span = SG_MIN(strspn(input, SG_OCTDIGITS), 3); // we need up to 3! if(span < 1) // no oct chars, which means we don't knwow what this is... { if(into->strbuf) free(into->strbuf); into->strbuf = sgAPrintf("Unknown escape sequence \\%c!", *input); *error = into->strbuf; return NULL; } // we have at least 1 oct char! memcpy(convbuf, input, span); convbuf[span] = 0; input += span; ul = strtoul(convbuf, NULL, 8); into->v.string[len++] = ul; } escape = SG_FALSE; } else if(*input == '\\') { input++; escape = SG_TRUE; } else if(*input == startc) { input++; into->v.string[len] = 0; return input; } else { into->v.string[len++] = *input; input++; } }