void CHOM::Load () { // Find and open file string_path fName; FS.update_path (fName,"$level$","level.hom"); if (!FS.exist(fName)) { Msg (" WARNING: Occlusion map '%s' not found.",fName); return; } Msg ("* Loading HOM: %s",fName); IReader* fs = FS.r_open(fName); IReader* S = fs->open_chunk(1); // Load tris and merge them CDB::Collector CL; while (!S->eof()) { HOM_poly P; S->r (&P,sizeof(P)); CL.add_face_packed_D (P.v1,P.v2,P.v3,P.flags,0.01f); } // Determine adjacency xr_vector<u32> adjacency; CL.calc_adjacency (adjacency); // Create RASTER-triangles m_pTris = xr_alloc<occTri> (u32(CL.getTS())); for (u32 it=0; it<CL.getTS(); it++) { CDB::TRI& clT = CL.getT()[it]; occTri& rT = m_pTris[it]; Fvector& v0 = CL.getV()[clT.verts[0]]; Fvector& v1 = CL.getV()[clT.verts[1]]; Fvector& v2 = CL.getV()[clT.verts[2]]; rT.adjacent[0] = (0xffffffff==adjacency[3*it+0])?((occTri*) (-1)):(m_pTris+adjacency[3*it+0]); rT.adjacent[1] = (0xffffffff==adjacency[3*it+1])?((occTri*) (-1)):(m_pTris+adjacency[3*it+1]); rT.adjacent[2] = (0xffffffff==adjacency[3*it+2])?((occTri*) (-1)):(m_pTris+adjacency[3*it+2]); rT.flags = clT.dummy; rT.area = Area (v0,v1,v2); if (rT.area<EPS_L) { Msg ("! Invalid HOM triangle (%f,%f,%f)-(%f,%f,%f)-(%f,%f,%f)",VPUSH(v0),VPUSH(v1),VPUSH(v2)); } rT.plane.build (v0,v1,v2); rT.skip = 0; rT.center.add(v0,v1).add(v2).div(3.f); } // Create AABB-tree m_pModel = xr_new<CDB::MODEL> (); m_pModel->build (CL.getV(),int(CL.getVS()),CL.getT(),int(CL.getTS())); bEnabled = TRUE; S->close (); FS.r_close (fs); }
void CALifeMonsterDetailPathManager::actualize () { m_path.clear (); typedef GraphEngineSpace::CGameVertexParams CGameVertexParams; CGameVertexParams temp = CGameVertexParams(object().m_tpaTerrain); bool failed = !ai().graph_engine().search ( ai().game_graph(), object().m_tGraphID, m_destination.m_game_vertex_id, &m_path, temp ); #ifdef DEBUG if (failed) { Msg ("! %s couldn't build game path from",object().name_replace()); { const CGameGraph::CVertex *vertex = ai().game_graph().vertex(object().m_tGraphID); Msg ( "! [%d][%s][%f][%f][%f]", object().m_tGraphID, *ai().game_graph().header().level( vertex->level_id() ).name(), VPUSH(vertex->level_point()) ); } { const CGameGraph::CVertex *vertex = ai().game_graph().vertex(m_destination.m_game_vertex_id); Msg ( "! [%d][%s][%f][%f][%f]", m_destination.m_game_vertex_id, *ai().game_graph().header().level( vertex->level_id() ).name(), VPUSH(vertex->level_point()) ); } } #endif if (failed) return; VERIFY (!m_path.empty()); if (m_path.size() == 1) { VERIFY (m_path.back() == object().m_tGraphID); return; } m_walked_distance = 0.f; std::reverse (m_path.begin(),m_path.end()); VERIFY (m_path.back() == object().m_tGraphID); }
int netCb(char* src,int lensrc,char* macsrc) { VPUSH(PNTTOVAL(VMALLOCSTR(src,lensrc))); VPUSH(PNTTOVAL(VMALLOCSTR(macsrc,6))); VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP)); if (VSTACKGET(0)!=NIL) interpGo(); else { VPULL();VPULL();} VPULL(); return 0; }
int main(int argc,char **argv) { PropLoad("config.txt"); if (!handle_options(argc, argv)) { return -1; } PropDump(); if (!vcompDoit(PropGet("SOURCE"))) { loadbytecode("foo.bin"); vmemInit(0); if (!strcmp(PropGet("BOOT"),"firmware")) { loaderInit((char*)dumpbc); } else { loaderInit(srcbytecode); } vmemDumpShort(); getchar(); simuInit(); VPUSH(INTTOVAL(0)); interpGo(); VPULL(); while(1) { simuDoLoop(); VPUSH(VCALLSTACKGET(sys_start,SYS_CBLOOP)); if (VSTACKGET(0)!=NIL) { interpGo(); } VPULL(); usleep(50 * 1000); } getchar(); } return 0; }
void sysRfidread(char* id,int bloc) { #ifdef VSIMU VPUSH(NIL); #endif #ifdef VREAL char buf[4]; int k=rfid_read(id,bloc,buf); if (k) { VPUSH(NIL); return; } VPUSH(PNTTOVAL(VMALLOCSTR(buf,4))); #endif }
void Log (const char *msg, const Fvector &dop) { u32 buffer_size = (xr_strlen(msg) + 2 + 3*(64 + 1) + 1) * sizeof(char); PSTR buf = (PSTR)_alloca( buffer_size ); xr_sprintf (buf, buffer_size,"%s (%f,%f,%f)",msg, VPUSH(dop) ); Log (buf); }
void sysItoh(int v) { char res[16]; int ires=0; if (v==0) { res[ires++]='0'; } else { int start=1; int imul=28; while(imul>=0) { int c=(v>>imul)&15; if ((c)||(!start)) { start=0; res[ires++]=(c<10)?'0'+c:'a'+c-10; } imul-=4; } } VPUSH(PNTTOVAL(VMALLOCSTR(res,ires))); }
void sysItobin2(int c) { unsigned char res[2]; res[1]=c; c>>=8; res[0]=c; VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,2))); }
void _draw_cam_pos(CGameFont* pFont) { float sz = pFont->GetHeight(); pFont->SetHeightI(0.02f); pFont->SetColor (0xffffffff); pFont->Out (10, 600, "CAMERA POSITION: [%3.2f,%3.2f,%3.2f]",VPUSH(Device.vCameraPosition)); pFont->SetHeight(sz); pFont->OnRender (); }
void sysCtoh(int c) { unsigned char res[2]; int v=(c>>4)&15; res[0]=(v<10)?'0'+v:'a'+v-10; v=c&15; res[1]=(v<10)?'0'+v:'a'+v-10; VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,2))); }
int sysI2cRead(unsigned char addr_i2c, int bufsize) { uchar* data; int nmax=1000; while((nmax>0)&&(read_i2c(addr_i2c,data,bufsize)==FALSE)){ nmax--;__no_operation(); } VPUSH(PNTTOVAL(VMALLOCSTR((unsigned char*)data,bufsize))); return nmax; }
/** UDPEventRead */ int udpEventRead(int fd) { char buf[4096]; struct sockaddr_in add; int i=udpbysock(fd); int l=sizeof(add); int res=recvfrom(fd,buf,4096,0,(struct sockaddr *)&add,&l); if (res<0) return 1; my_printf(LOG_SIMUNET, "Sockets : UDP Read %d bytes on :%d from %s:%d\n",res,udp_port[i],inet_ntoa(add.sin_addr),ntohs(add.sin_port)); VPUSH(INTTOVAL(i)); VPUSH(PNTTOVAL(VMALLOCSTR(buf,res))); VPUSH(PNTTOVAL(VMALLOCSTR((char*)&add.sin_addr.s_addr,4))); VPUSH(VCALLSTACKGET(sys_start,SYS_CBUDP)); if (VSTACKGET(0)!=NIL) interpGo(); else { VPULL();VPULL();VPULL();} VPULL(); return 1; }
/** Gère un evt write sur une socket */ int tcpEventWrite(int fd) { int idx = tcpbysock(fd); if (idx<0) { my_printf(LOG_SIMUNET, "Sockets : idx < 0\n"); return 0; } tcp_writeEventToNotify[idx] = 0; my_printf(LOG_SIMUNET, "Sockets : Write event on %d\n",idx); VPUSH(INTTOVAL(idx)); VPUSH(INTTOVAL(0)); VPUSH(NIL); VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP)); if (VSTACKGET(0)!=NIL) interpGo(); else { VPULL();VPULL();VPULL();} VPULL(); return 1; }
void netSeqAdd(unsigned char* seq,int n) { unsigned char res[4]; unsigned int val; val=(seq[0]<<24)+(seq[1]<<16)+(seq[2]<<8)+seq[3]; val+=n; res[3]=val; val>>=8; res[2]=val; val>>=8; res[1]=val; val>>=8; res[0]=val; VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,4))); }
// HUD void CActor::OnHUDDraw (CCustomHUD* /**hud/**/) { CHudItem* pHudItem = smart_cast<CHudItem*>(inventory().ActiveItem()); if (pHudItem && pHudItem->GetHUDmode()) // if(inventory().ActiveItem() ) { inventory().ActiveItem()->renderable_Render(); } #if 0//ndef NDEBUG if (Level().CurrentControlEntity() == this && g_ShowAnimationInfo) { string128 buf; HUD().Font().pFontStat->SetColor (0xffffffff); HUD().Font().pFontStat->OutSet (170,530); HUD().Font().pFontStat->OutNext ("Position: [%3.2f, %3.2f, %3.2f]",VPUSH(Position())); HUD().Font().pFontStat->OutNext ("Velocity: [%3.2f, %3.2f, %3.2f]",VPUSH(m_PhysicMovementControl->GetVelocity())); HUD().Font().pFontStat->OutNext ("Vel Magnitude: [%3.2f]",m_PhysicMovementControl->GetVelocityMagnitude()); HUD().Font().pFontStat->OutNext ("Vel Actual: [%3.2f]",m_PhysicMovementControl->GetVelocityActual()); switch (m_PhysicMovementControl->Environment()) { case CPHMovementControl::peOnGround: strcpy(buf,"ground"); break; case CPHMovementControl::peInAir: strcpy(buf,"air"); break; case CPHMovementControl::peAtWall: strcpy(buf,"wall"); break; } HUD().Font().pFontStat->OutNext (buf); if (IReceived != 0) { float Size = 0; Size = HUD().Font().pFontStat->GetSize(); HUD().Font().pFontStat->SetSize(Size*2); HUD().Font().pFontStat->SetColor (0xffff0000); HUD().Font().pFontStat->OutNext ("Input : [%3.2f]", ICoincidenced/IReceived * 100.0f); HUD().Font().pFontStat->SetSize(Size); }; }; #endif }
void CCar::OnHUDDraw (CCustomHUD* /**hud*/) { #ifdef DEBUG Fvector velocity; m_pPhysicsShell->get_LinearVel(velocity); UI().Font().pFontStat->SetColor (0xffffffff); UI().Font().pFontStat->OutSet (120,530); UI().Font().pFontStat->OutNext ("Position: [%3.2f, %3.2f, %3.2f]",VPUSH(Position())); UI().Font().pFontStat->OutNext ("Velocity: [%3.2f]",velocity.magnitude()); #endif }
void sysRfidgetList() { #ifdef VSIMU VPUSH(NIL); #endif #ifdef VREAL int n=0; n=check_rfid_n(); if (n<=0) { VPUSH(NIL); return; } int i; for(i=0;i<n;i++) { VPUSH(PNTTOVAL(VMALLOCSTR(get_nth_rfid(i),8))); } VPUSH(NIL); while(n--) VMKTAB(2); #endif }
u32 CRestrictedObject::accessible_nearest (const Fvector &position, Fvector &result) const { START_PROFILE("Restricted Object/Accessible Nearest"); VERIFY2 ( !accessible(position), make_string( "[%s] [%f][%f][%f]", object().cName().c_str(), VPUSH(position) ) ); return (Level().space_restriction_manager().accessible_nearest(object().ID(),position,result)); STOP_PROFILE; }
const Fmatrix CScriptEntity::GetUpdatedMatrix(shared_str caBoneName, const Fvector &tPositionOffset, const Fvector &tAngleOffset) { Fmatrix l_tMatrix; l_tMatrix.setHPB(VPUSH(tAngleOffset)); l_tMatrix.c = tPositionOffset; if (xr_strlen(caBoneName)) { CBoneInstance & l_tBoneInstance = smart_cast<IKinematics*>(object().Visual())->LL_GetBoneInstance(smart_cast<IKinematics*>(object().Visual())->LL_BoneID(caBoneName)); l_tMatrix.mulA_43 (l_tBoneInstance.mTransform); l_tMatrix.mulA_43 (object().XFORM()); } return (l_tMatrix); }
void netScan_(struct rt2501_scan_result *scan_result, void *userparam) { char buf[256]; sprintf(buf,">>> %s %d %d %d %d\n",scan_result->ssid,scan_result->rssi,scan_result->channel,scan_result->rateset,scan_result->encryption); consolestr((UBYTE*)buf); VPUSH(PNTTOVAL(VMALLOCSTR(scan_result->ssid,strlen(scan_result->ssid)))); VPUSH(PNTTOVAL(VMALLOCSTR((char*)scan_result->mac,6))); VPUSH(PNTTOVAL(VMALLOCSTR((char*)scan_result->bssid,6))); VPUSH(INTTOVAL(scan_result->rssi)); VPUSH(INTTOVAL(scan_result->channel)); VPUSH(INTTOVAL(scan_result->rateset)); VPUSH(INTTOVAL(scan_result->encryption)); VMKTAB(7); nscan++; }
char *loaderInitRec(char *src) { int l,i; l=loaderGetInt(src); src+=4; if (l==-1) { // printf("nil\n",l>>1); VPUSH(NIL); } else if (l&1) { l>>=1; if (l&1) { l>>=1; // printf("tuple %d\n",l); for(i=0;i<l;i++) src=loaderInitRec(src); VMKTAB(l); }
void CDetailPathManager::build_path(const xr_vector<u32> &level_path, u32 intermediate_index) { if (valid(m_start_position) && valid(m_dest_position)) { switch (m_path_type) { case eDetailPathTypeSmooth : { build_smooth_path(level_path,intermediate_index); break; } case eDetailPathTypeSmoothDodge : { build_smooth_path(level_path,intermediate_index); break; } case eDetailPathTypeSmoothCriteria : { build_smooth_path(level_path,intermediate_index); break; } default : NODEFAULT; } if (failed()) { Msg ("! DetailPathManager has failed : from [%f,%f,%f] to [%f,%f,%f]", VPUSH(ai().level_graph().vertex_position(level_path.front())), VPUSH(ai().level_graph().vertex_position(level_path.back()))); #ifdef DEBUG Msg ("! DetailPathManager has failed for object %s : from [%f,%f,%f] to [%f,%f,%f]", m_restricted_object ? *m_restricted_object->object().cName() : "unknown", VPUSH(ai().level_graph().vertex_position(level_path.front())), VPUSH(ai().level_graph().vertex_position(level_path.back()))); Msg ("List of available velocities :"); xr_vector<STravelParamsIndex>::const_iterator I = m_start_params.begin(); xr_vector<STravelParamsIndex>::const_iterator E = m_start_params.end(); for ( ; I != E; ++I) Msg ("[%d] : [%f][%f]",(*I).index,(*I).linear_velocity,(*I).angular_velocity); // for (;;) // build_smooth_path(level_path,intermediate_index); #endif } if (valid()) { m_actuality = true; m_current_travel_point = 0; m_time_path_built = Device.dwTimeGlobal; } } }
bool verify_invalid_links (const CLevelGraph &graph) { bool result = true; CLevelGraph::const_vertex_iterator I = graph.begin(); CLevelGraph::const_vertex_iterator E = graph.end(); for ( ; I != E; ++I) { u32 vertex_id = graph.vertex_id(I); CLevelGraph::const_iterator i,e; graph.begin (I,i,e); for ( ; i != e; ++i) { u32 link_vertex_id = graph.value(I,i); if (!graph.valid_vertex_id(link_vertex_id)) continue; if (vertex_id == link_vertex_id) { Msg ("Vertex [%d][%f][%f][%f] has link to itself",vertex_id,VPUSH(graph.vertex_position(I))); result = false; continue; } } }; return (result); }
float CGameGraphBuilder::path_distance (const u32 &game_vertex_id0, const u32 &game_vertex_id1) { // return (graph().vertex(game_vertex_id0)->data().level_point().distance_to(graph().vertex(game_vertex_id1)->data().level_point())); VERIFY (m_graph_engine); graph_type::CVertex &vertex0 = *graph().vertex(game_vertex_id0); graph_type::CVertex &vertex1 = *graph().vertex(game_vertex_id1); typedef GraphEngineSpace::CStraightLineParams CStraightLineParams; CStraightLineParams parameters(vertex0.data().level_point(),vertex1.data().level_point()); float pure_distance = vertex0.data().level_point().distance_to_xz(vertex1.data().level_point()); // float pure_distance = vertex0.data().level_point().distance_to(vertex1.data().level_point()); VERIFY (pure_distance < parameters.max_range); u32 level_vertex_id = level_graph().check_position_in_direction(vertex0.data().level_vertex_id(),vertex0.data().level_point(),vertex1.data().level_point()); if (level_graph().valid_vertex_id(level_vertex_id)) return (pure_distance); bool successfull = m_graph_engine->search( level_graph(), vertex0.data().level_vertex_id(), vertex1.data().level_vertex_id(), &m_path, parameters ); if (successfull) return (parameters.m_distance); Msg ("Cannot build path from [%d] to [%d]",game_vertex_id0,game_vertex_id1); Msg ("Cannot build path from [%f][%f][%f] to [%f][%f][%f]",VPUSH(vertex0.data().level_point()),VPUSH(vertex1.data().level_point())); R_ASSERT2 (false,"Cannot build path, check AI map"); return (flt_max); }
void sysItoa(int v) { char res[16]; int ires=0; if (v==0) { res[ires++]='0'; } else { int start=1; int imul=0; if (v<0) { v=-v; res[ires++]='-'; } while(imul<10) { int k=0; while(v>=itoarsc[imul]) { k++; v-=itoarsc[imul]; } if ((k)||(!start)) { start=0; res[ires++]='0'+k; } imul++; } } VPUSH(PNTTOVAL(VMALLOCSTR(res,ires))); }
void sysCtoa(int c) { unsigned char res[1]; res[0]=c; VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,1))); }
/** Gère un evt read sur une socket */ int tcpEventRead(int fd) { /* soit une donnée à lire, soit un accept, soit un close */ /* accept si on l'attend, close si on lit 0 data, read sinon */ int idx = tcpbysock(fd); if (idx < 0) { // TODO gérer l'erreur return 0; } if (tcp_listen[idx]) { // accept struct sockaddr_in cor; int ns; int sizecor; int ni,ip,port; char buf[16]; tcp_listen[idx] = 0; sizecor=sizeof(cor); ns=accept(fd,(struct sockaddr*)&cor,&sizecor); if (ns==-1) return 1; ni=tcpgetfree(); if (ni<0) { close(ns); return 1; } ip=cor.sin_addr.s_addr; port=ntohs(cor.sin_port); tcp_sock[ni]=ns; my_printf(LOG_SIMUNET, "Sockets : accept Tcp from %x:%d (socket=%d)\n",ip,port,ns); VPUSH(INTTOVAL(ni)); VPUSH(INTTOVAL(2)); sprintf(buf,"%d",idx); VPUSH(PNTTOVAL(VMALLOCSTR(buf,strlen(buf)))); VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP)); if (VSTACKGET(0)!=NIL) interpGo(); else { VPULL();VPULL();VPULL();} VPULL(); return 1; } // donnée ou close else { char buf[2048]; int res; if (!tcp_enable[idx]) { // Sleep(10); // recv(sock,buf,0,0); // printf("disabled\n"); return 1; } my_printf(LOG_SIMUNET, "Sockets : Read event on %d\n",fd); res=recv(fd,buf,2048,0); helper_write_buffer(buf, res); VPUSH(INTTOVAL(idx)); if (res>0) { VPUSH(INTTOVAL(1)); VPUSH(PNTTOVAL(VMALLOCSTR(buf,res))); } else { VPUSH(INTTOVAL(-1)); VPUSH(NIL); } VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP)); if (VSTACKGET(0)!=NIL) interpGo(); else { VPULL();VPULL();VPULL();} VPULL(); return 1; } }
bool CScriptEntity::bfAssignMovement(CScriptEntityAction *tpEntityAction) { CScriptMovementAction &l_tMovementAction = tpEntityAction->m_tMovementAction; if (l_tMovementAction.m_bCompleted) return (false); CEntityAlive *entity_alive = smart_cast<CEntityAlive*>(this); if (entity_alive && !entity_alive->g_Alive()) { l_tMovementAction.m_bCompleted = true; return (false); } if (!m_monster) { ai().script_engine().script_log(eLuaMessageTypeError,"Cannot assign a movement action not to a monster!"); return (true); } switch (l_tMovementAction.m_tGoalType) { case CScriptMovementAction::eGoalTypeObject : { CGameObject *l_tpGameObject = smart_cast<CGameObject*>(l_tMovementAction.m_tpObjectToGo); #ifdef DEBUG THROW2 (l_tpGameObject,"eGoalTypeObject specified, but no object passed!"); #else R_ASSERT(l_tpGameObject); #endif m_monster->movement().set_path_type(MovementManager::ePathTypeLevelPath); // Msg ("%6d Object %s, position [%f][%f][%f]",Device.dwTimeGlobal,*l_tpGameObject->cName(),VPUSH(l_tpGameObject->Position())); m_monster->movement().detail().set_dest_position(l_tpGameObject->Position()); m_monster->movement().set_level_dest_vertex(l_tpGameObject->ai_location().level_vertex_id()); break; } case CScriptMovementAction::eGoalTypePatrolPath : { m_monster->movement().set_path_type (MovementManager::ePathTypePatrolPath); m_monster->movement().patrol().set_path (l_tMovementAction.m_path,l_tMovementAction.m_path_name); m_monster->movement().patrol().set_start_type (l_tMovementAction.m_tPatrolPathStart); m_monster->movement().patrol().set_route_type (l_tMovementAction.m_tPatrolPathStop); m_monster->movement().patrol().set_random (l_tMovementAction.m_bRandom); if (l_tMovementAction.m_previous_patrol_point != u32(-1)) { m_monster->movement().patrol().set_previous_point(l_tMovementAction.m_previous_patrol_point); } break; } case CScriptMovementAction::eGoalTypePathPosition : { m_monster->movement().set_path_type(MovementManager::ePathTypeLevelPath); m_monster->movement().detail().set_dest_position(l_tMovementAction.m_tDestinationPosition); u32 vertex_id; vertex_id = ai().level_graph().vertex(object().ai_location().level_vertex_id(),l_tMovementAction.m_tDestinationPosition); if (!ai().level_graph().valid_vertex_id(vertex_id)) vertex_id = ai().level_graph().check_position_in_direction(object().ai_location().level_vertex_id(),object().Position(),l_tMovementAction.m_tDestinationPosition); #ifdef DEBUG if (!ai().level_graph().valid_vertex_id(vertex_id)) { string256 S; sprintf_s (S,"Cannot find corresponding level vertex for the specified position [%f][%f][%f] for monster %s",VPUSH(l_tMovementAction.m_tDestinationPosition),*m_monster->cName()); THROW2 (ai().level_graph().valid_vertex_id(vertex_id),S); } #endif m_monster->movement().level_path().set_dest_vertex(vertex_id); break; } case CScriptMovementAction::eGoalTypePathNodePosition : { VERIFY(ai().level_graph().valid_vertex_id(l_tMovementAction.m_tNodeID)); m_monster->movement().set_path_type (MovementManager::ePathTypeLevelPath); m_monster->movement().detail().set_dest_position (l_tMovementAction.m_tDestinationPosition); m_monster->movement().level_path().set_dest_vertex (l_tMovementAction.m_tNodeID); break; } case CScriptMovementAction::eGoalTypeNoPathPosition : { m_monster->movement().set_path_type(MovementManager::ePathTypeLevelPath); if (m_monster->movement().detail().path().empty() || (m_monster->movement().detail().path()[m_monster->movement().detail().path().size() - 1].position.distance_to(l_tMovementAction.m_tDestinationPosition) > .1f)) { m_monster->movement().detail().m_path.resize(2); m_monster->movement().detail().m_path[0].position = object().Position(); m_monster->movement().detail().m_path[1].position = l_tMovementAction.m_tDestinationPosition; m_monster->movement().detail().m_current_travel_point = 0; } if (m_monster->movement().detail().m_path[1].position.similar(object().Position(),.2f)) l_tMovementAction.m_bCompleted = true; break; } default : { m_monster->movement().set_desirable_speed(0.f); return (l_tMovementAction.m_bCompleted = true); } } if (m_monster->movement().actual_all() && m_monster->movement().path_completed()) l_tMovementAction.m_bCompleted = true; return (!l_tMovementAction.m_bCompleted); }
void CLevelGraph::draw_nodes () { CGameObject* O = smart_cast<CGameObject*> (Level().CurrentEntity()); Fvector POSITION = O->Position(); POSITION.y += 0.5f; // display Fvector P = POSITION; // CPosition Local; // vertex_position (Local,P); u32 ID = O->ai_location().level_vertex_id(); CGameFont* F = UI().Font().pFontDI; F->SetHeightI (.02f); F->OutI (0.f,0.5f,"%f,%f,%f",VPUSH(P)); // float x,z; // unpack_xz (Local,x,z); // F->Out (0.f,0.55f,"%3d,%4d,%3d -> %d", iFloor(x),iFloor(Local.y()),iFloor(z),u32(ID)); svector<u32,128> linked; { const_iterator i,e; begin (ID,i,e); for(; i != e; ++i) linked.push_back(value(ID,i)); } // render float sc = header().cell_size()/16; float st = 0.98f*header().cell_size()/2; float tt = 0.01f; Fvector DUP; DUP.set(0,1,0); //RCache.set_Shader (sh_debug); DRender->SetShader(sh_debug); F->SetColor (color_rgba(255,255,255,255)); ////////////////////////////////////////////////////////////////////////// Fvector min_position,max_position; max_position = min_position = Device.vCameraPosition; min_position.sub(30.f); max_position.add(30.f); CLevelGraph::const_vertex_iterator I, E; if (valid_vertex_position(min_position)) I = std::lower_bound(begin(),end(),vertex_position(min_position).xz(),&vertex::predicate2); else I = begin(); if (valid_vertex_position(max_position)) { E = std::upper_bound(begin(),end(),vertex_position(max_position).xz(),&vertex::predicate); if (E != end()) ++E; } else E = end(); ////////////////////////////////////////////////////////////////////////// for ( ; I != E; ++I) { const CLevelGraph::CVertex& N = *I; Fvector PC; PC = vertex_position(N); u32 Nid = vertex_id(I); if (Device.vCameraPosition.distance_to(PC)>30) continue; float sr = header().cell_size(); if (::Render->ViewBase.testSphere_dirty(PC,sr)) { u32 LL = 255; u32 CC = D3DCOLOR_XRGB(0,0,255); u32 CT = D3DCOLOR_XRGB(LL,LL,LL); u32 CH = D3DCOLOR_XRGB(0,128,0); BOOL bHL = FALSE; if (Nid==u32(ID)) { bHL = TRUE; CT = D3DCOLOR_XRGB(0,255,0); } else { for (u32 t=0; t<linked.size(); ++t) { if (linked[t]==Nid) { bHL = TRUE; CT = CH; break; } } } // unpack plane Fplane PL; Fvector vNorm; pvDecompress(vNorm,N.plane()); PL.build (PC,vNorm); // create vertices Fvector v,v1,v2,v3,v4; v.set(PC.x-st,PC.y,PC.z-st); PL.intersectRayPoint(v,DUP,v1); v1.mad(v1,PL.n,tt); // minX,minZ v.set(PC.x+st,PC.y,PC.z-st); PL.intersectRayPoint(v,DUP,v2); v2.mad(v2,PL.n,tt); // maxX,minZ v.set(PC.x+st,PC.y,PC.z+st); PL.intersectRayPoint(v,DUP,v3); v3.mad(v3,PL.n,tt); // maxX,maxZ v.set(PC.x-st,PC.y,PC.z+st); PL.intersectRayPoint(v,DUP,v4); v4.mad(v4,PL.n,tt); // minX,maxZ // render quad DRender->dbg_DrawTRI(Fidentity,v3,v2,v1,CT); DRender->dbg_DrawTRI(Fidentity,v1,v4,v3,CT); //RCache.dbg_DrawTRI (Fidentity,v3,v2,v1,CT); //RCache.dbg_DrawTRI (Fidentity,v1,v4,v3,CT); // render center Level().debug_renderer().draw_aabb (PC,sc,sc,sc,CC); // render id if (bHL) { Fvector T; Fvector4 S; T.set (PC); T.y+=0.3f; Device.mFullTransform.transform (S,T); if (S.z < 0 || S.z < 0) continue; if (S.x < -1.f || S.x > 1.f || S.y<-1.f || S.x>1.f) continue; F->SetHeightI (0.05f/_sqrt(_abs(S.w))); F->SetColor (0xffffffff); F->OutI (S.x,-S.y,"~%d",Nid); } } } }
void ESceneAIMapTool::DenumerateNodes() { u32 cnt=m_Nodes.size(); for (AINodeIt it=m_Nodes.begin(); it!=m_Nodes.end(); it++){ if (!((((u32)(*it)->n1<cnt)||((u32)(*it)->n1==InvalidNode))&& (((u32)(*it)->n2<cnt)||((u32)(*it)->n2==InvalidNode))&& (((u32)(*it)->n3<cnt)||((u32)(*it)->n3==InvalidNode))&& (((u32)(*it)->n4<cnt)||((u32)(*it)->n4==InvalidNode)))){ ELog.Msg(mtError,"Node: has wrong link [%3.2f, %3.2f, %3.2f], {%d,%d,%d,%d}",VPUSH((*it)->Pos),(*it)->n1,(*it)->n2,(*it)->n3,(*it)->n4); (*it)->n1 = 0; (*it)->n2 = 0; (*it)->n3 = 0; (*it)->n4 = 0; continue; } // ,"AINode: Wrong link found."); (*it)->n1 = ((u32)(*it)->n1==InvalidNode)?0:m_Nodes[(u32)(*it)->n1]; (*it)->n2 = ((u32)(*it)->n2==InvalidNode)?0:m_Nodes[(u32)(*it)->n2]; (*it)->n3 = ((u32)(*it)->n3==InvalidNode)?0:m_Nodes[(u32)(*it)->n3]; (*it)->n4 = ((u32)(*it)->n4==InvalidNode)?0:m_Nodes[(u32)(*it)->n4]; /* if (((u32)(*it)->n1<cnt)||((u32)(*it)->n1==InvalidNode)) (*it)->n1 = ((u32)(*it)->n1==InvalidNode)?0:m_Nodes[(u32)(*it)->n1]; else (*it)->n1=0; if (((u32)(*it)->n2<cnt)||((u32)(*it)->n2==InvalidNode)) (*it)->n2 = ((u32)(*it)->n2==InvalidNode)?0:m_Nodes[(u32)(*it)->n2]; else (*it)->n2=0; if (((u32)(*it)->n3<cnt)||((u32)(*it)->n3==InvalidNode)) (*it)->n3 = ((u32)(*it)->n3==InvalidNode)?0:m_Nodes[(u32)(*it)->n3]; else (*it)->n3=0; if (((u32)(*it)->n4<cnt)||((u32)(*it)->n4==InvalidNode)) (*it)->n4 = ((u32)(*it)->n4==InvalidNode)?0:m_Nodes[(u32)(*it)->n4]; else (*it)->n4=0; */ } }