static int _generate_star(PyObject *s, void *vg) { gen_state_t *g = (gen_state_t *)vg; if (SYMOBJ(s)->clean || g->clean || (!gen_state_hit_limit(g) && !gen_state_hit_depth(g))) { if (gen_state_inc_star_depth(g, s)) return -1; if (!SYMOBJ(s)->clean && !g->clean && chance(.1)) { // For the repetition generator, I think it helps to do self sometimes... DBGN(D_GEN, "-> *1 self %s/%d (L%d)\n", SYMOBJ(SYMOBJ(s)->data.star.child)->name, SYMOBJ(SYMOBJ(s)->data.star.child)->id, SYMOBJ(SYMOBJ(s)->data.star.child)->line_no); if (_generate(SYMOBJ(s), g)) return -1; if (_generate(SYMOBJ(SYMOBJ(s)->data.star.child), g)) return -1; } else if (!SYMOBJ(s)->clean && !g->clean && chance(.09)) { DBGN(D_GEN, "-> *1 %s/%d self (L%d)\n", SYMOBJ(SYMOBJ(s)->data.star.child)->name, SYMOBJ(SYMOBJ(s)->data.star.child)->id, SYMOBJ(SYMOBJ(s)->data.star.child)->line_no); if (_generate(SYMOBJ(SYMOBJ(s)->data.star.child), g)) return -1; if (_generate(SYMOBJ(s), g)) return -1; } else { // When sym.star_depth is 1, the average is recommended_count. For every nesting, the average is halved. int count, i; //old: //count = rnd(rnd(SYMOBJ(s)->data.star.recommended_count * powl(2, GRMOBJ(g->grammar)->star_depth - (int)gen_state_get_star_depth(g, s)))); //new: eliminate star_depth parameter, average is recommended_count/2 at depth=1, * 0.75 at each nesting count = rnd(SYMOBJ(s)->data.star.recommended_count); for (i = 1; i < gen_state_get_star_depth(g, s); i++) count = rnd(count); if (PyErr_Occurred()) return -1; DBGN(D_GEN, "-> *%d %s/%d (L%d)\n", count, SYMOBJ(SYMOBJ(s)->data.star.child)->name, SYMOBJ(SYMOBJ(s)->data.star.child)->id, SYMOBJ(SYMOBJ(s)->data.star.child)->line_no); for (i = 0; i < count; i++) { if (!SYMOBJ(s)->clean && !g->clean && (gen_state_hit_limit(g) || gen_state_hit_depth(g))) break; if (_generate(SYMOBJ(SYMOBJ(s)->data.star.child), g)) return -1; } } if (gen_state_dec_star_depth(g, s)) { return -1; } } return 0; }
void Texture::init( const GLuint format, const int32_t width, const int32_t height ) { _generate(); _setInternalFormat( format ); resize( width, height ); }
/* This symbol filters its children through a python function... where anything is possible. functions are generated differently than other symbols: - each arg is generated into the output, but the start/end of each arg is recorded for later - after references (@symbols) are resolved, then all the functions can be called - function output replaces the args in the output (may be bigger or smaller than arg length) - function args may contain other function calls, so when function return replaces it's args, need to check if this falls within the range of another function arg, and if so repair the range */ static int _generate_function(PyObject *s, void *g) { PyObject *res, *l; int status, i, func_cookie, has_ref, defer_depth; int *args, nargs; // generate arg values l = PySequence_Fast(SYMOBJ(s)->data.func.args, "Error enumerating function args"); if (!l) return -1; nargs = PySequence_Fast_GET_SIZE(l); args = (int *)malloc(sizeof(int) * (nargs + 1)); if (!args) { Py_DECREF(l); PyErr_NoMemory(); return -1; } args[0] = gen_state_tell(g); func_cookie = gen_state_enter_function(g); defer_depth = ((gen_state_t *)g)->nfuncs; for (i = 0; i < PySequence_Fast_GET_SIZE(l); i++) { status = _generate(SYMOBJ(PySequence_Fast_GET_ITEM(l, i)), g); if (status) { Py_DECREF(l); free(args); return -1; } args[i+1] = gen_state_tell(g); // mark end of this arg } Py_DECREF(l); has_ref = gen_state_leave_function(g, func_cookie); if (has_ref) { // function call must be deferred until after references are generated return gen_state_defer_function(g, s, nargs, args, defer_depth); } else { // call function now const char *strres; res = call_func_now(s, g, nargs, args); gen_state_backtrack(g, args[0]); free(args); if (!res) return -1; strres = PyBytes_AsString(res); if (!strres) { Py_DECREF(res); return -1; } status = gen_state_write((gen_state_t *)g, strres, PyBytes_GET_SIZE(res)); Py_DECREF(res); return status; } }
static int _generate_choice(PyObject *s, void *g) { int res; PyObject *obj; obj = choose_choice(SYMOBJ(s)); if (!obj) return -1; res = _generate(SYMOBJ(obj), (gen_state_t *)g); Py_DECREF(obj); return res; }
wstring Guid::Get() { if (m_guid.empty()) { m_bReaded = _read(); if (m_bReaded == false) { _generate(); } } return m_guid; }
void Texture::upload( const int32_t width, const int32_t height, const void* ptr ) { _generate(); _grow( width, height ); if( _impl->defined ) glBindTexture( _impl->target, _impl->name ); else resize( _impl->width, _impl->height ); glTexSubImage2D( _impl->target, 0, 0, 0, width, height, _impl->format, _impl->type, ptr ); }
void EnemyGenerater::_nextWave() { _wave++; int enemyCount = (int)(ENEMY_COUNT_PER_WAVE * UserDataManager::getInstance()->getEnemyNumRate()); if (_wave == WAVE_COUNT) { enemyCount = 1; } for (int i = 0; i < enemyCount; i++) { Animal* enemy = _generate(); _generateEnemyCallback(enemy); } }
static int _generate_concat(PyObject *s, void *vg) { gen_state_t *g = vg; int i; for (i = 0; i < SYMOBJ(s)->data.concat.n_children; i++) { if (!g->tracking && !SYMOBJ(s)->clean && !g->clean && chance(.001)) { i += rnd(SYMOBJ(s)->data.concat.n_children); // skip part of this concatenation } else { if (_generate(SYMOBJ(SYMOBJ(s)->data.concat.children[i]), g)) return -1; } } return 0; }
void Texture::copyFromFrameBuffer( const GLuint internalFormat, const fabric::PixelViewport& pvp ) { EQ_GL_ERROR( "before Texture::copyFromFrameBuffer" ); LB_TS_THREAD( _thread ); _generate(); _setInternalFormat( internalFormat ); _grow( pvp.w, pvp.h ); if( _impl->defined ) glBindTexture( _impl->target, _impl->name ); else resize( _impl->width, _impl->height ); glCopyTexSubImage2D( _impl->target, 0, 0, 0, pvp.x, pvp.y, pvp.w, pvp.h ); EQ_GL_ERROR( "after Texture::copyFromFrameBuffer" ); }
void CPUParticlesEditor::_generate_emission_points() { /// hacer codigo aca PoolVector<Vector3> points; PoolVector<Vector3> normals; if (!_generate(points, normals)) { return; } if (normals.size() == 0) { node->set_emission_shape(CPUParticles::EMISSION_SHAPE_POINTS); node->set_emission_points(points); } else { node->set_emission_shape(CPUParticles::EMISSION_SHAPE_DIRECTED_POINTS); node->set_emission_points(points); node->set_emission_normals(normals); } }
void Texture::bindToFBO( const GLenum target, const int32_t width, const int32_t height ) { LB_TS_THREAD( _thread ); LBASSERT( _impl->internalFormat ); LBASSERT( _impl->glewContext ); _generate(); glBindTexture( _impl->target, _impl->name ); glTexImage2D( _impl->target, 0, _impl->internalFormat, width, height, 0, _impl->format, _impl->type, 0 ); glFramebufferTexture2DEXT( GL_FRAMEBUFFER, target, _impl->target, _impl->name, 0 ); _impl->width = width; _impl->height = height; _impl->defined = true; }
Database::Database( const char* db_name ) : _db(nullptr), _stmt(nullptr), _connected(false) { _connected = sqlite3_open( db_name, &_db ) == SQLITE_OK; _generate(); }
int _generate(SymbolObject *s, void *vg) { gen_state_t *g = vg; int local_rstate = 0; int reference_tries; DBGN(D_GEN, "%s/%d (L%d)\n", s->name, s->id, s->line_no); if (s->tracked) { if (gen_state_start_tracking_instance(g, (PyObject *)s)) return -1; } else if (s->clean || s->recursive_clean || g->clean) { if (gen_state_start_clean(g, (PyObject *)s)) return -1; } else if (!g->tracking && !gen_state_hit_depth(g)) { /* pre-generate mutations */ if (chance(.001)) return 0; // skip entirely if (!gen_state_hit_limit(g) && !gen_state_hit_depth(g)) { if (chance(.001)) { if (_generate(s, g)) // extra of same symbol (before this one) return -1; } if (chance(.001)) { if (_generate(SYMOBJ(_random_symbol(GRMOBJ(g->grammar))), g)) // extra of another symbol, before this one return -1; } // AM - random char if (chance(.001)) { const char c = (char)rnd(128); if (gen_state_write(g, &c, 1)) return -1; } } if (g->rstate == 0 && chance(.03)) { local_rstate = 1; g->rstate = 1; g->rsym = (PyObject *)s; if (g->rpoint >= 6) { PyErr_Format(PyExc_RuntimeError, "gen_state_t.rpoints overflow %d", __LINE__); return -1; } g->rpoints[g->rpoint++] = gen_state_tell(g); } else if (g->rstate == 1 && g->rsym == (PyObject *)s && chance(.3)) { g->rstate = 2; if (g->rpoint >= 6) { PyErr_Format(PyExc_RuntimeError, "gen_state_t.rpoints overflow %d", __LINE__); return -1; } g->rpoints[g->rpoint++] = gen_state_tell(g); local_rstate = 2; } } reference_tries = 100; while (1) { g->depth += 1; if (g->depth > g->depth_watermark) g->depth_watermark = g->depth; if (g->depth > 10000) { PyErr_Format(PyExc_RuntimeError, "hit hard recursion limit"); return -1; } // only respect depth here for non-terminals if ((s->terminal || !(gen_state_hit_depth(g) || gen_state_hit_limit(g))) && s->_generate((PyObject *)s, g)) return -1; g->depth -= 1; if (g->tracking || s->clean || g->clean) { if (s->tracked) { int r = gen_state_end_tracking_instance(g, (PyObject *)s); if (r == -1) return -1; if (r) { reference_tries--; if (!reference_tries) { PyErr_Format(PyExc_RuntimeError, "Failed to generate unique tracked symbol! Does it have enough possibilities? %s (L%d)", s->name, s->line_no); return -1; } continue; } } if (gen_state_end_clean(g, (PyObject *)s)) return -1; return 0; } else { break; } } // tracking/clean symbols will return from above loop rather than break out. if (gen_state_hit_depth(g)) return 0; if (local_rstate == 1) { if (g->rstate == 1) { if (chance(.01)) { // No matching inner symbol was chosen, but we can repeat what happened inside this symbol anyway! // (good for testing the scanner, if not the parser, right?) if (g->rpoint >= 5) { PyErr_Format(PyExc_RuntimeError, "gen_state_t.rpoints overflow %d", __LINE__); return -1; } g->rpoints[g->rpoint++] = gen_state_tell(g); g->rpoints[g->rpoint++] = gen_state_tell(g); g->rstate = 9; } } else { if (g->rstate != 3) { PyErr_Format(PyExc_RuntimeError, "OOPS! %d", g->rstate); return -1; } g->rstate = 4; } if (g->rpoint >= 6) { PyErr_Format(PyExc_RuntimeError, "gen_state_t.rpoints overflow %d", __LINE__); return -1; } g->rpoints[g->rpoint++] = gen_state_tell(g); } else if (local_rstate == 2) { g->rstate = 3; if (g->rpoint >= 6) { PyErr_Format(PyExc_RuntimeError, "gen_state_t.rpoints overflow %d", __LINE__); return -1; } g->rpoints[g->rpoint++] = gen_state_tell(g); } if (!gen_state_hit_limit(g) && !gen_state_hit_depth(g) && chance(.001)) { if (_generate(SYMOBJ(_random_symbol(GRMOBJ(g->grammar))), g)) // extra of another symbol, after this one return -1; } return 0; }