int KX_VertexProxy::pyattr_set_uvs(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v); if (PySequence_Check(value)) { MT_Point2 vec; for (int i=0; i<PySequence_Size(value) && i<RAS_TexVert::MAX_UNIT; ++i) { if (PyVecTo(PySequence_GetItem(value, i), vec)) { self->m_vertex->SetUV(i, vec); self->m_mesh->SetMeshModified(true); } else { PyErr_SetString(PyExc_AttributeError, STR_String().Format("list[%d] was not a vector", i).ReadPtr()); return PY_SET_ATTR_FAIL; } } self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } return PY_SET_ATTR_FAIL; }
CExpression* CParser::ProcessText (const char *intext) { // and parses the string in intext and returns it. CExpression* expr; text = intext; chcount = 0; if (text.Length() == 0) { return NULL; } ch = text[0]; /* if (ch != '=') { * expr = new CConstExpr(new CStringValue(text)); * *dependent = deplist; * return expr; * } else */ // NextCh(); NextSym(); expr = Expr(); if (sym != eolsym) { CExpression* oldexpr = expr; expr = new COperator2Expr(VALUE_ADD_OPERATOR, oldexpr, Error(STR_String("Extra characters after expression")));//new CConstExpr(new CErrorValue("Extra characters after expression"))); } if (errmsg) errmsg->Release(); return expr; }
TSMT_Element :: TSMT_Element( int lenString , char * StringParm ) { SymbolString = STR_String( lenString , StringParm ) ; } // End of function: TSMT !Symbol table test element constructor
int KX_FontObject::pyattr_set_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_FontObject* self = static_cast<KX_FontObject*>(self_v); if (!PyUnicode_Check(value)) return PY_SET_ATTR_FAIL; char* chars = _PyUnicode_AsString(value); /* Allow for some logic brick control */ CValue* tprop = self->GetProperty("Text"); if (tprop) { CValue *newstringprop = new CStringValue(STR_String(chars), "Text"); self->SetProperty("Text", newstringprop); newstringprop->Release(); } else { self->m_text = split_string(STR_String(chars)); } return PY_SET_ATTR_SUCCESS; }
PyObject *KX_FontObject::pyattr_get_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_FontObject* self = static_cast<KX_FontObject*>(self_v); STR_String str = STR_String(); for (int i=0; i<self->m_text.size(); ++i) { if (i!=0) str += '\n'; str += self->m_text[i]; } return PyUnicode_From_STR_String(str); }
/* returns a camera if the name is valid */ KX_Camera* KX_SceneActuator::FindCamera(const char *camName) { KX_SceneList* sl = m_KetsjiEngine->CurrentScenes(); STR_String name = STR_String(camName); KX_SceneList::iterator it = sl->begin(); KX_Camera* cam = NULL; while ((it != sl->end()) && (!cam)) { cam = (*it)->FindCamera(name); it++; } return cam; }
GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window** window, const bool stereoVisual) { GHOST_TSuccess success; GHOST_ASSERT(m_displayManager, "GHOST_System::createFullScreenWindow(): invalid display manager") GHOST_DisplaySetting settings; success = m_displayManager->getCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, settings); if (success) { //GHOST_PRINT("GHOST_System::createFullScreenWindow(): creating full-screen window\n"); *window = (GHOST_Window*)createWindow( STR_String (""), 0, 0, settings.xPixels, settings.yPixels, GHOST_kWindowStateFullScreen, GHOST_kDrawingContextTypeOpenGL, stereoVisual); success = *window == 0 ? GHOST_kFailure : GHOST_kSuccess; } return success; }
void CParser::GrabRealString(int start) { // works like GrabString but converting \\n to \n // puts part of the input string into the global variable // const_as_string, from position start, to position chchount int i; char tmpch; const_as_string = STR_String(); for (i=start;i<chcount;i++) { tmpch= text[i]; if ((tmpch =='\\') && (text[i+1] == 'n')) { tmpch = '\n'; i++; } const_as_string += tmpch; } }
/* a close copy of ConvertPythonToGameObject but for meshes */ bool ConvertPythonToMesh(PyObject *value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix) { if (value==NULL) { PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix); *object = NULL; return false; } if (value==Py_None) { *object = NULL; if (py_none_ok) { return true; } else { PyErr_Format(PyExc_TypeError, "%s, expected KX_MeshProxy or a KX_MeshProxy name, None is invalid", error_prefix); return false; } } if (PyUnicode_Check(value)) { *object = (RAS_MeshObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String( _PyUnicode_AsString(value) )); if (*object) { return true; } else { PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_MeshProxy in this scene", error_prefix, _PyUnicode_AsString(value)); return false; } } if (PyObject_TypeCheck(value, &KX_MeshProxy::Type)) { KX_MeshProxy *kx_mesh = static_cast<KX_MeshProxy*>BGE_PROXY_REF(value); /* sets the error */ if (kx_mesh==NULL) { PyErr_Format(PyExc_SystemError, "%s, " BGE_PROXY_ERROR_MSG, error_prefix); return false; } *object = kx_mesh->GetMesh(); return true; }
GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window **window, const GHOST_DisplaySetting &settings, const bool stereoVisual, const bool alphaBackground, const GHOST_TUns16 numOfAASamples) { GHOST_GLSettings glSettings = {0}; if (stereoVisual) glSettings.flags |= GHOST_glStereoVisual; if (alphaBackground) glSettings.flags |= GHOST_glAlphaBackground; glSettings.numOfAASamples = numOfAASamples; /* note: don't use getCurrentDisplaySetting() because on X11 we may * be zoomed in and the desktop may be bigger then the viewport. */ GHOST_ASSERT(m_displayManager, "GHOST_System::createFullScreenWindow(): invalid display manager"); //GHOST_PRINT("GHOST_System::createFullScreenWindow(): creating full-screen window\n"); *window = (GHOST_Window *)createWindow( STR_String(""), 0, 0, settings.xPixels, settings.yPixels, GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, glSettings, true /* exclusive */); return (*window == NULL) ? GHOST_kFailure : GHOST_kSuccess; }
void KX_KetsjiEngine::RenderDebugProperties() { STR_String debugtxt; int xcoord = 10; // mmmm, these constants were taken from blender source int ycoord = 14; // to 'mimic' behaviour float tottime = m_logger->GetAverage(); if (tottime < 1e-6f) { tottime = 1e-6f; } // Set viewport to entire canvas RAS_Rect viewport; m_canvas->SetViewPort(0, 0, int(m_canvas->GetWidth()), int(m_canvas->GetHeight())); /* Framerate display */ if (m_show_framerate) { debugtxt.Format("swap : %.3f (%.3f frames per second)", tottime, 1.0/tottime); m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, debugtxt.Ptr(), xcoord, ycoord, m_canvas->GetWidth() /* RdV, TODO ?? */, m_canvas->GetHeight() /* RdV, TODO ?? */); ycoord += 14; } /* Profile and framerate display */ if (m_show_profile) { for (int j = tc_first; j < tc_numCategories; j++) { debugtxt.Format(m_profileLabels[j]); m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, debugtxt.Ptr(), xcoord,ycoord, m_canvas->GetWidth(), m_canvas->GetHeight()); double time = m_logger->GetAverage((KX_TimeCategory)j); debugtxt.Format("%.3fms (%2.2f %%)", time*1000.f, time/tottime * 100.f); m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, debugtxt.Ptr(), xcoord + 60 ,ycoord, m_canvas->GetWidth(), m_canvas->GetHeight()); ycoord += 14; } } /* Property display*/ if (m_show_debug_properties && m_propertiesPresent) { KX_SceneList::iterator sceneit; for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++) { KX_Scene* scene = *sceneit; /* the 'normal' debug props */ vector<SCA_DebugProp*>& debugproplist = scene->GetDebugProperties(); for (vector<SCA_DebugProp*>::iterator it = debugproplist.begin(); !(it==debugproplist.end());it++) { CValue* propobj = (*it)->m_obj; STR_String objname = propobj->GetName(); STR_String propname = (*it)->m_name; if (propname == "__state__") { // reserve name for object state KX_GameObject* gameobj = static_cast<KX_GameObject*>(propobj); unsigned int state = gameobj->GetState(); debugtxt = objname + "." + propname + " = "; bool first = true; for (int statenum=1;state;state >>= 1, statenum++) { if (state & 1) { if (!first) { debugtxt += ","; } debugtxt += STR_String(statenum); first = false; } } m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, debugtxt.Ptr(), xcoord, ycoord, m_canvas->GetWidth(), m_canvas->GetHeight()); ycoord += 14; } else { CValue* propval = propobj->GetProperty(propname); if (propval) { STR_String text = propval->GetText(); debugtxt = objname + "." + propname + " = " + text; m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, debugtxt.Ptr(), xcoord, ycoord, m_canvas->GetWidth(), m_canvas->GetHeight()); ycoord += 14; } } }
} CListValue::~CListValue() { if (m_bReleaseContents) { for (unsigned int i=0;i<m_pValueArray.size();i++) { m_pValueArray[i]->Release(); } } } static STR_String gstrListRep=STR_String("List"); const STR_String & CListValue::GetText() { gstrListRep = "["; STR_String commastr = ""; for (int i=0;i<GetCount();i++) { gstrListRep += commastr; gstrListRep += GetValue(i)->GetText(); commastr = ","; } gstrListRep += "]"; return gstrListRep;
{ // empty space is solid, so always inside return true; } double* CEmptyValue::GetVector3(bool bGetTransformedVec) { assertd(false); // don't get vector from me return ZeroVector(); } static STR_String emptyString = STR_String(""); const STR_String & CEmptyValue::GetText() { return emptyString; } CValue* CEmptyValue::GetReplica() { CEmptyValue* replica = new CEmptyValue(*this); replica->ProcessReplica(); return replica; }
void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer) { bProperty* prop = (bProperty*)object->prop.first; CValue* propval; bool show_debug_info; while(prop) { propval = NULL; show_debug_info = bool (prop->flag & PROP_DEBUG); switch(prop->type) { case GPROP_BOOL: { propval = new CBoolValue((bool)(prop->data != 0)); gameobj->SetProperty(prop->name,propval); //promp->poin= &prop->data; break; } case GPROP_INT: { propval = new CIntValue((int)prop->data); gameobj->SetProperty(prop->name,propval); break; } case GPROP_FLOAT: { //prop->poin= &prop->data; float floatprop = *((float*)&prop->data); propval = new CFloatValue(floatprop); gameobj->SetProperty(prop->name,propval); } break; case GPROP_STRING: { //prop->poin= callocN(MAX_PROPSTRING, "property string"); propval = new CStringValue((char*)prop->poin,""); gameobj->SetProperty(prop->name,propval); break; } case GPROP_TIME: { float floatprop = *((float*)&prop->data); CValue* timeval = new CFloatValue(floatprop); // set a subproperty called 'timer' so that // we can register the replica of this property // at the time a game object is replicated (AddObjectActuator triggers this) CValue *bval = new CBoolValue(true); timeval->SetProperty("timer",bval); bval->Release(); if (isInActiveLayer) { timemgr->AddTimeProperty(timeval); } propval = timeval; gameobj->SetProperty(prop->name,timeval); } default: { // todo make an assert etc. } } if (propval) { if (show_debug_info) { scene->AddDebugProperty(gameobj,STR_String(prop->name)); } // done with propval, release it propval->Release(); } #ifdef WITH_PYTHON /* Warn if we double up on attributes, this isnt quite right since it wont find inherited attributes however there arnt many */ for(PyAttributeDef *attrdef = KX_GameObject::Attributes; attrdef->m_name; attrdef++) { if(strcmp(prop->name, attrdef->m_name)==0) { printf("Warning! user defined property name \"%s\" is also a python attribute for object \"%s\"\n\tUse ob[\"%s\"] syntax to avoid conflict\n", prop->name, object->id.name+2, prop->name); break; } } for(PyMethodDef *methdef = KX_GameObject::Methods; methdef->ml_name; methdef++) { if(strcmp(prop->name, methdef->ml_name)==0) { printf("Warning! user defined property name \"%s\" is also a python method for object \"%s\"\n\tUse ob[\"%s\"] syntax to avoid conflict\n", prop->name, object->id.name+2, prop->name); break; } } /* end warning check */ #endif // WITH_PYTHON prop = prop->next; } // check if state needs to be debugged if (object->scaflag & OB_DEBUGSTATE) { // reserve name for object state scene->AddDebugProperty(gameobj,STR_String("__state__")); } /* Font Objects need to 'copy' the Font Object data body to ["Text"] */ if (object->type == OB_FONT) { BL_ConvertTextProperty(object, (KX_FontObject *)gameobj, timemgr, scene, isInActiveLayer); } }
SetModified(true); } void CVectorValue::SetValue(CValue *newval) { double* newvec = ((CVectorValue*)newval)->GetVector3(); m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X]; m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y]; m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z]; SetModified(true); } static const STR_String gstrVectorStr=STR_String(); const STR_String & CVectorValue::GetText() { assertd(false); return gstrVectorStr; } CValue* CVectorValue::GetReplica() { CVectorValue* replica = new CVectorValue(*this); replica->ProcessReplica(); return replica; }; /*void CVectorValue::Transform(rcMatrix4x4 mat) { m_transformedvec = mat*m_vec;
void BL_ConvertControllers( struct Object* blenderobject, class KX_GameObject* gameobj, SCA_LogicManager* logicmgr, int activeLayerBitInfo, bool isInActiveLayer, KX_BlenderSceneConverter* converter ) { int uniqueint=0; int count = 0; int executePriority=0; bController* bcontr = (bController*)blenderobject->controllers.first; while (bcontr) { bcontr = bcontr->next; count++; } gameobj->ReserveController(count); bcontr = (bController*)blenderobject->controllers.first; while (bcontr) { SCA_IController* gamecontroller = NULL; switch(bcontr->type) { case CONT_LOGIC_AND: { gamecontroller = new SCA_ANDController(gameobj); break; } case CONT_LOGIC_OR: { gamecontroller = new SCA_ORController(gameobj); break; } case CONT_LOGIC_NAND: { gamecontroller = new SCA_NANDController(gameobj); break; } case CONT_LOGIC_NOR: { gamecontroller = new SCA_NORController(gameobj); break; } case CONT_LOGIC_XOR: { gamecontroller = new SCA_XORController(gameobj); break; } case CONT_LOGIC_XNOR: { gamecontroller = new SCA_XNORController(gameobj); break; } case CONT_EXPRESSION: { bExpressionCont* bexpcont = (bExpressionCont*) bcontr->data; STR_String expressiontext = STR_String(bexpcont->str); if (expressiontext.Length() > 0) { gamecontroller = new SCA_ExpressionController(gameobj,expressiontext); } break; } case CONT_PYTHON: { bPythonCont* pycont = (bPythonCont*) bcontr->data; SCA_PythonController* pyctrl = new SCA_PythonController(gameobj, pycont->mode); gamecontroller = pyctrl; #ifdef WITH_PYTHON pyctrl->SetNamespace(converter->GetPyNamespace()); if(pycont->mode==SCA_PythonController::SCA_PYEXEC_SCRIPT) { if (pycont->text) { char *buf; // this is some blender specific code buf= txt_to_buf(pycont->text); if (buf) { pyctrl->SetScriptText(STR_String(buf)); pyctrl->SetScriptName(pycont->text->id.name+2); MEM_freeN(buf); } } } else { /* let the controller print any warnings here when importing */ pyctrl->SetScriptText(STR_String(pycont->module)); pyctrl->SetScriptName(pycont->module); /* will be something like module.func so using it as the name is OK */ if(pycont->flag & CONT_PY_DEBUG) { printf("\nDebuging \"%s\", module for object %s\n\texpect worse performance.\n", pycont->module, blenderobject->id.name+2); pyctrl->SetDebug(true); } } #endif // WITH_PYTHON break; } default: { } } if (gamecontroller) { LinkControllerToActuators(gamecontroller,bcontr,logicmgr,converter); gamecontroller->SetExecutePriority(executePriority++); gamecontroller->SetBookmark((bcontr->flag & CONT_PRIO) != 0); gamecontroller->SetState(bcontr->state_mask); STR_String uniquename = bcontr->name; uniquename += "#CONTR#"; uniqueint++; CIntValue* uniqueval = new CIntValue(uniqueint); uniquename += uniqueval->GetText(); uniqueval->Release(); //unique name was never implemented for sensors and actuators, only for controllers //and it's producing difference in the keys for the lists: obj.controllers/sensors/actuators //at some point it should either be implemented globally (and saved as a separate var) or removed. //gamecontroller->SetName(uniquename); gamecontroller->SetName(bcontr->name); gameobj->AddController(gamecontroller); converter->RegisterGameController(gamecontroller, bcontr); #ifdef WITH_PYTHON if (bcontr->type==CONT_PYTHON) { SCA_PythonController *pyctrl= static_cast<SCA_PythonController*>(gamecontroller); /* not strictly needed but gives syntax errors early on and * gives more predictable performance for larger scripts */ if(pyctrl->m_mode==SCA_PythonController::SCA_PYEXEC_SCRIPT) pyctrl->Compile(); else { /* We cant do this because importing runs the script which could end up accessing * internal BGE functions, this is unstable while we're converting the scene. * This is a pitty because its useful to see errors at startup but cant help it */ // pyctrl->Import(); } } #endif // WITH_PYTHON //done with gamecontroller gamecontroller->Release(); } bcontr = bcontr->next; } }