Beispiel #1
0
//-------------------------------------------------------------------------------------
int UDPPacket::recvFromEndPoint(EndPoint & ep, Address* pAddr)
{
	KBE_ASSERT(maxBufferSize() > wpos());

	// 当接收来的大小大于接收缓冲区的时候,recvfrom返回-1
	int len = ep.recvfrom(data() + wpos(), size() - wpos(),
		(u_int16_t*)&pAddr->port, (u_int32_t*)&pAddr->ip);

	if(len > 0)
		wpos(wpos() + len);

	return len;
}
Beispiel #2
0
bool Chunk::unplaceBlock(const BlockInChunk &pos)
{
    unsigned int index = getIndexByPosition(pos);
    if (index >= CHUNK_INDEX_MAX)
    {
        return false;
    }
    Chunk *temp_chunk = nullptr;
    unsigned int temp_index;
    Block *p_block = m_pBlocks + index;
    BlockInWorld wpos(*this, pos);

    if (!findBlock(wpos.getSide(TOP), temp_chunk, temp_index)|| m_pBlocks[index].material == MAT_WATER) hideTile(p_block, TOP);
    else { temp_chunk->showTile(temp_index, BOTTOM); if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) hideTile(p_block, TOP); }
    if (!findBlock(wpos.getSide(BOTTOM), temp_chunk, temp_index)) hideTile(p_block, BOTTOM);
    else { temp_chunk->showTile(temp_index, TOP); if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) hideTile(p_block, BOTTOM); }
    if (!findBlock(wpos.getSide(RIGHT), temp_chunk, temp_index)) hideTile(p_block, RIGHT);
    else { temp_chunk->showTile(temp_index, LEFT); if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) hideTile(p_block, RIGHT); }
    if (!findBlock(wpos.getSide(LEFT), temp_chunk, temp_index)) hideTile(p_block, LEFT);
    else { temp_chunk->showTile(temp_index, RIGHT); if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) hideTile(p_block, LEFT); }
    if (!findBlock(wpos.getSide(BACK), temp_chunk, temp_index)) hideTile(p_block, BACK);
    else { temp_chunk->showTile(temp_index, FRONT); if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) hideTile(p_block, BACK); }
    if (!findBlock(wpos.getSide(FRONT), temp_chunk, temp_index)) hideTile(p_block, FRONT);
    else { temp_chunk->showTile(temp_index, BACK); if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) hideTile(p_block, FRONT); }

    removeBlock(wpos.bx, wpos.by, wpos.bz);

    m_NeedToRender[0] = RENDER_NEED;
    m_NeedToRender[1] = RENDER_NEED;

    return true;
}
Beispiel #3
0
//-------------------------------------------------------------------------------------
int TCPPacket::recvFromEndPoint(EndPoint & ep, Address* pAddr)
{
	//KBE_ASSERT(MessageHandlers::pMainMessageHandlers != NULL && "Must set up a MainMessageHandlers!\n");
	KBE_ASSERT(maxBufferSize() > wpos());
	int len = ep.recv(data() + wpos(), (int)(size() - wpos()));
	
	if(len > 0) 
	{
		wpos((int)(wpos() + len));

		// 注意:必须在大于0的时候否则DEBUG_MSG将会导致WSAGetLastError返回0从而陷入死循环
		// DEBUG_MSG(fmt::format("TCPPacket::recvFromEndPoint: datasize={}, wpos={}.\n", len, wpos()));
	}

	return len; 
}
Beispiel #4
0
void WaveEventBase::write(int level, Xml& xml, const Pos& offset, bool forcePath) const
{
    if (f.isNull())
        return;
    xml.tag(level++, "event");
    PosLen wpos(*this);
    wpos += offset;
    wpos.write(level, xml, "poslen");
    xml.intTag(level, "frame", _spos); // offset in wave file
    xml.intTag(level, "leftclip", m_leftclip);
    xml.intTag(level, "rightclip", m_rightclip);

    //
    // waves in the project dirctory are stored
    // with relative path name, others with absolute path
    //
    QString path = f.dirPath();

    //if (path.contains(losProject)) {
    if (!forcePath && path.contains(losProject))
    {
        // extract losProject.
        QString newName = f.path().remove(losProject + "/");
        xml.strTag(level, "file", newName);
    }
    else
        xml.strTag(level, "file", f.path());
    xml.etag(--level, "event");
}
Beispiel #5
0
void ZCompressor::Deflate(uint8 level)
{
    if( _iscompressed || (!size()) || level>9 )
        return;

    char *buf;
    buf=new char[size()+8];

    uint32 newsize=size(),oldsize=size();
    reserve(size()+8);

    _compress((void*)buf, &newsize, (void*)contents(),size(),level);

    if(!newsize)
        return;

    resize(newsize);
    rpos(0);
    wpos(0);
    append(buf,newsize);
    delete [] buf;

    _iscompressed=true;

    _real_size=oldsize;
}
Beispiel #6
0
//! Compresses packet in place
void WorldPacket::Compress(z_stream* compressionStream)
{
    Opcodes uncompressedOpcode = GetOpcode();
    if (uncompressedOpcode & COMPRESSED_OPCODE_MASK)
    {
        sLog->outError(LOG_FILTER_NETWORKIO, "Packet with opcode 0x%04X is already compressed!", uncompressedOpcode);
        return;
    }

    Opcodes opcode = Opcodes(uncompressedOpcode | COMPRESSED_OPCODE_MASK);
    uint32 size = wpos();
    uint32 destsize = compressBound(size);

    std::vector<uint8> storage(destsize);

    _compressionStream = compressionStream;
    Compress(static_cast<void*>(&storage[0]), &destsize, static_cast<const void*>(contents()), size);
    if (destsize == 0)
        return;

    clear();
    reserve(destsize + sizeof(uint32));
    *this << uint32(size);
    append(&storage[0], destsize);
    SetOpcode(opcode);

	sLog->outInfo(LOG_FILTER_NETWORKIO, "%s (len %u) successfully compressed to %04X (len %u)", GetOpcodeNameForLogging(uncompressedOpcode, true).c_str(), size, opcode, destsize);
}
Beispiel #7
0
/*================================
 * save_gedcom -- save gedcom file
 *==============================*/
BOOLEAN
save_gedcom (void)
{
    FILE *fp=NULL;
    struct tag_export_feedback efeed;
    STRING srcdir=NULL, fname=0, fullpath=0;

    srcdir = getlloptstr("LLARCHIVES", ".");
    fp = ask_for_output_file(LLWRITETEXT, _(qSoutarc), &fname, &fullpath, srcdir, ".ged");
    if (!fp) {
        strfree(&fname);
        msg_error(_("The database was not saved."));
        return FALSE;
    }
    prefix_file_for_gedcom(fp);

    memset(&efeed, 0, sizeof(efeed));
    efeed.added_rec_fnc = export_saved_rec;

    llwprintf(_("Saving database `%s' in file `%s'."), readpath_file, fullpath);

    /* Display 0 counts */
    clear_rec_counts(0);

    archive_in_file(&efeed, fp);
    fclose(fp);

    wpos(7,0);
    msg_info(_(qSoutfin), readpath_file, fname);
    strfree(&fname);

    return TRUE;
}
Beispiel #8
0
//-------------------------------------------------------------------------------------
int TCPPacket::recvFromEndPoint(EndPoint & ep, Address* pAddr)
{
	//KBE_ASSERT(MessageHandlers::pMainMessageHandlers != NULL && "Must set up a MainMessageHandlers!\n");
	KBE_ASSERT(maxBufferSize() > wpos());
	int len = ep.recv(data() + wpos(), size() - wpos());
	wpos(wpos() + len);
	
	/*
	// 注意:必须在大于0的时候否则DEBUG_MSG将会导致WSAGetLastError返回0从而陷入死循环
	if(len > 0) 
	{
		DEBUG_MSG(boost::format("TCPPacket::recvFromEndPoint: datasize=%1%, wpos=%2%.\n") % len % wpos());
	}
	*/
	return len; 
}
Beispiel #9
0
LuaPacket::LuaPacket(lua_State* L) : ByteBuffer(0), changed_(false)
{
    uint32_t opcode = static_cast<uint32_t>(luaL_checknumber(L, 1));
    ByteBuffer::SetOpcode(opcode);
    rpos(sizeof(uint32_t));
    wpos(sizeof(uint32_t));
}
Beispiel #10
0
/*================================
 * load_gedcom -- have user select gedcom file & import it
 *==============================*/
void
load_gedcom (BOOLEAN picklist)
{
    FILE *fp=NULL;
    struct tag_import_feedback ifeed;
    STRING srcdir=NULL;
    STRING fullpath=0;
    time_t begin = time(NULL);
    time_t beginui = get_uitime();

    srcdir = getlloptstr("InputPath", ".");
    if (!ask_for_gedcom(LLREADTEXT, _(qSwhatgedc), 0, &fullpath, srcdir, ".ged", picklist)
            || !(fp = fopen(fullpath, LLREADBINARY))) {
        strfree(&fullpath);
        return;
    }

    /*
    Note: we read the file in binary mode, so ftell & fseek will work correctly.
    Microsoft's ftell/fseek do not work correctly if the file has simple unix (\n)
    line terminations! -- Perry, 2003-02-11
    */

    memset(&ifeed, 0, sizeof(ifeed));
    ifeed.validating_fnc = import_validating;
    ifeed.validated_rec_fnc = import_validated_rec;
    ifeed.beginning_import_fnc = import_beginning_import;
    ifeed.error_invalid_fnc = import_error_invalid;
    ifeed.error_readonly_fnc = import_readonly;
    ifeed.adding_unused_keys_fnc = import_adding_unused_keys;
    ifeed.added_rec_fnc = import_added_rec;
    ifeed.validation_error_fnc = import_validation_error;
    ifeed.validation_warning_fnc =  import_validation_warning;

    import_from_gedcom_file(&ifeed, fp);

    fclose(fp);
    strfree(&fullpath);


    if (1) {
        INT duration = time(NULL) - begin;
        INT uitime = get_uitime() - beginui;
        ZSTR zt1=approx_time(duration-uitime), zt2=approx_time(uitime);
        /* TRANSLATORS: how long Import ran, and how much of that was UI delay */
        ZSTR zout = zs_newf(_("Import time %s (ui %s)\n")
                            , zs_str(zt1), zs_str(zt2));
        wfield(8,0, zs_str(zout));
        zs_free(&zt1);
        zs_free(&zt2);
        zs_free(&zout);
    }

    /* position cursor further down stdout so check_stdout
    doesn't overwrite our messages from above */
    wpos(15,0);
}
Beispiel #11
0
//-------------------------------------------------------------------------------------
int UDPPacket::recvFromEndPoint(EndPoint & ep, Address* pAddr)
{
	int len = ep.recvfrom(data(), PACKET_MAX_SIZE_UDP,
		(u_int16_t*)&pAddr->port, (u_int32_t*)&pAddr->ip);

	KBE_ASSERT(rpos() == 0);
	wpos(len);
	return len;
}
Beispiel #12
0
//-------------------------------------------------------------------------------------
int TCPPacket::recvFromEndPoint(EndPoint & ep, Address* pAddr)
{
	//KBE_ASSERT(MessageHandlers::pMainMessageHandlers != NULL && "Must set up a MainMessageHandlers!\n");
	int len = ep.recv(data(), PACKET_MAX_SIZE_TCP * 4);
	KBE_ASSERT(rpos() == 0);
	wpos(len);

	// DEBUG_MSG("TCPPacket::recvFromEndPoint: datasize=%d, wpos=%d.\n", len, wpos());
	return len;
}
Beispiel #13
0
//------------------------------------------------------------------------
//chr safe to remove?
bool CGunTurret::IsTargetCloaked(IActor *pActor) const
{
	// cloak check
	if(m_turretparams.find_cloaked)
		return false;

	bool cloaked = false;

	// if destinationId assigned, target can always be found
	if(m_destinationId && pActor->GetEntityId() == m_destinationId)
		return false;

	if(cloaked && m_turretparams.light_fov != 0.f)
	{
		// if cloaked, target can only be found with searchlight
		// check if target inside light cone
		const Matrix34 &weaponTM = GetEntity()->GetSlotWorldTM(eIGS_ThirdPerson);
		Vec3 wpos(weaponTM.GetTranslation());
		Vec3 wdir(weaponTM.GetColumn1());
		Vec3 tpos(GetTargetPos(pActor->GetEntity()));

		float epsilon = 0.8f;
		Quat rot = Quat::CreateRotationAA(epsilon*0.5f*DEG2RAD(m_turretparams.light_fov), weaponTM.GetColumn2());
		Vec3 a = wpos + m_turretparams.mg_range*(wdir*rot);
		Vec3 b = wpos + m_turretparams.mg_range*(wdir*rot.GetInverted());
		bool inside = Overlap::PointInTriangle(tpos, wpos, a, b, weaponTM.GetColumn2());

		if(inside)
		{
			rot = Quat::CreateRotationAA(0.5f*DEG2RAD(m_turretparams.light_fov), weaponTM.GetColumn0());
			a = wpos + m_turretparams.mg_range*(wdir*rot);
			b = wpos + m_turretparams.mg_range*(wdir*rot.GetInverted());
			inside = Overlap::PointInTriangle(tpos, wpos, a, b, weaponTM.GetColumn0());
		}

		cloaked = !inside;

		if(g_pGameCVars->i_debug_turrets == eGTD_Search)
		{
			IRenderAuxGeom *pGeom = gEnv->pRenderer->GetIRenderAuxGeom();
			pGeom->SetRenderFlags(e_Def3DPublicRenderflags);
			float color[] = {1,1,1,1};
			Vec3 points[] = {wpos, a, b};
			pGeom->DrawPolyline(points, 3, true, ColorB(0,255,0,255));

			if(inside)
				gEnv->pRenderer->Draw2dLabel(200,200,1.4f,color,false,"target inside cone");
		}
	}

	return cloaked;
}
Beispiel #14
0
bool Chunk::placeBlock(const BlockInChunk &pos, char mat)
{
    unsigned int index = addBlock(pos.bx, pos.by, pos.bz, mat);
    if (index >= CHUNK_INDEX_MAX)
    {
        return false;
    }
    Chunk *temp_chunk = nullptr;
    unsigned int temp_index;
    Block *p_block = m_pBlocks + index;
    BlockInWorld wpos(*this, pos);

    if (m_pBlocks[index].material == MAT_WATER)
    {
        if (!findBlock(wpos.getSide(TOP), temp_chunk, temp_index)) showTile(p_block, TOP);
        else if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) temp_chunk->hideTile(temp_index, BOTTOM);
        if (!findBlock(wpos.getSide(BOTTOM), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, BOTTOM); }
        else if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) temp_chunk->hideTile(temp_index, TOP);
        if (!findBlock(wpos.getSide(RIGHT), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, RIGHT); }
        else if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) temp_chunk->hideTile(temp_index, LEFT);
        if (!findBlock(wpos.getSide(LEFT), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, LEFT); }
        else if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) temp_chunk->hideTile(temp_index, RIGHT);
        if (!findBlock(wpos.getSide(BACK), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, BACK); }
        else if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) temp_chunk->hideTile(temp_index, FRONT);
        if (!findBlock(wpos.getSide(FRONT), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, FRONT); }
        else if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) temp_chunk->hideTile(temp_index, BACK);
    }
    else
    {
        if (!findBlock(wpos.getSide(TOP), temp_chunk, temp_index)) showTile(p_block, TOP);
        else { temp_chunk->hideTile(temp_index, BOTTOM); if (temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) showTile(p_block, TOP); }
        if (!findBlock(wpos.getSide(BOTTOM), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, BOTTOM); }
        else { if (temp_chunk && temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) showTile(p_block, BOTTOM); else temp_chunk->hideTile(temp_index, TOP); }
        if (!findBlock(wpos.getSide(RIGHT), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, RIGHT); }
        else {temp_chunk->hideTile(temp_index, LEFT); if (temp_chunk && temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) showTile(p_block, RIGHT); }
        if (!findBlock(wpos.getSide(LEFT), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, LEFT); }
        else { temp_chunk->hideTile(temp_index, RIGHT); if (temp_chunk && temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) showTile(p_block, LEFT); }
        if (!findBlock(wpos.getSide(BACK), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, BACK); }
        else { temp_chunk->hideTile(temp_index, FRONT); if (temp_chunk && temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) showTile(p_block, BACK); }
        if (!findBlock(wpos.getSide(FRONT), temp_chunk, temp_index)) { if (temp_chunk) showTile(p_block, FRONT); }
        else { temp_chunk->hideTile(temp_index, BACK); if (temp_chunk && temp_chunk->m_pBlocks[temp_index].material == MAT_WATER) showTile(p_block, FRONT); }
    }

    m_NeedToRender[0] = RENDER_NEED;
    m_NeedToRender[1] = RENDER_NEED;

    return true;
}
Beispiel #15
0
void MemoryStream::print_storage()
{
	FString fbuffer;
	uint32 trpos = rpos_;

	DEBUG_MSG("MemoryStream::print_storage(): STORAGE_SIZE: %lu, rpos=%lu.", (unsigned long)wpos(), (unsigned long)rpos());

	for (uint32 i = rpos(); i < wpos(); ++i)
	{
		fbuffer.AppendInt((int)read<uint8>(i));
		fbuffer += TEXT(" ");
	}

	DEBUG_MSG("%s", *fbuffer);

	rpos_ = trpos;
}
Beispiel #16
0
void WorldPacket::compress(Opcodes opcode)
{
    if (opcode == UNKNOWN_OPCODE)
        return;

    Opcodes uncompressedOpcode = GetOpcode();
    uint32 size = wpos();
    uint32 destsize = compressBound(size);

    std::vector<uint8> storage(destsize);

    _compress(static_cast<void*>(&storage[0]), &destsize, static_cast<const void*>(contents()), size);
    if (destsize == 0)
        return;

    clear();
    reserve(destsize + sizeof(uint32));
    *this << uint32(size);
    append(&storage[0], destsize);
    SetOpcode(opcode);

    sLog->outStaticDebug("Successfully compressed opcode %u (len %u) to %u (len %u)",
        uncompressedOpcode, size, opcode, destsize);
}
Beispiel #17
0
void WorldPacket::compress(uint32 opcode)
{
    if (opcode == OPCODE_NOT_FOUND)  // this just doesn't look right, atm not using that define opcode way.
        return;

    uint32 uncompressedOpcode = GetOpcode();
    uint32 size = wpos();
    uint32 destsize = compressBound(size);

    std::vector<uint8> storage(destsize);

    _compress(static_cast<void*>(&storage[0]), &destsize, static_cast<const void*>(contents()), size);
    if (destsize == 0)
        return;

    clear();
    reserve(destsize + sizeof(uint32));
    *this << uint32(size);
    append(&storage[0], destsize);
    SetOpcode(opcode);

    sLog->outStaticDebug("Successfully compressed opcode %u (len %u) to %u (len %u)",
        uncompressedOpcode, size, opcode, destsize);
}
Beispiel #18
0
void ZCompressor::Inflate(void)
{
    if( (!_iscompressed) || (!_real_size) || (!size()))
        return;

    uLongf origsize=_real_size;
    int8 result;
    uint8 *target=new uint8[_real_size];
    wpos(0);
    rpos(0);
    result = uncompress(target, &origsize, (uint8*)contents(), size());
    if( result!=Z_OK || origsize!=_real_size)
    {
        logerror("ZCompressor: Inflate error! result=%d cursize=%u origsize=%u realsize=%u\n",result,size(),origsize,_real_size);
        delete [] target;
        return;
    }
    clear();
    append(target,origsize);
    delete [] target;
    _real_size=0;
    _iscompressed=false;

}
Beispiel #19
0
//-------------------------------------------------------------------------------------
TCPPacket::TCPPacket(MessageID msgID, size_t res):
Packet(msgID, true, res)
{
	data_resize(maxBufferSize());
	wpos(0);
}
void CGuiHandler::DrawMapStuff(void)
{
	if(activeMousePress){
		int cc=-1;
		int button=SDL_BUTTON_LEFT;
		if(inCommand!=-1){
			cc=inCommand;
		} else {
			if(mouse->buttons[SDL_BUTTON_RIGHT].pressed && mouse->activeReceiver==this){
				cc=defaultCmdMemory;//GetDefaultCommand(mouse->lastx,mouse->lasty);
				button=SDL_BUTTON_RIGHT;
			}
		}

		if(cc>=0 && cc<commands.size()){
			switch(commands[cc].type){
			case CMDTYPE_ICON_FRONT:
				if(mouse->buttons[button].movement>30){
					if(commands[cc].params.size()>0)
						if(commands[cc].params.size()>1)
							DrawFront(button,atoi(commands[cc].params[0].c_str()),atof(commands[cc].params[1].c_str()));
						else
							DrawFront(button,atoi(commands[cc].params[0].c_str()),0);
					else
						DrawFront(button,1000,0);
				}
				break;
			case CMDTYPE_ICON_UNIT_OR_AREA:
			case CMDTYPE_ICON_UNIT_FEATURE_OR_AREA:
			case CMDTYPE_ICON_AREA:{
				float maxRadius=100000;
				if(commands[cc].params.size()==1)
					maxRadius=atof(commands[cc].params[0].c_str());
				if(mouse->buttons[button].movement>4){
					float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*9000);
					if(dist<0){
						break;
					}
					float3 pos=mouse->buttons[button].camPos+mouse->buttons[button].dir*dist;
					dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
					if(dist<0){
						break;
					}
					float3 pos2=camera->pos+mouse->dir*dist;
					DrawArea(pos,min(maxRadius,pos.distance2D(pos2)));
				}
				break;}
			default:
				break;
			}
		}
	}
	//draw buildings we are about to build
	if(inCommand>=0 && inCommand<commands.size() && commands[guihandler->inCommand].type==CMDTYPE_ICON_BUILDING){
		float dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
		if(dist>0){
			string s=commands[guihandler->inCommand].name;
			UnitDef *unitdef = unitDefHandler->GetUnitByName(s);

			if(unitdef){
				float3 pos=camera->pos+mouse->dir*dist;
				std::vector<float3> buildPos;
				if(keys[SDLK_LSHIFT] && mouse->buttons[SDL_BUTTON_LEFT].pressed){
					float dist=ground->LineGroundCol(mouse->buttons[SDL_BUTTON_LEFT].camPos,mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*9000);
					float3 pos2=mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*dist;
					buildPos=GetBuildPos(pos2,pos,unitdef);
				} else {
					buildPos=GetBuildPos(pos,pos,unitdef);
				}

				for(std::vector<float3>::iterator bpi=buildPos.begin();bpi!=buildPos.end();++bpi){
					float3 pos=*bpi;
					if(uh->ShowUnitBuildSquare(pos,unitdef))
						glColor4f(0.7,1,1,0.4);
					else
						glColor4f(1,0.5,0.5,0.4);

					unitDrawer->SetupForGhostDrawing ();
					S3DOModel* model=modelParser->Load3DO((unitdef->model.modelpath).c_str() ,1, gu->myTeam);
					glPushMatrix();
					glTranslatef3(pos);
					//glCallList(model->displist);
					model->DrawStatic();
					unitDrawer->CleanUpGhostDrawing();
					glPopMatrix();
					if(unitdef->weapons.size()>0){	//draw range
						glDisable(GL_TEXTURE_2D);
						glColor4f(1,0.3,0.3,0.7);
						glBegin(GL_LINE_STRIP);
						for(int a=0;a<=40;++a){
							float3 wpos(cos(a*2*PI/40)*unitdef->weapons[0].def->range,0,sin(a*2*PI/40)*unitdef->weapons[0].def->range);
							wpos+=pos;
							float dh=ground->GetHeight(wpos.x,wpos.z)-pos.y;
							float modRange=unitdef->weapons[0].def->range-dh*unitdef->weapons[0].def->heightmod;
							wpos=float3(cos(a*2*PI/40)*(modRange),0,sin(a*2*PI/40)*(modRange));
							wpos+=pos;
							wpos.y=ground->GetHeight(wpos.x,wpos.z)+8;
							glVertexf3(wpos);
						}
						glEnd();
					}
					if(unitdef->extractRange>0){	//draw range
						glDisable(GL_TEXTURE_2D);
						glColor4f(1,0.3,0.3,0.7);
						glBegin(GL_LINE_STRIP);
						for(int a=0;a<=40;++a){
							float3 wpos(cos(a*2*PI/40)*unitdef->extractRange,0,sin(a*2*PI/40)*unitdef->extractRange);
							wpos+=pos;
							wpos.y=ground->GetHeight(wpos.x,wpos.z)+8;
							glVertexf3(wpos);
						}
						glEnd();
					}
				}
			}
		}
	}

	if(keys[SDLK_LSHIFT]){
		CUnit* unit=0;
		float dist2=helper->GuiTraceRay(camera->pos,mouse->dir,9000,unit,20,false);
		if(unit && ((unit->losStatus[gu->myAllyTeam] & LOS_INLOS) || gu->spectating)){		//draw weapon range
			if(unit->maxRange>0){
				glDisable(GL_TEXTURE_2D);
				glColor4f(1,0.3,0.3,0.7);
				glBegin(GL_LINE_STRIP);
				float h=unit->pos.y;
				for(int a=0;a<=40;++a){
					float3 pos(cos(a*2*PI/40)*unit->maxRange,0,sin(a*2*PI/40)*unit->maxRange);
					pos+=unit->pos;
					float dh=ground->GetHeight(pos.x,pos.z)-h;
					pos=float3(cos(a*2*PI/40)*(unit->maxRange-dh*unit->weapons.front()->heightMod),0,sin(a*2*PI/40)*(unit->maxRange-dh*unit->weapons.front()->heightMod));
					pos+=unit->pos;
					pos.y=ground->GetHeight(pos.x,pos.z)+8;
					glVertexf3(pos);
				}
				glEnd();
			}
			if(unit->unitDef->decloakDistance>0){			//draw decloak distance
				glDisable(GL_TEXTURE_2D);
				glColor4f(0.3,0.3,1,0.7);
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=40;++a){
					float3 pos(cos(a*2*PI/40)*unit->unitDef->decloakDistance,0,sin(a*2*PI/40)*unit->unitDef->decloakDistance);
					pos+=unit->pos;
					pos.y=ground->GetHeight(pos.x,pos.z)+8;
					glVertexf3(pos);
				}
				glEnd();
			}
			if(unit->unitDef->kamikazeDist>0){			//draw self destruct and damage distance
				glDisable(GL_TEXTURE_2D);
				glColor4f(0.8,0.8,0.1,0.7);
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=40;++a){
					float3 pos(cos(a*2*PI/40)*unit->unitDef->kamikazeDist,0,sin(a*2*PI/40)*unit->unitDef->kamikazeDist);
					pos+=unit->pos;
					pos.y=ground->GetHeight(pos.x,pos.z)+8;
					glVertexf3(pos);
				}
				glEnd();
				if(!unit->unitDef->selfDExplosion.empty()){
					glColor4f(0.8,0.1,0.1,0.7);
					WeaponDef* wd=weaponDefHandler->GetWeapon(unit->unitDef->selfDExplosion);

					glBegin(GL_LINE_STRIP);
					for(int a=0;a<=40;++a){
						float3 pos(cos(a*2*PI/40)*wd->areaOfEffect,0,sin(a*2*PI/40)*wd->areaOfEffect);
						pos+=unit->pos;
						pos.y=ground->GetHeight(pos.x,pos.z)+8;
						glVertexf3(pos);
					}
					glEnd();
				}
			}
		}
	}
	//draw range circles if attack orders are imminent
	int defcmd=GetDefaultCommand(mouse->lastx,mouse->lasty);
	if((inCommand>0 && inCommand<commands.size() && commands[inCommand].id==CMD_ATTACK) || (inCommand==-1 && defcmd>0 && commands[defcmd].id==CMD_ATTACK)){
		for(std::set<CUnit*>::iterator si=selectedUnits.selectedUnits.begin();si!=selectedUnits.selectedUnits.end();++si){
			CUnit* unit=*si;
			if(unit->maxRange>0 && ((unit->losStatus[gu->myAllyTeam] & LOS_INLOS) || gu->spectating)){
				glDisable(GL_TEXTURE_2D);
				glColor4f(1,0.3,0.3,0.7);
				glBegin(GL_LINE_STRIP);
				float h=unit->pos.y;
				for(int a=0;a<=40;++a){
					float3 pos(cos(a*2*PI/40)*unit->maxRange,0,sin(a*2*PI/40)*unit->maxRange);
					pos+=unit->pos;
					float dh=ground->GetHeight(pos.x,pos.z)-h;
					pos=float3(cos(a*2*PI/40)*(unit->maxRange-dh*unit->weapons.front()->heightMod),0,sin(a*2*PI/40)*(unit->maxRange-dh*unit->weapons.front()->heightMod));
					pos+=unit->pos;
					pos.y=ground->GetHeight(pos.x,pos.z)+8;
					glVertexf3(pos);
				}
				glEnd();
			}
		}
	}
}
Beispiel #21
0
static float
calc_rank_or(float *w, tsvector * t, QUERYTYPE * q)
{
	WordEntry  *entry;
	WordEntryPos *post;
	int4		dimt,
				j,
				i;
	float		res = 0.0;
	ITEM	  **item;
	int			size = q->size;

	*(uint16 *) POSNULL = lengthof(POSNULL) - 1;
	item = SortAndUniqItems(GETOPERAND(q), GETQUERY(q), &size);

	for (i = 0; i < size; i++)
	{
		float		resj,
					wjm;
		int4		jm;

		entry = find_wordentry(t, q, item[i]);
		if (!entry)
			continue;

		if (entry->haspos)
		{
			dimt = POSDATALEN(t, entry);
			post = POSDATAPTR(t, entry);
		}
		else
		{
			dimt = *(uint16 *) POSNULL;
			post = POSNULL + 1;
		}

		resj = 0.0;
		wjm = -1.0;
		jm = 0;
		for (j = 0; j < dimt; j++)
		{
			resj = resj + wpos(post[j]) / ((j + 1) * (j + 1));
			if (wpos(post[j]) > wjm)
			{
				wjm = wpos(post[j]);
				jm = j;
			}
		}
/*
		limit (sum(i/i^2),i->inf) = pi^2/6
		resj = sum(wi/i^2),i=1,noccurence,
		wi - should be sorted desc,
		don't sort for now, just choose maximum weight. This should be corrected
		Oleg Bartunov
*/
		res = res + (wjm + resj - wjm / ((jm + 1) * (jm + 1))) / 1.64493406685;
	}
	if (size > 0)
		res = res / size;
	pfree(item);
	return res;
}
Beispiel #22
0
static float
calc_rank_and(float *w, tsvector * t, QUERYTYPE * q)
{
	uint16	  **pos;
	int			i,
				k,
				l,
				p;
	WordEntry  *entry;
	WordEntryPos *post,
			   *ct;
	int4		dimt,
				lenct,
				dist;
	float		res = -1.0;
	ITEM	  **item;
	int			size = q->size;

	item = SortAndUniqItems(GETOPERAND(q), GETQUERY(q), &size);
	if (size < 2)
	{
		pfree(item);
		return calc_rank_or(w, t, q);
	}
	pos = (uint16 **) palloc(sizeof(uint16 *) * q->size);
	memset(pos, 0, sizeof(uint16 *) * q->size);
	*(uint16 *) POSNULL = lengthof(POSNULL) - 1;
	WEP_SETPOS(POSNULL[1], MAXENTRYPOS - 1);

	for (i = 0; i < size; i++)
	{
		entry = find_wordentry(t, q, item[i]);
		if (!entry)
			continue;

		if (entry->haspos)
			pos[i] = (uint16 *) _POSDATAPTR(t, entry);
		else
			pos[i] = (uint16 *) POSNULL;


		dimt = *(uint16 *) (pos[i]);
		post = (WordEntryPos *) (pos[i] + 1);
		for (k = 0; k < i; k++)
		{
			if (!pos[k])
				continue;
			lenct = *(uint16 *) (pos[k]);
			ct = (WordEntryPos *) (pos[k] + 1);
			for (l = 0; l < dimt; l++)
			{
				for (p = 0; p < lenct; p++)
				{
					dist = Abs((int) WEP_GETPOS(post[l]) - (int) WEP_GETPOS(ct[p]));
					if (dist || (dist == 0 && (pos[i] == (uint16 *) POSNULL || pos[k] == (uint16 *) POSNULL)))
					{
						float		curw;

						if (!dist)
							dist = MAXENTRYPOS;
						curw = sqrt(wpos(post[l]) * wpos(ct[p]) * word_distance(dist));
						res = (res < 0) ? curw : 1.0 - (1.0 - res) * (1.0 - curw);
					}
				}
			}
		}
	}
	pfree(pos);
	pfree(item);
	return res;
}
Beispiel #23
0
//-------------------------------------------------------------------------------------
UDPPacket::UDPPacket(MessageID msgID, size_t res):
Packet(msgID, false, res)
{
	data_resize(maxBufferSize());
	wpos(0);
}
Beispiel #24
0
//-------------------------------------------------------------------------------------
TCPPacket::TCPPacket(MessageID msgID, size_t res):
Packet(msgID, true, res)
{
	data_resize(PACKET_MAX_SIZE_TCP * 4);
	wpos(0);
}
void CBuilderCAI::DrawCommands(void)
{
	float3 pos=owner->midPos;
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	glEnable(GL_BLEND);

	if(uh->limitDgun && owner->unitDef->isCommander){
		glColor4f(1,1,1,0.6);
		float3 p=gs->Team(owner->team)->startPos;
		glBegin(GL_LINE_STRIP);
		for(int a=0;a<=40;++a){
			float3 pos2=float3(p.x+sin(a*PI*2/40)*uh->dgunRadius,0,p.z+cos(a*PI*2/40)*uh->dgunRadius);
			pos2.y=ground->GetHeight(pos2.x,pos2.z)+5;
			glVertexf3(pos2);
		}
		glEnd();
	}
	glColor4f(1,1,1,0.4);
	glBegin(GL_LINE_STRIP);
	glVertexf3(pos);
	deque<Command>::iterator ci;
	for(ci=commandQue.begin();ci!=commandQue.end();++ci){
		bool draw=false;
		switch(ci->id){
		case CMD_MOVE:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(0.5,1,0.5,0.4);
			draw=true;
			break;
		case CMD_RECLAIM:
		case CMD_RESURRECT:
			if(ci->id==CMD_RECLAIM)
				glColor4f(1,0.2,1,0.4);
			else
				glColor4f(0.2,0.6,1,0.4);

			if(ci->params.size()==4){
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
				float radius=ci->params[3];
				glVertexf3(pos);
				glEnd();
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=20;++a){
					float3 pos2=float3(pos.x+sin(a*PI*2/20)*radius,0,pos.z+cos(a*PI*2/20)*radius);
					pos2.y=ground->GetHeight(pos2.x,pos2.z)+5;
					glVertexf3(pos2);
				}
				glEnd();
				glBegin(GL_LINE_STRIP);
			} else {
				int id=(int) ci->params[0];
				if(id>=MAX_UNITS){
					if(featureHandler->features[id-MAX_UNITS])
						pos=featureHandler->features[id-MAX_UNITS]->midPos;
				} else {
					if(uh->units[id]!=0 && uh->units[id]!=owner)
						pos=helper->GetUnitErrorPos(uh->units[id],owner->allyteam);
				}
			}
			draw=true;
			break;
		case CMD_PATROL:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(0.5,0.5,1,0.4);
			draw=true;
			break;
		case CMD_REPAIR:
		case CMD_CAPTURE:
			if(ci->id==CMD_REPAIR)
				glColor4f(0.3,1,1,0.4);
			else
				glColor4f(1,1,0.3,0.4);
			if(ci->params.size()==4){
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
				float radius=ci->params[3];
				glVertexf3(pos);
				glEnd();
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=20;++a){
					float3 pos2=float3(pos.x+sin(a*PI*2/20)*radius,0,pos.z+cos(a*PI*2/20)*radius);
					pos2.y=ground->GetHeight(pos2.x,pos2.z);
					glVertexf3(pos2);
				}
				glEnd();
				glBegin(GL_LINE_STRIP);
			} else {
				int id=(int) ci->params[0];
				if(uh->units[id]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			}
			draw=true;
			break;
		case CMD_RESTORE:{
			glColor4f(0.3,1,0.5,0.4);
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			float radius=ci->params[3];
			glVertexf3(pos);
			glEnd();
			glBegin(GL_LINE_STRIP);
			for(int a=0;a<=20;++a){
				float3 pos2=float3(pos.x+sin(a*PI*2/20)*radius,0,pos.z+cos(a*PI*2/20)*radius);
				pos2.y=ground->GetHeight(pos2.x,pos2.z);
				glVertexf3(pos2);
			}
			glEnd();
			glBegin(GL_LINE_STRIP);
			draw=true;
			break;}
		case CMD_GUARD:
			if(uh->units[int(ci->params[0])]!=0)
				pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			glColor4f(0.3,0.3,1,0.4);
			draw=true;
			break;
		case CMD_ATTACK:
		case CMD_DGUN:
			if(ci->params.size()==1){
				if(uh->units[int(ci->params[0])]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			} else {
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			}
			glColor4f(1,0.5,0.5,0.4);
			draw=true;
			break;
		}
		map<int,string>::iterator boi;
		if((boi=buildOptions.find(ci->id))!=buildOptions.end()){
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			UnitDef *unitdef = unitDefHandler->GetUnitByName(boi->second);

			glColor4f(1,1,1,0.4);
			glVertexf3(pos);
			glEnd();

			pos=helper->Pos2BuildPos(pos,unitdef);

			if(unitdef->extractRange>0){	//draw range
				glDisable(GL_TEXTURE_2D);
				glColor4f(1,0.3,0.3,0.7);
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=40;++a){
					float3 wpos(cos(a*2*PI/40)*unitdef->extractRange,0,sin(a*2*PI/40)*unitdef->extractRange);
					wpos+=pos;
					wpos.y=ground->GetHeight(wpos.x,wpos.z)+8;
					glVertexf3(wpos);
				}
				glEnd();
			}

			glColor4f(1,1,1,0.3);
			unitDrawer->DrawBuildingSample(unitdef, owner->team, pos);

			glColor4f(1,1,1,0.4);
			glBegin(GL_LINE_STRIP);
			draw=true;
		}
		if(draw){
			glVertexf3(pos);	
		}
	}
	glEnd();
}
Beispiel #26
0
//-------------------------------------------------------------------------------------
UDPPacket::UDPPacket(MessageID msgID, size_t res):
Packet(msgID, false, res)
{
	data_resize(PACKET_MAX_SIZE_UDP);
	wpos(0);
}
Beispiel #27
0
static float
calc_rank_or(float *w, TSVector t, TSQuery q)
{
	WordEntry  *entry,
			   *firstentry;
	WordEntryPos *post;
	int32		dimt,
				j,
				i,
				nitem;
	float		res = 0.0;
	QueryOperand **item;
	int			size = q->size;

	item = SortAndUniqItems(q, &size);

	for (i = 0; i < size; i++)
	{
		float		resj,
					wjm;
		int32		jm;

		firstentry = entry = find_wordentry(t, q, item[i], &nitem);
		if (!entry)
			continue;

		while (entry - firstentry < nitem)
		{
			if (entry->haspos)
			{
				dimt = POSDATALEN(t, entry);
				post = POSDATAPTR(t, entry);
			}
			else
			{
				dimt = POSNULL.npos;
				post = POSNULL.pos;
			}

			resj = 0.0;
			wjm = -1.0;
			jm = 0;
			for (j = 0; j < dimt; j++)
			{
				resj = resj + wpos(post[j]) / ((j + 1) * (j + 1));
				if (wpos(post[j]) > wjm)
				{
					wjm = wpos(post[j]);
					jm = j;
				}
			}
/*
			limit (sum(i/i^2),i->inf) = pi^2/6
			resj = sum(wi/i^2),i=1,noccurence,
			wi - should be sorted desc,
			don't sort for now, just choose maximum weight. This should be corrected
			Oleg Bartunov
*/
			res = res + (wjm + resj - wjm / ((jm + 1) * (jm + 1))) / 1.64493406685;

			entry++;
		}
	}
	if (size > 0)
		res = res / size;
	pfree(item);
	return res;
}
Beispiel #28
0
static float
calc_rank_and(float *w, TSVector t, TSQuery q)
{
	WordEntryPosVector **pos;
	int			i,
				k,
				l,
				p;
	WordEntry  *entry,
			   *firstentry;
	WordEntryPos *post,
			   *ct;
	int32		dimt,
				lenct,
				dist,
				nitem;
	float		res = -1.0;
	QueryOperand **item;
	int			size = q->size;

	item = SortAndUniqItems(q, &size);
	if (size < 2)
	{
		pfree(item);
		return calc_rank_or(w, t, q);
	}
	pos = (WordEntryPosVector **) palloc0(sizeof(WordEntryPosVector *) * q->size);
	WEP_SETPOS(POSNULL.pos[0], MAXENTRYPOS - 1);

	for (i = 0; i < size; i++)
	{
		firstentry = entry = find_wordentry(t, q, item[i], &nitem);
		if (!entry)
			continue;

		while (entry - firstentry < nitem)
		{
			if (entry->haspos)
				pos[i] = _POSVECPTR(t, entry);
			else
				pos[i] = &POSNULL;

			dimt = pos[i]->npos;
			post = pos[i]->pos;
			for (k = 0; k < i; k++)
			{
				if (!pos[k])
					continue;
				lenct = pos[k]->npos;
				ct = pos[k]->pos;
				for (l = 0; l < dimt; l++)
				{
					for (p = 0; p < lenct; p++)
					{
						dist = Abs((int) WEP_GETPOS(post[l]) - (int) WEP_GETPOS(ct[p]));
						if (dist || (dist == 0 && (pos[i] == &POSNULL || pos[k] == &POSNULL)))
						{
							float		curw;

							if (!dist)
								dist = MAXENTRYPOS;
							curw = sqrt(wpos(post[l]) * wpos(ct[p]) * word_distance(dist));
							res = (res < 0) ? curw : 1.0 - (1.0 - res) * (1.0 - curw);
						}
					}
				}
			}

			entry++;
		}
	}
	pfree(pos);
	pfree(item);
	return res;
}
Beispiel #29
0
	virtual size_t totalSize() const { return wpos() - rpos(); }
Beispiel #30
0
	void resetPacket(void)
	{
		wpos(0);
		rpos(0);
		// memset(data(), 0, size());
	};