1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.replica.replicaisland; 18 19 import java.util.ArrayList; 20 21 /** 22 * The object registry manages a collection of global singleton objects. However, it differs from 23 * the standard singleton pattern in a few important ways: 24 * - The objects managed by the registry have an undefined lifetime. They may become invalid at 25 * any time, and they may not be valid at the beginning of the program. 26 * - The only object that is always guaranteed to be valid is the ObjectRegistry itself. 27 * - There may be more than one ObjectRegistry, and there may be more than one instance of any of 28 * the systems managed by ObjectRegistry allocated at once. For example, separate threads may 29 * maintain their own separate ObjectRegistry instances. 30 */ 31 public class ObjectRegistry extends BaseObject { 32 33 public BufferLibrary bufferLibrary; 34 public CameraSystem cameraSystem; 35 public ChannelSystem channelSystem; 36 public CollisionSystem collisionSystem; 37 public ContextParameters contextParameters; 38 public CustomToastSystem customToastSystem; 39 public DebugSystem debugSystem; 40 public DrawableFactory drawableFactory; 41 public EventRecorder eventRecorder; 42 public GameObjectCollisionSystem gameObjectCollisionSystem; 43 public GameObjectFactory gameObjectFactory; 44 public GameObjectManager gameObjectManager; 45 public HitPointPool hitPointPool; 46 public HotSpotSystem hotSpotSystem; 47 public HudSystem hudSystem; 48 public InputGameInterface inputGameInterface; 49 public InputSystem inputSystem; 50 public LevelBuilder levelBuilder; 51 public LevelSystem levelSystem; 52 public OpenGLSystem openGLSystem; 53 public SoundSystem soundSystem; 54 public TextureLibrary shortTermTextureLibrary; 55 public TextureLibrary longTermTextureLibrary; 56 public TimeSystem timeSystem; 57 public RenderSystem renderSystem; 58 public VectorPool vectorPool; 59 public VibrationSystem vibrationSystem; 60 61 private ArrayList<BaseObject> mItemsNeedingReset = new ArrayList<BaseObject>(); 62 ObjectRegistry()63 public ObjectRegistry() { 64 super(); 65 } 66 registerForReset(BaseObject object)67 public void registerForReset(BaseObject object) { 68 final boolean contained = mItemsNeedingReset.contains(object); 69 assert !contained; 70 if (!contained) { 71 mItemsNeedingReset.add(object); 72 } 73 } 74 75 @Override reset()76 public void reset() { 77 final int count = mItemsNeedingReset.size(); 78 for (int x = 0; x < count; x++) { 79 mItemsNeedingReset.get(x).reset(); 80 } 81 } 82 83 } 84