예제 #1
0
파일: Corpse.cpp 프로젝트: 2mac/openspades
		void Corpse::Spring(NodeType n1a,
							NodeType n1b,
							 NodeType n2,
							 float distance,
							 float dt){
			SPADES_MARK_FUNCTION_DEBUG();
			SPAssert(n1a >= 0); SPAssert(n1a < NodeCount);
			SPAssert(n1b >= 0); SPAssert(n1b < NodeCount);
			SPAssert(n2 >= 0); SPAssert(n2 < NodeCount);
			Node& x = nodes[n1a];
			Node& y = nodes[n1b];
			Node& b = nodes[n2];
			Vector3 diff = b.pos - (x.pos + y.pos) * .5f;
			float dist = diff.GetLength();
			Vector3 force = diff.Normalize() * (distance - dist);
			force *= dt * 50.f;
			
			b.vel += force;
			force *= .5f;
			x.vel -= force;
			y.vel -= force;
			
			Vector3 velMid = (x.vel + y.vel) * .25f + b.vel * .5f;
			float dump = 1.f - powf(.05f, dt);
			x.vel += (velMid - x.vel) * dump;
			y.vel += (velMid - y.vel) * dump;
			b.vel += (velMid - b.vel) * dump;
			
		}
예제 #2
0
파일: Corpse.cpp 프로젝트: 2mac/openspades
		void Corpse::Spring(NodeType n1,
							NodeType n2,
							float distance,
							float dt){
			SPADES_MARK_FUNCTION_DEBUG();
			SPAssert(n1 >= 0); SPAssert(n1 < NodeCount);
			SPAssert(n2 >= 0); SPAssert(n2 < NodeCount);
			Node& a = nodes[n1];
			Node& b = nodes[n2];
			Vector3 diff = b.pos - a.pos;
			float dist = diff.GetLength();
			Vector3 force = diff.Normalize() * (distance - dist);
			force *= dt * 50.f;
			
			b.vel += force;
			a.vel -= force;
			
			b.pos += force / (dt * 50.f) * 0.5f;
			a.pos -= force / (dt * 50.f) * 0.5f;
			
			Vector3 velMid = (a.vel + b.vel) * .5f;
			float dump = 1.f - powf(.1f, dt);
			a.vel += (velMid - a.vel) * dump;
			b.vel += (velMid - b.vel) * dump;
			
		}
예제 #3
0
		std::string ChatWindow::ColoredMessage(const std::string & msg,
											   char c){
			SPADES_MARK_FUNCTION_DEBUG();
			std::string s;
			s += c;
			s += msg;
			s += MsgColorRestore;
			return s;
		}
예제 #4
0
		std::vector<Grenade *> World::GetAllGrenades() {
			SPADES_MARK_FUNCTION_DEBUG();
			
			std::vector<Grenade *> g;
			for(std::list<Grenade *>::iterator it = grenades.begin();
				it != grenades.end(); it++){
				g.push_back(*it);
			}
			return g;
		}
예제 #5
0
		std::string ChatWindow::TeamColorMessage(const std::string &msg,
												 int team){
			SPADES_MARK_FUNCTION_DEBUG();
			if(team == 0)
				return ColoredMessage(msg, MsgColorTeam1);
			if(team == 1)
				return ColoredMessage(msg, MsgColorTeam2);
			if(team == 2)
				return ColoredMessage(msg, MsgColorTeam3);
			return msg;
		}
예제 #6
0
		void GLSpriteRenderer::Add(spades::draw::GLImage *img,
								   spades::Vector3 center, float rad, float ang,
								   Vector4 color){
			SPADES_MARK_FUNCTION_DEBUG();
			Sprite spr;
			spr.image = img;
			spr.center = center;
			spr.radius = rad;
			spr.angle = ang;
			spr.color = color;
			sprites.push_back(spr);
		}
예제 #7
0
		void GLRadiosityRenderer::Invalidate(int minX, int minY, int minZ, int maxX, int maxY,
		                                     int maxZ) {
			SPADES_MARK_FUNCTION_DEBUG();
			if (minZ < 0)
				minZ = 0;
			if (maxZ > d - 1)
				maxZ = d - 1;
			if (minX > maxX || minY > maxY || minZ > maxZ)
				return;

			// these should be floor div
			int cx1 = minX >> ChunkSizeBits;
			int cy1 = minY >> ChunkSizeBits;
			int cz1 = minZ >> ChunkSizeBits;
			int cx2 = maxX >> ChunkSizeBits;
			int cy2 = maxY >> ChunkSizeBits;
			int cz2 = maxZ >> ChunkSizeBits;

			for (int cx = cx1; cx <= cx2; cx++)
				for (int cy = cy1; cy <= cy2; cy++)
					for (int cz = cz1; cz <= cz2; cz++) {
						Chunk &c = GetChunkWrapped(cx, cy, cz);
						int originX = cx * ChunkSize;
						int originY = cy * ChunkSize;
						int originZ = cz * ChunkSize;

						int inMinX = std::max(minX - originX, 0);
						int inMinY = std::max(minY - originY, 0);
						int inMinZ = std::max(minZ - originZ, 0);
						int inMaxX = std::min(maxX - originX, ChunkSize - 1);
						int inMaxY = std::min(maxY - originY, ChunkSize - 1);
						int inMaxZ = std::min(maxZ - originZ, ChunkSize - 1);

						if (!c.dirty) {
							c.dirtyMinX = inMinX;
							c.dirtyMinY = inMinY;
							c.dirtyMinZ = inMinZ;
							c.dirtyMaxX = inMaxX;
							c.dirtyMaxY = inMaxY;
							c.dirtyMaxZ = inMaxZ;
							c.dirty = true;
						} else {
							c.dirtyMinX = std::min(inMinX, c.dirtyMinX);
							c.dirtyMinY = std::min(inMinY, c.dirtyMinY);
							c.dirtyMinZ = std::min(inMinZ, c.dirtyMinZ);
							c.dirtyMaxX = std::max(inMaxX, c.dirtyMaxX);
							c.dirtyMaxY = std::max(inMaxY, c.dirtyMaxY);
							c.dirtyMaxZ = std::max(inMaxZ, c.dirtyMaxZ);
						}
					}
		}
		bool ParticleSpriteEntity::Update(float dt) {
			SPADES_MARK_FUNCTION_DEBUG();
			Vector3 lastPos = position;
			
			time += dt;
			if(time > lifetime)
				return false;
			
			position += velocity * dt;
			velocity.z += 32.f * dt * gravityScale;
			
			// TODO: control clip action
			if(blockHitAction != Ignore && map){
				if(map->ClipWorld(position.x, position.y, position.z)){
					if(blockHitAction == Delete){
						return false;
					}else{
						IntVector3 lp2 = lastPos.Floor();
						IntVector3 lp = position.Floor();
						if (lp.z != lp2.z && ((lp.x == lp2.x && lp.y == lp2.y) ||
											  !map->ClipWorld(lp.x, lp.y, lp2.z)))
							velocity.z = -velocity.z;
						else if(lp.x != lp2.x && ((lp.y == lp2.y && lp.z == lp2.z) ||
												  !map->ClipWorld(lp2.x, lp.y, lp.z)))
							velocity.x = -velocity.x;
						else if(lp.y != lp2.y && ((lp.x == lp2.x && lp.z == lp2.z) ||
												  !map->ClipWorld(lp.x, lp2.y, lp.z)))
							velocity.y = -velocity.y;
						velocity *= .36f;
						position = lastPos;
					}
				}
			}
			
			// radius
			if(radiusVelocity != 0.f)
				radius += radiusVelocity * dt;
			
			if(rotationVelocity != 0.f)
				angle += rotationVelocity * dt;
			
			if(velocityDamp != 1.f)
				velocity *= powf(velocityDamp, dt);
			
			if(radiusDamp != 1.f)
				radiusVelocity *= powf(radiusDamp, dt);
			
			return true;
		}
예제 #9
0
		int GLProgramAttribute::operator()(spades::draw::GLProgram *prog){
			
			SPADES_MARK_FUNCTION_DEBUG();
			
			if(prog == NULL) {
				SPInvalidArgument("prog");
			}
			if(prog != last){
				last = prog;
				loc = last->GetDevice()->GetAttribLocation(last->GetHandle(), name.c_str());
				if(loc == -1){
					fprintf(stderr, "WARNING: GLSL attribute '%s' not found\n", name.c_str());
				}
			}
			return loc;
		}
예제 #10
0
		void GLSoftSpriteRenderer::Flush() {
			SPADES_MARK_FUNCTION_DEBUG();

			if (vertices.empty())
				return;

			device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::FloatType, false,
			                            sizeof(Vertex), &(vertices[0].x));
			device->VertexAttribPointer(spritePosAttribute(), 4, IGLDevice::FloatType, false,
			                            sizeof(Vertex), &(vertices[0].sx));
			device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
			                            sizeof(Vertex), &(vertices[0].r));

			SPAssert(lastImage);
			lastImage->Bind(IGLDevice::Texture2D);

			device->DrawElements(IGLDevice::Triangles,
			                     static_cast<IGLDevice::Sizei>(indices.size()),
			                     IGLDevice::UnsignedInt, indices.data());

			vertices.clear();
			indices.clear();
		}
예제 #11
0
	uint64_t StdStream::GetPosition() {
		SPADES_MARK_FUNCTION_DEBUG();
		return ftell(handle);
	}
예제 #12
0
	size_t StdStream::Read(void *buf, size_t bytes) {
		SPADES_MARK_FUNCTION_DEBUG();

		return fread(buf, 1, bytes, handle);
	}
예제 #13
0
	void StdStream::SetLength(uint64_t len) {
		SPADES_MARK_FUNCTION_DEBUG();

		// this is not safe
		ftruncate(fileno(handle), len);
	}
예제 #14
0
		void GLVoxelModel::EmitFace(spades::VoxelModel *model, int x, int y, int z, int nx, int ny,
		                            int nz, uint32_t color) {
			SPADES_MARK_FUNCTION_DEBUG();
			// decide face tangent
			int ux = ny, uy = nz, uz = nx;
			int vx = nz, vy = nx, vz = ny;
			if (nx < 0 || ny < 0 || nz < 0) {
				vx = -vx;
				vy = -vy;
				vz = -vz;
			}
			// now cross(u, v) = n (somehow)
			SPAssert(ux * vx + uy * vy + uz * vz == 0);
			SPAssert(ux * nx + uy * ny + uz * nz == 0);
			SPAssert(nx * vx + ny * vy + nz * vz == 0);
			SPAssert(uy * vz - uz * vy == -nx);
			SPAssert(uz * vx - ux * vz == -ny);
			SPAssert(ux * vy - uy * vx == -nz);

			// decide face origin
			int fx = 0, fy = 0, fz = 0;
			if (ux == -1 || vx == -1) {
				fx = 1;
				SPAssert(ux + vx == -1);
			}
			if (uy == -1 || vy == -1) {
				fy = 1;
				SPAssert(uy + vy == -1);
			}
			if (uz == -1 || vz == -1) {
				fz = 1;
				SPAssert(uz + vz == -1);
			}
			SPAssert(nx * fx + ny * fy + nz * fz == 0);

			uint8_t aoID = calcAOID(model, x + nx, y + ny, z + nz, ux, uy, uz, vx, vy, vz);

			Vertex v;
			uint32_t idx = (uint32_t)vertices.size();

			v.aoID = aoID;
			v.red = (uint8_t)(color);
			v.green = (uint8_t)(color >> 8);
			v.blue = (uint8_t)(color >> 16);
			v.diffuse = 255;
			v.nx = nx;
			v.ny = ny;
			v.nz = nz;

			x += fx;
			y += fy;
			z += fz;

			if (nx > 0)
				x++;
			if (ny > 0)
				y++;
			if (nz > 0)
				z++;

			SPAssert(x >= 0);
			SPAssert(y >= 0);
			SPAssert(y >= 0);
			SPAssert(x + ux >= 0);
			SPAssert(y + uy >= 0);
			SPAssert(z + uz >= 0);
			SPAssert(x + vx >= 0);
			SPAssert(y + vy >= 0);
			SPAssert(z + vz >= 0);
			SPAssert(x + ux + vx >= 0);
			SPAssert(y + uy + vy >= 0);
			SPAssert(z + uz + vz >= 0);

			v.u = 0;
			v.v = 0;
			v.x = x;
			v.y = y;
			v.z = z;
			vertices.push_back(v);

			v.u = 1;
			v.v = 0;
			v.x = x + ux;
			v.y = y + uy;
			v.z = z + uz;
			vertices.push_back(v);

			v.u = 0;
			v.v = 1;
			v.x = x + vx;
			v.y = y + vy;
			v.z = z + vz;
			vertices.push_back(v);

			v.u = 1;
			v.v = 1;
			v.x = x + ux + vx;
			v.y = y + uy + vy;
			v.z = z + uz + vz;
			vertices.push_back(v);

			indices.push_back(idx);
			indices.push_back(idx + 1);
			indices.push_back(idx + 2);
			indices.push_back(idx + 1);
			indices.push_back(idx + 3);
			indices.push_back(idx + 2);
		}
예제 #15
0
		std::vector<IntVector3> World::CubeLine(spades::IntVector3 v1,
												spades::IntVector3 v2,
												int maxLength) {
			SPADES_MARK_FUNCTION_DEBUG();
			
			IntVector3 c = v1;
			IntVector3 d = v2 - v1;
			long ixi, iyi, izi, dx, dy, dz, dxi, dyi, dzi;
			std::vector<IntVector3> ret;
			
			int VSID = map->Width();
			SPAssert(VSID == map->Height());
			
			int MAXZDIM = map->Depth();
			
			if (d.x < 0) ixi = -1;
			else ixi = 1;
			if (d.y < 0) iyi = -1;
			else iyi = 1;
			if (d.z < 0) izi = -1;
			else izi = 1;
			
			if ((abs(d.x) >= abs(d.y)) && (abs(d.x) >= abs(d.z)))
			{
				dxi = 1024; dx = 512;
				dyi = (long)(!d.y ? 0x3fffffff/VSID : abs(d.x*1024/d.y));
				dy = dyi/2;
				dzi = (long)(!d.z ? 0x3fffffff/VSID : abs(d.x*1024/d.z));
				dz = dzi/2;
			}
			else if (abs(d.y) >= abs(d.z))
			{
				dyi = 1024; dy = 512;
				dxi = (long)(!d.x ? 0x3fffffff/VSID : abs(d.y*1024/d.x));
				dx = dxi/2;
				dzi = (long)(!d.z ? 0x3fffffff/VSID : abs(d.y*1024/d.z));
				dz = dzi/2;
			}
			else
			{
				dzi = 1024; dz = 512;
				dxi = (long)(!d.x ? 0x3fffffff/VSID : abs(d.z*1024/d.x));
				dx = dxi/2;
				dyi = (long)(!d.y ? 0x3fffffff/VSID : abs(d.z*1024/d.y));
				dy = dyi/2;
			}
			if (ixi >= 0) dx = dxi-dx;
			if (iyi >= 0) dy = dyi-dy;
			if (izi >= 0) dz = dzi-dz;
			
			while (1)
			{
				ret.push_back(c);
				
				if(ret.size() == (size_t)maxLength)
					break;
				
				if(c.x == v2.x &&
				   c.y == v2.y &&
				   c.z == v2.z)
					break;
				
				if ((dz <= dx) && (dz <= dy))
				{
					c.z += izi;
					if (c.z < 0 || c.z >= MAXZDIM)
						break;
					dz += dzi;
				}
				else
				{
					if (dx < dy)
					{
						c.x += ixi;
						if ((unsigned long)c.x >= VSID)
							break;
						dx += dxi;
					}
					else
					{
						c.y += iyi;
						if ((unsigned long)c.y >= VSID)
							break;
						dy += dyi;
					}
				}
			}
			
			return ret;
		}
예제 #16
0
		void Weapon::ReloadDone(int ammo, int stock) {
			SPADES_MARK_FUNCTION_DEBUG();
			this->ammo = ammo;
			this->stock = stock;
		}
예제 #17
0
		void World::AddGrenade(spades::client::Grenade *g){
			SPADES_MARK_FUNCTION_DEBUG();
			
			grenades.push_back(g);
		}
예제 #18
0
		void Weapon::AbortReload() {
			SPADES_MARK_FUNCTION_DEBUG();
			reloading = false;
		}