Re: [Avatarsdev-general] modificatori e altro
Status: Inactive
Brought to you by:
andreavalente
From: Inglima M. D. S. <st9...@ed...> - 2003-06-03 13:52:44
|
On Tue, 3 Jun 2003, Inglima Modica Davide Silvio wrote: > Modifiers and ids -- K - 2003 03 18 > 1) Modifiers: "Modifiers" means the way I chose to apply changes to > entities in the game. That changes could be temporary ("transient") or > can be not-reversible ("permanent"). [snip] The problem is: what do you think a modifier has to do? * Does it have to work as a netbeans/eclipse/mozilla plugin component? * Does it have instead to work a simple "modifier" for the outcome of an action? In the first case the chaos ensues, but in the second case it is rather simple. You have a modifier which: (a) registers (enters a stack) (b) unregisters let's say to have a man with "Strenght" as one of his characteristics, then there is a stack of modifiers somewhere. To get the raw or modified strenght we have these member functions: int getStrenghtRaw() { return strenght; } int getStrenghtModified() { int tempvalue = processStrenght(strengh); return validate(tempvalue); } To add a modifier we use a Collection: List strenghtPile; void strenghtModifiersPile(StrenghtModifier x) { /// should throw an exception in case of duplicate modifier strenghtPile.add(x); } To use the modifiers then we iterate on it: int processStrenght(int strenght) { /// of course it could access directly strenght, but maybe we want /// a little more freedom... /* * insert classic iterator example here * since I'm trying to remember things... */ Iterator i = strenghtPile.getIterator() while(i.hasnext()) { strenght = i.getNext().getModifierAction(strenght); } return strenght; } Modifiers then could be added or removed when needed > We need a way to identify the modifier to remove. > [ADD] I need some explanation: how the universe is supposed to > work? The "universe" has many "worlds" (one per runtime environment) > connected, and an entity can travel from one to another > on the net (ie over TCP/IP, etc.)? [ADD] [snip] > 3.1) What can be used as id in Java? [snip] > [ADD] 4- java.rmi.server.UID [ADD] Could be useful (the classes you propose are in J2SE if I'm correct, right?). Anyway... IDManager could be a singleton class. A singleton is a design pattern which says: "for each running instance of program x there is only a given object of a given singleton class", so having only one IDManager we can keep track of consistencies and inconsistencies. If we ever need to have a set of local and distributed IDManagers, the local IDManager could call a central server IDManager which will give back a pool of 100/1000 id's at a time. How to write a singleton: package net.sourceforge.avatars.util; public class IDManager { private static IDManager idmanager = null; private int lastid = 0; // note the private constructor private IDManager() { } // this creates a new IDManager OR returns the IDManager already running public static IDManager getInstance() { if (idmanager == null) { idmanager = new IDManager(); } return idmanager; } // this returns a number and adds one to the count; public synchronized Integer getNewID() { Integer result = new Integer(lastid); lastid++; return result; } } How to access it: IDManager idm = IDManager.getInstance(); Integer ix = idm.getNewID(); If we need to scale the IDs to a number higher, we could give back a class with four integers, or whatevere other else. Do we really need to free the IDs after having used them? Ciao. -- Davide Silvio Inglima-Modica "Mana is rapidly disappearing from the world, Even the" "mana tree has begun to wither" - Seiken Densetsu 3 http://web.tiscali.it/inglima/davide/ mailto:had...@li... |