Пример #1
0
        public void tick()
        {
            Game g = Game.GAME_INSTANCE;

            while (!g.isGameRunning())
            {
            }

            double lastTick = 0;

            while (g.isGameRunning())
            {
                double now = TimeUtils.getNow();
                if ((now - lastTick) < (1d / 60d))
                {
                    continue;
                }
                lastTick = now;

                double start = TimeUtils.getNow();

                foreach (GUI gui in GUI.getGUIs())
                {
                    gui.tick();
                }

                if (Scene.getActiveScene() != null)
                {
                    Scene.getActiveScene().tick();
                }
                //while(!renderDone) {}
                renderDone = false;
            }
        }
Пример #2
0
 public virtual void tick()
 {
     if (Scene.getActiveScene().isPaused())
     {
         return;
     }
 }
Пример #3
0
        public List <Model> getHittingModels()
        {
            List <Model> models = new List <Model>();

            foreach (Model m in Scene.getActiveScene().getModels())
            {
                if (m == null)
                {
                    continue;
                }
                if (!isHitting(m))
                {
                    continue;
                }
                models.Add(m);
            }
            return(models);
        }
Пример #4
0
        public List <Entity> getHittingEntities()
        {
            List <Entity> entities = new List <Entity>();

            if (Scene.getActiveScene() == null)
            {
                return(entities);
            }
            foreach (Entity e in Scene.getActiveScene().getEntities())
            {
                if (e == null)
                {
                    continue;
                }
                if (!isHitting(e))
                {
                    continue;
                }
                entities.Add(e);
            }
            return(entities);
        }
Пример #5
0
        public void Dispose()
        {
            this.gameRunning = false;
            GameLogger.getLogger().log("Closing Game Thread");
            try { this.gameThread.Interrupt(); } catch (Exception e) {}

            GameLogger.getLogger().log("Unloading BGMs");
            foreach (BackgroundMusic bgm in BackgroundMusic.getLoadedBackgroundMusics())
            {
                try { bgm.Dispose(); } catch (Exception e) {}
            }

            GameLogger.getLogger().log("Destroying all GUIs");
            foreach (GUI gui in GUI.getGUIs())
            {
                try { gui.Dispose(); } catch (Exception e) {}
            }

            GameLogger.getLogger().log("Diposing Scene");
            try { Scene.getActiveScene().Dispose(); } catch (Exception e) {}

            getDisplayManager().Dispose();
        }
Пример #6
0
        public void tick()
        {
            if (chatModel == null && this.chatMessages.Count > 0)
            {
                Scene.getActiveScene().pause();
                chatModel = new Model();
                chatModel.getMaterial().setRender2D(true);
                chatModel.getMaterial().setRender3D(false);

                Camera cmr;
                lock (cmr = Camera.getCamera()) {
                    background = new Quad();
                    background.setScaleX(cmr.getWidth());
                    background.getMaterial().setRender2D(true);
                    background.getMaterial().setRender3D(false);
                    background.setScaleY(150);
                    background.getMaterial().setColor(Color.BLUE.clone().setAlpha(0.1));

                    chatModel.addChild(background);

                    chatModel.getLocation().setX(cmr.getWidth() / 2.0);
                    chatModel.getLocation().setY(cmr.getHeight() - background.getScaleY() / 2.0);
                }

                Sprite cu = this.characterFace = new Sprite(Chat.getFrameBuffer().getLoadableTexture().getTexture());
                cu.flipY();
                cu.updateFace();
                cu.getLocation().setX(-background.getScaleX() / 2.0);
                cu.getLocation().setY(-cu.getHeight() / 2.0);
                chatModel.addChild(cu);

                Scene.getActiveScene().addModel(chatModel);
            }

            if (this.chatMessages.Count < 1 && chatModel != null)
            {
                Scene.getActiveScene().removeModel(chatModel);

                background.Dispose();
                characterFace.Dispose();
                chatModel.Dispose();

                background    = null;
                characterFace = null;
                chatModel     = null;
                Scene.getActiveScene().resume();
            }

            if (chatModel != null)
            {
                Scene.getActiveScene().removeModel(chatModel);

                if (getCurrentMessage() != this.currentMessage)
                {
                    if (this.fontModels != null)
                    {
                        lock (this.fontModels) {
                            foreach (FontModel fm in this.fontModels)
                            {
                                if (fm == null)
                                {
                                    continue;
                                }
                                lock (fm) {
                                    fm.getTexture().Dispose();
                                    fm.getVBO().Dispose();
                                    fm.Dispose();
                                }
                            }
                        }
                        this.fontModels = null;
                    }
                    else
                    {
                        ChatMessage c = this.currentMessage = getCurrentMessage();
                        String[]    s = c.getMessage().Split('\n');
                        foreach (String ss in s)
                        {
                            this.strs.Add(ss);
                        }
                        this.updateFonts();
                    }
                }

                Scene.getActiveScene().addModel(chatModel);

                if (this.strs.Count > 0)
                {
                    if (Game.GAME_INSTANCE.isButtonDown(GamePadButtons.Enter) && !this.enterLastFrame)
                    {
                        this.nextPage();
                    }
                }
            }

            this.enterLastFrame = Game.GAME_INSTANCE.isButtonDown(GamePadButtons.Enter);
        }
Пример #7
0
		public void render() {
			//Begin Rendering
			GraphicsContext graphics = getGraphicsContext();
			
			//Load Textures as Needed
			lock(this.texturesToLoad) {
				foreach(LoadableTexture lt in new List<LoadableTexture>(this.texturesToLoad)) {
					lock(lt) {try {
							Game.GAME_INSTANCE.getLogger().log ("Loading Texture " + lt.getTextureName());
							this.texturesToLoad.Remove(lt);
							if(lt.isLoaded()) continue;
							Texture2D texture;
							if(lt.getTextureName() != null) {
								texture = new Texture2D(lt.getTextureName(), false);
							} else {
								texture = new Texture2D(lt.getWidth(), lt.getHeight(), false, PixelFormat.Rgba, PixelBufferOption.Renderable);
							}
							
							if(lt.getImage() != null) {
								texture.SetPixels(0, lt.getImage().ToBuffer(), 0, 0, lt.getWidth(), lt.getHeight());
							}
							
							lt.setTexture(texture);
							Game.GAME_INSTANCE.getLogger().log ("...Done loading " + lt.getTextureName());
					} catch(Exception e) {Game.GAME_INSTANCE.getLogger().log ("Failed to load Texture..");}}
				} 
			}
			
			//Generate Depth Buffer Objects as Needed
			lock(this.depthBuffersToMake) {
				foreach(ThreadSafeDepthBuffer dsfb in new List<ThreadSafeDepthBuffer>(this.depthBuffersToMake)) {
					if(dsfb == null) continue;
					if(dsfb.getDepthBuffer() != null) continue;
					DepthBuffer db = new DepthBuffer(dsfb.getWidth(), dsfb.getHeight(), PixelFormat.Depth16);
					dsfb.setDepthBuffer(db);
					this.depthBuffersToMake.Remove(dsfb);
				}
			}
			
			//Generate Frame Buffer Objects as Needed
			lock(this.frameBuffersToMake) {
				foreach(ThreadSafeFrameBuffer tsfb in new List<ThreadSafeFrameBuffer>(this.frameBuffersToMake)) {
					if(tsfb == null) continue;
					if(tsfb.getFrameBuffer() != null) continue;
					FrameBuffer fb = new FrameBuffer();
					tsfb.setFrameBuffer(fb);
					
					if(tsfb.getLoadableTexture() != null && tsfb.getLoadableTexture().isLoaded()) {
						fb.SetColorTarget(tsfb.getLoadableTexture().getTexture(), 0);
					}
					
					if(tsfb.getThreadSafeDepthBuffer() != null && tsfb.getThreadSafeDepthBuffer().getDepthBuffer() != null) {
						fb.SetDepthTarget(tsfb.getThreadSafeDepthBuffer().getDepthBuffer());
					}
					this.frameBuffersToMake.Remove(tsfb);
				}
			}
			
			//Put Things on VBO as needed
			lock(this.vboWaitingList) {
				foreach(Model m in new List<Model>(this.vboWaitingList)) {
					Game.GAME_INSTANCE.getLogger().log ("Putting " + m.GetType() + "(" + m.getName() + ") on the VBO");
					m.putOnVBO();
					this.vboWaitingList.Remove(m);
				}
			}
			
			lock(this.getCamera()) {				
				List<Model> models = this.getModels();
				
				try {
					models.Sort(
						delegate(Model p1, Model p2) {
							if(p1 == null || p2 == null) return 0;
							lock(p1) {
								lock(p2) {
									Location p1Abs = p1.getLocation().getAbsoluteLocation();
									Location p2Abs = p2.getLocation().getAbsoluteLocation();
									double p1Dist = getCamera().getLocation().getDistance(p1Abs);
									double p2Dist = getCamera().getLocation().getDistance(p2Abs);
									return p1Dist.CompareTo(p2Dist);
								}
							}
						}
					);
				} catch(Exception e) {}
				
				//Render Objects
				if(Scene.getActiveScene() != null) {
					try {
						lock(Scene.getActiveScene()) {
							Scene.getActiveScene().onRender();
						}
					} catch(Exception e) {}
				}
				
				renderToBuffer(models, getCamera());
				
				//Add Custom Models as Needed
				if(Game.GAME_INSTANCE.getDebugMode()) {
					
					FontModel fps = new FontModel("FPS: " + this.getCamera().getFrameRate());
					fps.render(getCamera());
					fps.getTexture().Dispose();
					fps.getVBO().Dispose();
					fps.Dispose();
				}
			}
			
			graphics.SwapBuffers ();
			System.GC.Collect();
		}