public Shots(Device device) { shots = new Photon[Constants.NumShots]; for (int count = 0; count < Constants.NumShots; count++) { shots[count] = new Photon(device); } }
public override void OnHandlerMessage(Photon.SocketServer.OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters) { SubCode subCode = ParameterTool.GetParameter<SubCode>(request.Parameters,ParameterCode.SubCode,false); //给response参数添加subCode response.Parameters.Add((byte) ParameterCode.SubCode,subCode); switch (subCode) { case SubCode.AddTaskDB: TaskDB taskDB = ParameterTool.GetParameter<TaskDB>(request.Parameters, ParameterCode.TaskDB); taskDB.Role = peer.LoginRole; taskDBManager.AddTaskDB(taskDB); taskDB.Role = null; ParameterTool.AddParameter(response.Parameters,ParameterCode.TaskDB, taskDB); response.ReturnCode = (short) ReturnCode.Success; break; case SubCode.GetTaskDB: List<TaskDB> list = taskDBManager.GetTaskDBList(peer.LoginRole); foreach (var taskDb in list) { taskDb.Role = null; } ParameterTool.AddParameter(response.Parameters,ParameterCode.TaskDBList, list); response.ReturnCode = (short) ReturnCode.Success; break; case SubCode.UpdateTaskDB: TaskDB taskDB2 = ParameterTool.GetParameter<TaskDB>(request.Parameters, ParameterCode.TaskDB); taskDB2.Role = peer.LoginRole; taskDBManager.UpdataTaskDB(taskDB2); response.ReturnCode = (short) ReturnCode.Success; break; } }
protected override Photon.SocketServer.PeerBase CreatePeer(Photon.SocketServer.InitRequest initRequest) { var peer = new ServerPeer(initRequest); lock (_SynObject) { _NewProviderQueue.Enqueue(new Regulus.Remoting.Soul.SoulProvider(peer, peer)); } return peer; }
private TreeNode BuildTree(Photon ph) { TreeNode node = new TreeNode(); node.Tag = ph; node.Checked = false; node.Text = "photon " + ((ph.PhotonColorPower.R+ph.PhotonColorPower.G+ph.PhotonColorPower.B)/3).ToString(); if (ph.parent != null) { node.Nodes.Add(BuildTree(ph.parent)); } return node; }
public override void OnHandlerMessage(Photon.SocketServer.OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters) { //先得到子操作代码,根据子操作代码,分别进行不同的处理 SubCode subcode = ParameterTool.GetParameter<SubCode>(request.Parameters, ParameterCode.SubCode, false); Dictionary<byte, object> parameters = response.Parameters; parameters.Add((byte) ParameterCode.SubCode,subcode); response.OperationCode = request.OperationCode; switch (subcode) { case SubCode.AddRole: Role role = ParameterTool.GetParameter<Role>(request.Parameters, ParameterCode.Role); role.User = peer.LoginUser; roleManager.AddRole(role); role.User = null; //Json解析的时候不清空role.User会出现问题 //返回给客户端 ParameterTool.AddParameter(parameters,ParameterCode.Role,role); break; case SubCode.GetRole: List<Role> roleList = roleManager.GetRoleListByUser(peer.LoginUser); //List<Role>中的Role带用User对象,有关联的转换会出现错误,所以把他设置成空 //User是引用类型,json不知道怎么进行操作 foreach (var role1 in roleList) { role1.User = null; } ParameterTool.AddParameter(parameters,ParameterCode.RoleList, roleList); break; case SubCode.SelectRole: peer.LoginRole = ParameterTool.GetParameter<Role>(request.Parameters, ParameterCode.Role); break; case SubCode.UpdateRole: Role role2 = ParameterTool.GetParameter<Role>(request.Parameters, ParameterCode.Role); role2.User = peer.LoginUser; roleManager.UpdateRole(role2); role2.User = null; response.ReturnCode = (short) ReturnCode.Success; ParameterTool.AddParameter(parameters,ParameterCode.Role,role2); break; } }
public PhotonTrailQueue( Texture2D texture, Vector2 position ) { m_texture = texture; // Construct the queue. m_queue = new Photon[MAX_PHOTONS]; m_head = 0; m_tail = -1; m_size = 0; // "Predeclare" all the photons. for ( int ii = 0; ii < MAX_PHOTONS; ii++ ) { m_queue[ii] = new Photon(); } // These variables are used in Draw. m_position = position; m_origin = new Vector2( 0.0f, 0.0f ); }
public override void OnHandlerMessage(Photon.SocketServer.OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters) { User user = ParameterTool.GetParameter<User>(request.Parameters,ParameterCode.User); User userDB = manager.GetUserByUsername(user.Username); if (userDB != null) { response.ReturnCode = (short) ReturnCode.Fail; response.DebugMessage = "用户名重复"; } else { user.Password = MD5Tool.GetMD5(user.Password); manager.AddUser(user); response.ReturnCode = (short) ReturnCode.Success; } }
//得到客户端传递过来的user对象,根据用户名和密码进行查询,查询是否存在数据库,如果存在登录成功,否则登录失败 public override void OnHandlerMessage(Photon.SocketServer.OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters) { //得到user参数 Dictionary<byte, object> parameters = request.Parameters; object jsonObject = null; parameters.TryGetValue((byte) ParameterCode.User, out jsonObject); //把字符串转成user的对象 User user = JsonMapper.ToObject<User>(jsonObject.ToString()); User userDB = manager.GetUserByUsername(user.Username); if (userDB != null && userDB.Password == MD5Tool.GetMD5(user.Password)) { //用户名和密码正确 登录成功 response.ReturnCode =(short)ReturnCode.Success; peer.LoginUser = userDB; } else { response.ReturnCode = (short) ReturnCode.Fail; response.DebugMessage = "用户名或密码错误"; } }
protected override void ProcessMessage(Photon.Hive.Messages.IMessage message) { try { switch (message.Action) { case (byte)GameMessageCodes.ReinitializeGameStateOnMaster: if (this.ActorsManager.ActorsCount == 0) { Log.WarnFormat("Reinitialize tried to update GameState with ActorCount = 0. " + this); } else { var gameProperties = this.GetLobbyGameProperties(this.Properties.GetProperties()); object[] lobbyPropertyFilter = null; if (this.LobbyProperties != null) { lobbyPropertyFilter = new object[this.LobbyProperties.Count]; this.LobbyProperties.CopyTo(lobbyPropertyFilter); } var excludedActors = this.ActorsManager.ExcludedActors.Count > 0 ? this.ActorsManager.ExcludedActors.ToArray() : null; var expectedUsers = this.ActorsManager.ExpectedUsers.Count > 0 ? this.ActorsManager.ExpectedUsers.ToArray() : null; this.UpdateGameStateOnMaster(this.MaxPlayers, this.IsOpen, this.IsVisible, lobbyPropertyFilter, gameProperties, this.GetActiveUserIds(), null, true, this.GetInactiveUserIds(), excludedActors, expectedUsers, this.RoomState.CheckUserOnJoin); } break; case (byte)GameMessageCodes.CheckGame: this.CheckGame(); break; default: base.ProcessMessage(message); break; } } catch (Exception ex) { Log.Error(ex); } }
/// <summary>Logging method called by the client library.</summary> /// <remarks> /// This method is not responsible to keep up the state of a LoadBalancingClient, so calling base.DebugReturn is optional. /// The amount of logging can be controlled by property PhotonPeer.DebugOut (try: this.loadBalancingPeer.DebugOut). /// </remarks> /// <param name="level">Severity of the message.</param> /// <param name="message">A debug message.</param> public override void DebugReturn(Photon.DebugLevel level, string message) { Log.AppendLine(message); base.DebugReturn(level, message); }
public void TestIfShot(Photon photon) { if (IsActive && photon.IsActive && _meteorSprite.IsPointWithin(photon.Location)) { IsActive = false; photon.SetInactive(); if(!(_meteorType is NullMeteorType)) { GameManager.RaiseMeteorHit(this); } } }
/// <summary> /// Implementation of a callback that's used by the Photon library to update the application / game of incoming events. /// </summary> /// <remarks> /// When you override this method, it's very important to call base.OnEvent to keep the state. /// /// Photon uses events to add or remove players from this client's lists. When we call base.OnEvent() /// and it adds a player, we want to fetch this player afterwards, if this removes a player, this /// player will be gone after base.OnEvent(). /// To get the added/removed player in any case, we might have to fetch it before or after running base code. /// </remarks> /// <param name="photonEvent">The event someone (or the server) sent.</param> public override void OnEvent(Photon.EventData photonEvent) { // most events have a sender / origin (but not all) - let's find the player sending this int actorNr = 0; Player origin = null; if (photonEvent.Parameters.ContainsKey(ParameterCode.ActorNr)) { actorNr = (int)photonEvent[ParameterCode.ActorNr]; // actorNr (a.k.a. playerNumber / ID) of sending player } if (actorNr > 0) { this.LocalRoom.Players.TryGetValue(actorNr, out origin); } base.OnEvent(photonEvent); // important to call, to keep state up to date if (actorNr > 0 && origin == null) { this.LocalRoom.Players.TryGetValue(actorNr, out origin); } // the list of players will only store Player references (not the derived class). simply cast: ParticlePlayer originatingPlayer = (ParticlePlayer)origin; // this demo logic doesn't handle any events from the server (that is done in the base class) so we could return here if (actorNr != 0 && originatingPlayer == null) { this.DebugReturn(DebugLevel.WARNING, photonEvent.Code + " ev. We didn't find a originating player for actorId: " + actorNr); return; } // this demo defined 2 events: Position and Color. additionally, a event is triggered when players join or leave switch (photonEvent.Code) { case DemoConstants.EvPosition: originatingPlayer.ReadEvMove((Hashtable)photonEvent[ParameterCode.CustomEventContent]); break; case DemoConstants.EvColor: originatingPlayer.ReadEvColor((Hashtable)photonEvent[ParameterCode.CustomEventContent]); break; // in this demo, we want a callback when players join or leave (so we can update their representation) case EventCode.Join: if (OnEventJoin != null) { OnEventJoin(originatingPlayer); } break; case EventCode.Leave: if (OnEventLeave != null) { OnEventLeave(originatingPlayer); } break; } UpdateVisuals = true; }
public ServerPeer(Photon.SocketServer.InitRequest initRequest) : base(initRequest.Protocol, initRequest.PhotonPeer) { _Fiber = new ExitGames.Concurrency.Fibers.PoolFiber(); _Fiber.Start(); }
protected override void OnOperationRequest(Photon.SocketServer.OperationRequest operationRequest, Photon.SocketServer.SendParameters sendParameters) { if (operationRequest.OperationCode == (byte)ClientToServerPhotonOpCode.Ping) { (this as Regulus.Remoting.IResponseQueue).Push((int)ServerToClientPhotonOpCode.Ping , new Dictionary<byte,byte[]>()); }else if (operationRequest.OperationCode == (byte)ClientToServerPhotonOpCode.CallMethod) { var entityId = new Guid(operationRequest.Parameters[0] as byte[]); var methodName = System.Text.Encoding.Default.GetString(operationRequest.Parameters[1] as byte[]); object par = null; Guid returnId = Guid.Empty; if (operationRequest.Parameters.TryGetValue(2, out par)) { returnId = new Guid(par as byte[]); } var methodParams = (from p in operationRequest.Parameters where p.Key >= 3 orderby p.Key select p.Value as byte[]).ToArray(); _Push(entityId, methodName, returnId, methodParams); } }
private void PhotonShade(HitInfo hit, Line ray, int threadId, int depth, bool inside, ColorIntensity lightCol, Random rnd, double distance, double area) { if (depth > maxrecurse) return; if (lightCol.GreyScale() < minratio) return; RealHitInfo realHit = hit.GetReal(ray); Material surf = realHit.HitStuff; ColorIntensity pigment = realHit.Pigment.GetTexture(realHit.Normal, 0); double dist = realHit.Normal.Start.LineTo(ray.Start).Length; distance += dist; if (surf.Attenutive && inside) { lightCol.R *= Math.Exp(-(1.0 - surf.Attenuation[0]) * dist / surf.AttenuationDistance); lightCol.G *= Math.Exp(-(1.0 - surf.Attenuation[1]) * dist / surf.AttenuationDistance); lightCol.B *= Math.Exp(-(1.0 - surf.Attenuation[2]) * dist / surf.AttenuationDistance); } #if DEBUG Photon currentParent = PhotonParents[threadId]; #endif if ((depth > 0 || allLightsArePhotons)) { Photon photon = new Photon(); photon.HitPos.X = (float)realHit.Normal.Start.X; photon.HitPos.Y = (float)realHit.Normal.Start.Y; photon.HitPos.Z = (float)realHit.Normal.Start.Z; photon.TravelDir.Dx = (float)ray.Direct.Dx; photon.TravelDir.Dy = (float)ray.Direct.Dy; photon.TravelDir.Dz = (float)ray.Direct.Dz; ColorIntensity photonColor = lightCol; if (realLighting || distance == double.PositiveInfinity) { photonColor.R *= area / PhotonCount; photonColor.G *= area / PhotonCount; photonColor.B *= area / PhotonCount; } else { photonColor.R *= distance * distance * area / PhotonCount; photonColor.G *= distance * distance * area / PhotonCount; photonColor.B *= distance * distance * area / PhotonCount; } photon.PhotonColorPower.R = (float)photonColor.R; photon.PhotonColorPower.G = (float)photonColor.G; photon.PhotonColorPower.B = (float)photonColor.B; #if DEBUG photon.parent = currentParent; PhotonParents[threadId] = photon; #endif Map.AddPhoton(photon, threadId); } ColorIntensity reflectance = new ColorIntensity(); ColorIntensity transmitance = new ColorIntensity(); Line refractRay = new Line(); Line reflectRay = new Line(); if (surf.Refractive || surf.Reflective) { ray.Direct = ray.Direct.Scale(1 / ray.Direct.Length); reflectance.R = surf.Reflective ? surf.Reflectance[0] : 0.0; reflectance.G = surf.Reflective ? surf.Reflectance[1] : 0.0; reflectance.B = surf.Reflective ? surf.Reflectance[2] : 0.0; if (surf.Refractive) { double ni = inside ? surf.RefractIndex : 1.0; double nt = (!inside) ? surf.RefractIndex : 1.0; double cratio = ni / nt; double ct1 = -ray.Direct.Dot(realHit.Normal.Direct); double ct2sqrd = 1 - cratio * cratio * (1 - ct1 * ct1); if (ct2sqrd <= 0) { reflectance.R = 1; reflectance.G = 1; reflectance.B = 1; } else { double ct2 = Math.Sqrt(ct2sqrd); // fresnel equations for reflectance perp and parallel. double rperp = (ni * ct1 - nt * ct2) / (ni * ct1 + nt * ct2); double rpll = (nt * ct1 - ni * ct2) / (ni * ct2 + nt + ct1); // assume unpolarised light always - better then tracing 2 // rays for both sides of every interface. double reflectanceval = (rperp * rperp + rpll * rpll) / 2; reflectance.R = Math.Min(1.0, reflectance.R + reflectanceval); reflectance.G = Math.Min(1.0, reflectance.G + reflectanceval); reflectance.B = Math.Min(1.0, reflectance.B + reflectanceval); transmitance.R = 1 - reflectance.R; transmitance.G = 1 - reflectance.G; transmitance.B = 1 - reflectance.B; refractRay.Direct = ray.Direct.Scale(cratio); refractRay.Direct.Add(realHit.Normal.Direct.Scale(cratio * (ct1) - ct2)); refractRay.Start = realHit.Normal.Start.MoveBy(refractRay.Direct.Scale(EPSILON * 10)); } } reflectRay.Direct = new Vector(ray.Direct.Dx, ray.Direct.Dy, ray.Direct.Dz); reflectRay.Direct.Add(realHit.Normal.Direct.Scale(-2 * ray.Direct.Dot(realHit.Normal.Direct))); reflectRay.Start = realHit.Normal.Start.MoveBy(reflectRay.Direct.Scale(EPSILON * 10)); } bool doReflect = false; bool doRefract = false; bool doDifuse = false; double avr = reflectance.R + reflectance.G + reflectance.B; avr /= 3; double avt = transmitance.R + transmitance.G + transmitance.B; avt /= 3; double reflectWeight = Math.Max(avr, 0.0); double refractWeight = Math.Max(avt, 0.0); double diffuseWeight = Math.Max(pigment.GreyScale() * surf.Diffuse, 0.0); double specularity = 1.0; double diffusivity = 1.0; if (surf.Refractive) { specularity = surf.Specularity; diffusivity = 1.0 - specularity; reflectWeight *= surf.Specularity; refractWeight *= surf.Specularity; diffuseWeight *= 1.0-surf.Specularity; } double choice = rnd.NextDouble(); if (choice < diffuseWeight) doDifuse = true; else if (choice < diffuseWeight+reflectWeight) doReflect = true; else if (choice < diffuseWeight+reflectWeight+refractWeight) doRefract = true; if (doRefract && avt > minratio) { SetIn(ref refractRay.Start, threadId); HitInfo hitnew = scene.Intersect(refractRay, threadId); if (!(hitnew.HitDist == -1)) { ColorIntensity lightCol2 = new ColorIntensity(); lightCol2.R = lightCol.R * transmitance.R *specularity/ refractWeight; lightCol2.G = lightCol.G * transmitance.G * specularity / refractWeight; lightCol2.B = lightCol.B * transmitance.B * specularity / refractWeight; PhotonShade(hitnew, refractRay, threadId, depth + 1, !inside, lightCol2, rnd, distance, area); } } if (doReflect && avr > minratio) { SetIn(ref reflectRay.Start, threadId); HitInfo hitnew2 = scene.Intersect(reflectRay, threadId); if (!(hitnew2.HitDist == -1)) { ColorIntensity lightCol2 = new ColorIntensity(); lightCol2.R = lightCol.R * reflectance.R * specularity / reflectWeight; lightCol2.G = lightCol.G * reflectance.G * specularity / reflectWeight; lightCol2.B = lightCol.B * reflectance.B * specularity / reflectWeight; PhotonShade(hitnew2, reflectRay, threadId, depth + 1, inside, lightCol2, rnd, distance, area); } } if (doDifuse) { double z = rnd.NextDouble(); double theta = rnd.NextDouble() * 2.0 * Math.PI; double r = Math.Sqrt(1 - z * z); double x = Math.Cos(theta) * r; double y = Math.Sin(theta) * r; Line diffuseRay = new Line(); Vector a; Vector b; Vector basis = realHit.Normal.Direct.Scale(1.0/realHit.Normal.Direct.Length); GetPerp(basis, out a, out b); diffuseRay.Direct = basis.Scale(z); diffuseRay.Direct.Add(a.Scale(x/a.Length)); diffuseRay.Direct.Add(b.Scale(y/b.Length)); diffuseRay.Start = realHit.Normal.Start.MoveBy(diffuseRay.Direct.Scale(EPSILON * 10)); SetIn(ref diffuseRay.Start, threadId); HitInfo hitnew2 = scene.Intersect(diffuseRay, threadId); if (!(hitnew2.HitDist == -1)) { ColorIntensity lightCol2 = new ColorIntensity(); lightCol2.R = lightCol.R * surf.Diffuse * pigment.R *diffusivity/ diffuseWeight; lightCol2.G = lightCol.G * surf.Diffuse * pigment.G * diffusivity / diffuseWeight; lightCol2.B = lightCol.B * surf.Diffuse * pigment.B * diffusivity / diffuseWeight; PhotonShade(hitnew2, diffuseRay, threadId, depth + 1, inside, lightCol2, rnd, distance, area); } } #if DEBUG PhotonParents[threadId] = currentParent; #endif }
public virtual void OnCustomAuthenticationError(Photon.Common.ErrorCode errorCode, string debugMessage, IAuthenticateRequest authenticateRequest, SendParameters sendParameters, object state) { try { if (this.Connected == false) { return; } if (log.IsDebugEnabled) { log.DebugFormat("Client custom authentication failed: appId={0}, result={1}, msg={2}", authenticateRequest.ApplicationId, errorCode, debugMessage); } var operationResponse = new OperationResponse((byte)Hive.Operations.OperationCode.Authenticate) { ReturnCode = (short)errorCode, DebugMessage = debugMessage, }; this.SendOperationResponse(operationResponse, sendParameters); this.SetCurrentOperationHandler(OperationHandlerInitial.Instance); } catch(Exception ex) { log.Error(ex); var errorResponse = new OperationResponse((byte)Hive.Operations.OperationCode.Authenticate) { ReturnCode = (short)Photon.Common.ErrorCode.InternalServerError }; this.SendOperationResponse(errorResponse, sendParameters); } }
void IPluginHost.BroadcastEvent(IList<int> receiverActors, int senderActor, byte evCode, Dictionary<byte, object> data, byte cacheOp, Photon.Hive.Plugin.SendParameters sendParameters) { var targets = receiverActors == null ? this.Actors : this.ActorsManager.ActorsGetActorsByNumbers(receiverActors.ToArray()); this.BroadcastEventInternal(evCode, data, cacheOp, true, senderActor, targets, sendParameters); }
public void SetShotArray(Photon[] shotArray) { lock(this) { this.shots = shotArray; } }
/// <summary> /// Implementation of a callback that's used by the Photon library to update the application / game of operation responses by server. /// </summary> /// <remarks>When you override this method, it's very important to call base.OnEvent to keep the state.</remarks> /// <param name="operationResponse">The response to some operation we called on the server.</param> public override void OnOperationResponse(Photon.OperationResponse operationResponse) { base.OnOperationResponse(operationResponse); // important to call, to keep state up to date if (operationResponse.ReturnCode != ErrorCode.Ok) { //this.DebugReturn(DebugLevel.ERROR, operationResponse.ToStringFull() + " " + this.State); } // this demo connects when you call start and then it automatically executes a certain operation workflow to get you in a room switch (operationResponse.OperationCode) { case OperationCode.Authenticate: // Unlike before, the game-joining can now be triggered by the simpler OnStateChangeAction delegate: OnStateChanged(ClientState newState) break; case OperationCode.JoinRandomGame: // OpJoinRandomRoom is called above. the response to that is handled here // if the Master Server didn't find a room, simply create one. the result is handled below if (this.JoinRandomGame && operationResponse.ReturnCode != ErrorCode.Ok) { this.CreateParticleDemoRoom(DemoConstants.MapType.Forest, 4); } break; case OperationCode.JoinGame: case OperationCode.CreateGame: // the master server will respond to join and create but this is handled in the base class if (this.State == ClientState.Joined) { // no matter if we joined or created a game, when we arrived in state "Joined", we are on the game server in a room and // this client could start moving and update others of it's color this.LocalPlayer.RandomizePosition(); //this.loadBalancingPeer.OpRaiseEvent(DemoConstants.EvColor, this.LocalPlayer.WriteEvColor(), true, 0, null, EventCaching.AddToRoomCache); this.loadBalancingPeer.OpRaiseEvent(DemoConstants.EvColor, this.LocalPlayer.WriteEvColor(), this.SendReliable, new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache }); } break; } UpdateVisuals = true; }
/// <summary> /// In this demo we only update the visuals when the status changes. The base class does everything else. /// </summary> /// <remarks>When you override this method, it's very important to call base.OnStatusChanged to keep the state.</remarks> /// <param name="statusCode"></param> public override void OnStatusChanged(Photon.StatusCode statusCode) { base.OnStatusChanged(statusCode); // important to call, to keep state up to date if (statusCode == StatusCode.Disconnect && this.DisconnectedCause != DisconnectCause.None) { DebugReturn(DebugLevel.ERROR, this.DisconnectedCause + " caused a disconnect. State: " + this.State + " statusCode: " + statusCode + "."); } UpdateVisuals = true; }
void IPluginHost.BroadcastEvent(byte target, int senderActor, byte targetGroup, byte evCode, Dictionary<byte, object> data, byte cacheOp, Photon.Hive.Plugin.SendParameters sendParameters) { IEnumerable<Actor> actors; var updateEventCache = false; switch (target) { case ReciverGroup.All: actors = this.Actors; updateEventCache = true; break; case ReciverGroup.Others: actors = this.ActorsManager.ActorsGetExcludedList(senderActor); updateEventCache = true; break; case ReciverGroup.Group: actors = this.GroupManager.GetActorGroup(targetGroup); break; default: Log.ErrorFormat("Unknown target {0} specified in BroadcastEvent", target); throw new ArgumentException(string.Format("Unknown target {0} specified in BroadcastEvent", target)); } this.BroadcastEventInternal(evCode, data, cacheOp, updateEventCache, senderActor, actors, sendParameters); }
private PixelMap Trace(int threadCount) { if (scene == null) { throw new NullReferenceException("Empty Scene"); } scene.SetTracer(this, threadCount); raycount = new int[threadCount]; Pools = new HitInfoListPool[threadCount]; #if DEBUG PhotonParents = new Photon[threadCount]; #endif for (int i = 0; i < threadCount; i++) Pools[i] = new HitInfoListPool(); if (photons) { if (PhotonFile == null || !File.Exists(PhotonFile)) { Map.InitForThreads(threadCount, true); Thread[] pthreads = new Thread[threadCount]; for (int i = 0; i < threadCount; i++) { pthreads[i] = new Thread(GeneratePhotonsWrap); pthreads[i].IsBackground = true; PhotonThreadArgs args = new PhotonThreadArgs(); args.threadCount = threadCount; args.threadId = i; pthreads[i].Start(args); } for (int i = 0; i < threadCount; i++) { pthreads[i].Join(); } Map.BalanceMap(); if (PhotonFile != null) Map.Save(PhotonFile); Map.OptimiseRadi(); } else { Map.InitForThreads(threadCount, false); Map.Load(PhotonFile); Map.ValidateBalance(); Map.OptimiseRadi(); } } PixelMap scrpix = new PixelMap(viewport.ScreenX, viewport.ScreenY); Color[] screen = scrpix.Pix; List<ColorIntensity>[] shadings = new List<ColorIntensity>[screen.Length]; for (int i = 0; i < shadings.Length; i++) shadings[i] = new List<ColorIntensity>(); Counter completed = new Counter(); int[] successive = new int[screen.Length]; if (OnProgress != null) { OnProgress(scrpix, 0 , 0); } Thread[] threads = new Thread[threadCount]; for (int i = 0; i < threadCount; i++) { threads[i] = new Thread(OneRenderThreadWrap); threads[i].IsBackground = true; RenderThreadArgs args = new RenderThreadArgs(); args.threadCount = threadCount; args.threadId = i; args.successive = successive; args.shadings = shadings; args.scrpix = scrpix; args.screen = screen; args.completed = completed; threads[i].Start(args); } for (int i = 0; i < threadCount; i++) { threads[i].Join(); } return scrpix; }