You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(20) |
Jun
(46) |
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
|
Feb
|
Mar
(86) |
Apr
(77) |
May
(21) |
Jun
(11) |
Jul
(16) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(48) |
Oct
(1) |
Nov
(4) |
Dec
|
From: Snowdog <sn...@ga...> - 2006-06-15 21:29:18
|
Mark Tarrabain wrote: > Well, one ramification with choosing to do this is that you are > including some files in each jar file that do not need to be there. I don't think an extra 12k is really going to bug anyone ;-) As I said before, the lesser of two evils. > Further, why do you think you would have to violate any data hiding > principles to refactor them as I mentioned? I'd have to review all the files (which I don't have time for at the time of this writing) to give you specifics; but there are many points in the network code where calls are made to both package scope methods/vars as well as private classes. To refactor would require that a number of package-visibility scopes be changed to public to allow for package to package access. This would mean that ANY outside package could also access those variables and methods.. which as I stated before is something to avoid. Standard OOP practice: encapsulate, protect, and force usage though a predictable API. This network system is somewhat convoluted and complex in comparison to that of OpenRPG1's system. It has a delicate ballet being performed between several threads that must function without interruption or error. Protecting its internals is very important. --Snowdog |
From: Mark T. <ma...@ly...> - 2006-06-15 21:07:36
|
Well, one ramification with choosing to do this is that you are including some files in each jar file that do not need to be there. Further, why do you think you would have to violate any data hiding principles to refactor them as I mentioned? >> Mark Snowdog wrote: > Mark Tarrabain wrote: >> I was noticing that the following classes should probably be refactored >> from the openrpg2.common.core.network package and into packages that are >> specific to either the client or the server, as appropriate. >> >> NetworkAcceptThread, NetworkServer, NetworkServerModule, >> NetworkServiceThread, and NetworkThreadPool do not seem to get used by >> the client. Similarly the NetworkClient and NetworkClientModule classes >> do not seem to get used by the server. >> > > You are correct the client and server portions do not interact. They > reside in the same core package due to visibility constraints that are > required to prevent outside (i.e. non core.network) classes from direct > access to classes/objects on which both the client and server network > code depend. To move those classes you mentioned above to a new package > would require visibility changes (i.e. from private to public) that > could compromise the 'black-box' of the OpenRPG2 network layer. This is > an example of 'defensive' programming; the network layer is essentially > only accessible through the NetworkClient and NetworkServer objects and > their respective APIs. > > Initially those classes were in separate packages (outside of the core > package) however as the network came together it made more and more > sense to migrate them into a single package even if a tad counter > intuitive. The lesser of two evils IMO. > > --Snowdog > > > _______________________________________________ > Openrpg-v2-dev mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openrpg-v2-dev > > |
From: Baleno <tb...@wr...> - 2006-06-15 19:55:49
|
I agree :) Tom ---------- Original Message ----------- From: Snowdog <sn...@ga...> To: "Developer mailing list for OpenRPG 2 (Java)" <openrpg-v2- de...@li...> Sent: Thu, 15 Jun 2006 12:06:04 -0700 Subject: Re: [Openrpg2 dev] Moving things to where they belong. > Mark Tarrabain wrote: > > I was noticing that the following classes should probably be refactored > > from the openrpg2.common.core.network package and into packages that are > > specific to either the client or the server, as appropriate. > > > > NetworkAcceptThread, NetworkServer, NetworkServerModule, > > NetworkServiceThread, and NetworkThreadPool do not seem to get used by > > the client. Similarly the NetworkClient and NetworkClientModule classes > > do not seem to get used by the server. > > > > You are correct the client and server portions do not interact. They > reside in the same core package due to visibility constraints that are > required to prevent outside (i.e. non core.network) classes from direct > access to classes/objects on which both the client and server network > code depend. To move those classes you mentioned above to a new package > would require visibility changes (i.e. from private to public) that > could compromise the 'black-box' of the OpenRPG2 network layer. This is > an example of 'defensive' programming; the network layer is essentially > only accessible through the NetworkClient and NetworkServer objects and > their respective APIs. > > Initially those classes were in separate packages (outside of the core > package) however as the network came together it made more and more > sense to migrate them into a single package even if a tad counter > intuitive. The lesser of two evils IMO. > > --Snowdog > > _______________________________________________ > Openrpg-v2-dev mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openrpg-v2-dev ------- End of Original Message ------- |
From: Snowdog <sn...@ga...> - 2006-06-15 19:06:05
|
Mark Tarrabain wrote: > I was noticing that the following classes should probably be refactored > from the openrpg2.common.core.network package and into packages that are > specific to either the client or the server, as appropriate. > > NetworkAcceptThread, NetworkServer, NetworkServerModule, > NetworkServiceThread, and NetworkThreadPool do not seem to get used by > the client. Similarly the NetworkClient and NetworkClientModule classes > do not seem to get used by the server. > You are correct the client and server portions do not interact. They reside in the same core package due to visibility constraints that are required to prevent outside (i.e. non core.network) classes from direct access to classes/objects on which both the client and server network code depend. To move those classes you mentioned above to a new package would require visibility changes (i.e. from private to public) that could compromise the 'black-box' of the OpenRPG2 network layer. This is an example of 'defensive' programming; the network layer is essentially only accessible through the NetworkClient and NetworkServer objects and their respective APIs. Initially those classes were in separate packages (outside of the core package) however as the network came together it made more and more sense to migrate them into a single package even if a tad counter intuitive. The lesser of two evils IMO. --Snowdog |
From: Mark T. <ma...@ly...> - 2006-06-15 18:22:23
|
I was noticing that the following classes should probably be refactored from the openrpg2.common.core.network package and into packages that are specific to either the client or the server, as appropriate. NetworkAcceptThread, NetworkServer, NetworkServerModule, NetworkServiceThread, and NetworkThreadPool do not seem to get used by the client. Similarly the NetworkClient and NetworkClientModule classes do not seem to get used by the server. |
From: Snowdog <sn...@ga...> - 2006-06-15 17:07:56
|
Stop loosing sleep over it. :) There is method behind the madness. Yes, in some circumstances it would be nice (read: convenience to the developer) to be able to 'subscribe' to a message 'type'. However, that 'convience' comes at the price of easily spagettied code and cross module dependence... two things the messaging system was explicitly designed to help prevent. My thinking behind the module specific messages... A) Modules are not tied to a specific message format/structure. B) Message routing through a single-level lookup table is fast and doesn't require significant parsing. C) Messages cannot be altered by other modules. D) Module interdependence must be explicit (hard coded module-to-module) E) Modules should ONLY be dealing with its own messages (if you need to read another modules messages most likely your code is in the wrong place) F) Modules can be made to safely communicate with each other directly (after message parsing has occured) G) Module specific message parsers exist only once (in the owning module) and easily changed/maintained. H) Modules are allowed to handle/register multiple message types. The big problem with this is of course the chat system and map system which both have many 'parts'. These can either be coded as single large module or designed to have their own extensible sub-module system where messages are handed off to dynamically loaded sub-modules. The latter is the way I'd figured the map and chat would work best. When designing the messaging system I'd looked very hard at the pros and cons of the more traditional 'central parser' vs the 'distributed parser' setup which I eventually elected to go with. When it came right down to nuts and bolts though there really is no justification for any module to know how to read (or even be able to read) another modules messages. If the 'other' module needs to inform your module or otherwise interact with your module it should do so though the module API (i.e. explicitly) and not through message scanning. An example of this might be the 'typing/idle' display in the player list. You could look for incoming chat messages and rip out the info needed to update the player list but that is not only inefficient (due to double parsing) but also non-explicit. A much better solution is to add code to the chat module to inform the player-list module (though an event message or peer-to-peer method call) of the information that needs updated. The latter solution is explicit. Its obvious in both the player-list and the chat modules that something is supposed to happen. Of course it also leaves all the parsing of chat messages in the hands of the chat module so changes to the chat modules message format won't break other code. Hope that makes sense. --Snowdog Mark Tarrabain wrote: > I was lying awake tonight thinking about the message routing system, and > I wasn't sure if this was brought up before, but I'm not sure if the > existing system allows for something in particular: > > I'm thinking of situations where potentially more than one module might > be interested in a particular message. As it sits, it seems it just > looks up the message type in a hash table to get the interested > NetworkModule, but I was thinking that would not be amenable to a > situation where more than one module is interested in the message. > I'm thinking that in such situations, every interested module would > receive an identical copy of the message (in no particular order... they > should be considered simultaneous, even though it is likely they will > execute in sequence) and do with it whatever the module considers > appropriate. > > Am I out to lunch on this? Or should I just go back to bed and stop > losing sleep over it? > > |
From: Dj G. <dig...@gm...> - 2006-06-15 12:53:58
|
>From what I understand the messaging system is kind of a Publish / Subscribe system. So any module that is sending messages Publishes them and any modules that want a specific type of message subscribes to that type eg. Module A sends out Message types A and A1. Module B sends out type B, but Subscribes to type A. Module C sends out no messages but subscribes to Type A, A1, and B Of course I may be completely off my rocker her :) On 6/15/06, Mark Tarrabain <ma...@ly...> wrote: > I was lying awake tonight thinking about the message routing system, and > I wasn't sure if this was brought up before, but I'm not sure if the > existing system allows for something in particular: > > I'm thinking of situations where potentially more than one module might > be interested in a particular message. As it sits, it seems it just > looks up the message type in a hash table to get the interested > NetworkModule, but I was thinking that would not be amenable to a > situation where more than one module is interested in the message. > I'm thinking that in such situations, every interested module would > receive an identical copy of the message (in no particular order... they > should be considered simultaneous, even though it is likely they will > execute in sequence) and do with it whatever the module considers > appropriate. > > Am I out to lunch on this? Or should I just go back to bed and stop > losing sleep over it? > > >> Mark > > > _______________________________________________ > Openrpg-v2-dev mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openrpg-v2-dev > -- Dj Gilcrease OpenRPG Developer ~~http://www.openrpg.com OpenRPG++ Lead Developer ~~http://www.digitalxero.net XeroWiki Creator ~~http://www.digitalxero.net Web Admin for Thewarcouncil.us ~~http://www.thewarcouncil.us |
From: Mark T. <ma...@ly...> - 2006-06-15 09:39:25
|
I was lying awake tonight thinking about the message routing system, and I wasn't sure if this was brought up before, but I'm not sure if the existing system allows for something in particular: I'm thinking of situations where potentially more than one module might be interested in a particular message. As it sits, it seems it just looks up the message type in a hash table to get the interested NetworkModule, but I was thinking that would not be amenable to a situation where more than one module is interested in the message. I'm thinking that in such situations, every interested module would receive an identical copy of the message (in no particular order... they should be considered simultaneous, even though it is likely they will execute in sequence) and do with it whatever the module considers appropriate. Am I out to lunch on this? Or should I just go back to bed and stop losing sleep over it? >> Mark |
From: <sno...@us...> - 2006-06-06 21:26:34
|
Revision: 71 Author: snowdog_ Date: 2006-06-06 14:25:58 -0700 (Tue, 06 Jun 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=71&view=rev Log Message: ----------- Merging in SF Patch # 1501818 (Dice rolling package fixup) for Mark Tarrabain Modified Paths: -------------- trunk/src/openrpg2/common/dice/AddExpr.java trunk/src/openrpg2/common/dice/BinaryExpr.java trunk/src/openrpg2/common/dice/ConstExpr.java trunk/src/openrpg2/common/dice/Dice.java trunk/src/openrpg2/common/dice/DiceParser.java trunk/src/openrpg2/common/dice/DivExpr.java trunk/src/openrpg2/common/dice/FuncExpr.java trunk/src/openrpg2/common/dice/Function.java trunk/src/openrpg2/common/dice/GroupValue.java trunk/src/openrpg2/common/dice/HighestFunc.java trunk/src/openrpg2/common/dice/IntValue.java trunk/src/openrpg2/common/dice/LowestFunc.java trunk/src/openrpg2/common/dice/MaxFunc.java trunk/src/openrpg2/common/dice/MinFunc.java trunk/src/openrpg2/common/dice/MultExpr.java trunk/src/openrpg2/common/dice/NegExpr.java trunk/src/openrpg2/common/dice/StrValue.java Added Paths: ----------- trunk/src/openrpg2/common/dice/DiceExpr.java trunk/src/openrpg2/common/dice/DiceValue.java Removed Paths: ------------- trunk/src/openrpg2/common/dice/Die.java trunk/src/openrpg2/common/dice/Expr.java Modified: trunk/src/openrpg2/common/dice/AddExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/AddExpr.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/AddExpr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -26,7 +26,7 @@ * @author markt */ public class AddExpr extends BinaryExpr { - private Expr x,y; + private DiceExpr x,y; private char join; /** * Creates a new instance of AddExpr @@ -34,7 +34,7 @@ * @param b The right hand parameter * @param j The type of operation ('+' or '-') */ - public AddExpr(Expr a,Expr b,char j) { + public AddExpr(DiceExpr a,DiceExpr b,char j) { super(a,b,j); x=a; y=b; Modified: trunk/src/openrpg2/common/dice/BinaryExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/BinaryExpr.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/BinaryExpr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -24,12 +24,12 @@ * Base class for binary operators * @author markt */ -public class BinaryExpr extends Expr { - protected Expr x; +public class BinaryExpr extends DiceExpr { + protected DiceExpr x; /** * Right hand argument */ - protected Expr y; + protected DiceExpr y; /** * Operator character */ @@ -40,7 +40,7 @@ * @param b Right hand parameter * @param c The operator to join them */ - public BinaryExpr(Expr a,Expr b,char c) { + public BinaryExpr(DiceExpr a,DiceExpr b,char c) { x=a; y=b; join=c; Modified: trunk/src/openrpg2/common/dice/ConstExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/ConstExpr.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/ConstExpr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -24,7 +24,7 @@ * Constant expression, either an integer or string * @author markt */ -public class ConstExpr extends Expr { +public class ConstExpr extends DiceExpr { /** * Creates a new instance of ConstExpr as a string. Modified: trunk/src/openrpg2/common/dice/Dice.java =================================================================== --- trunk/src/openrpg2/common/dice/Dice.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/Dice.java 2006-06-06 21:25:58 UTC (rev 71) @@ -28,7 +28,7 @@ * Class for managing a group of identical dice * @author markt */ -public class Dice extends Expr { +public class Dice extends DiceExpr { private int num; private Die die; private Vector sides; @@ -118,7 +118,7 @@ * Rolls all the dice in this expression */ public void roll() { - Value[] vals=new Value[num]; + DiceValue[] vals=new DiceValue[num]; for(int i=0;i<num;i++) { String s=(String)sides.get(getRandom().nextInt(sides.size())); if (isint) Added: trunk/src/openrpg2/common/dice/DiceExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/DiceExpr.java (rev 0) +++ trunk/src/openrpg2/common/dice/DiceExpr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -0,0 +1,90 @@ +/* + * DiceExpr.java + * + * Created on April 2, 2006, 3:00 PM + * + * ==================================================================== + * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License on www.gnu.org for more details. + * ==================================================================== + */ + +package openrpg2.common.dice; + +/** + * Base class forming the root of all possible expressions in this package + * @author markt + */ +public class DiceExpr { + /** + * The base value, to be determined once dice are rolled + */ + protected DiceValue value; + /** + * Default constructor. Basic initialization. + */ + protected DiceExpr() { + value=null; + } + /** + * gets the value associated with this expression after rolling any dice in it + * @return the value associated with this expression + */ + public DiceValue getValue() { + return value; + } + /** + * gets the details of this expression + * @return the details of this expression + */ + public String getDetails() { + return getValue().toString(); + } + /** + * whether or not this expression is an integer + * @return true if an integer, false otherwise + */ + public boolean isInt() { + return false; + } + /** + * gets the size of this expression + * @return the number of subelements in this expression, or 0 if atomic. + */ + public int getSize() { + return 0; + } + /** + * Rolls all the dice in this expression + */ + public void roll() { + } + /** + * Gets the integer value of this expression after rolling the dice + * @return the integer value for this expression. 0 if it is not an integer. + */ + public int getIntValue() { + try { + return Integer.parseInt(value.getBaseValue().toString()); + } + catch(NumberFormatException e) { + return 0; + } + } + /** + * Gets the string form of the value for this expression after rollind dice + * @return a string showing the value of this expression + */ + public String getStrValue() { + return value.getBaseValue().toString(); + } +} Property changes on: trunk/src/openrpg2/common/dice/DiceExpr.java ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/src/openrpg2/common/dice/DiceParser.java =================================================================== --- trunk/src/openrpg2/common/dice/DiceParser.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/DiceParser.java 2006-06-06 21:25:58 UTC (rev 71) @@ -62,9 +62,9 @@ * 1) Create a class that extends the abstract Function class in this package. * 2) Implement the following functions in the Function decendant: * a) a constructor that calls super(name) as its first instruction - * b) void getSize(Expr[] exprs) - * c) void isInt(Expr[] exprs) - * d) Value exec(Value[] vals) + * b) void getSize(DiceExpr[] exprs) + * c) void isInt(DiceExpr[] exprs) + * d) DiceValue exec(DiceValue[] vals) * 3) create an instance of the class defined in step 2 * 4) call parser.addFunction(name,instance) * The policy for creating new Die types is: @@ -77,7 +77,7 @@ * * Once created you can then reuse this DiceParser as often as you wish by * calling expr=parser.createDiceExpression(s), which takes the string to - * parse, and returns an instance of an Expr class. You can roll the dice in + * parse, and returns an instance of an DiceExpr class. You can roll the dice in * this expression by calling expr.roll(). Dice may be rerolled for a given * expression any number of times without having to reparse the original * string expression. expr.getDetails() returns a string that shows the @@ -194,11 +194,11 @@ * @param s The string to parse * @throws java.lang.NumberFormatException if an integer expresion within the string failed to parse correctly * @throws java.lang.IllegalArgumentException if the parameter failed to evaluate to a dice expression - * @return an instance of Expr that contains the dice expression. + * @return an instance of DiceExpr that contains the dice expression. */ - public Expr createDiceExpression(String s) throws IllegalArgumentException, NumberFormatException { + public DiceExpr createDiceExpression(String s) throws IllegalArgumentException, NumberFormatException { Scanner scanner=new Scanner(s); - Expr expr=scanner.parseExpr(); + DiceExpr expr=scanner.parseExpr(); if (scanner.token!=TEOF) throw new IllegalArgumentException("Expected end of expression"); return expr; @@ -372,8 +372,8 @@ } } - private Expr parseUnary(Reader in) { - Expr e=null; + private DiceExpr parseUnary(Reader in) { + DiceExpr e=null; if (token==TLPAR) { scan(); e=parseExpr(); @@ -404,8 +404,8 @@ if (token!=TRPAR) throw new IllegalArgumentException("Expecting ')'"); scan(); - Expr []exprs=new Expr[parms.size()]; - for(int i=0;i<exprs.length;i++) exprs[i]=(Expr)parms.get(i); + DiceExpr []exprs=new DiceExpr[parms.size()]; + for(int i=0;i<exprs.length;i++) exprs[i]=(DiceExpr)parms.get(i); e=new FuncExpr(func,exprs); } else if (token==TDICE) { Dice dice=new Dice(number,(Die)symbols.get(word)); @@ -473,7 +473,7 @@ return e; } - private Expr parseFactor() { + private DiceExpr parseFactor() { if (token==TMINUS) { scan(); if (token==TINT) { @@ -481,19 +481,19 @@ scan(); return result; } else { - Expr e=parseUnary(in); + DiceExpr e=parseUnary(in); return new NegExpr(e); } } else return parseUnary(in); } - private Expr parseTerm() { - Expr e=parseFactor(); + private DiceExpr parseTerm() { + DiceExpr e=parseFactor(); while(token==TSTAR || token==TSLASH) { char c=(token==TSTAR?'*':'/'); scan(); - Expr f=parseFactor(); + DiceExpr f=parseFactor(); if (c=='*') e=new MultExpr(e,f); else @@ -502,12 +502,12 @@ return e; } - public Expr parseExpr() { - Expr e=parseTerm(); + public DiceExpr parseExpr() { + DiceExpr e=parseTerm(); while(token==TPLUS || token==TMINUS) { char c=(token==TPLUS?'+':'-'); scan(); - Expr f=parseTerm(); + DiceExpr f=parseTerm(); e=new AddExpr(e,f,c); } return e; Added: trunk/src/openrpg2/common/dice/DiceValue.java =================================================================== --- trunk/src/openrpg2/common/dice/DiceValue.java (rev 0) +++ trunk/src/openrpg2/common/dice/DiceValue.java 2006-06-06 21:25:58 UTC (rev 71) @@ -0,0 +1,43 @@ +/* + * DiceValue.java + * + * Created on April 2, 2006, 2:48 PM + * + * ==================================================================== + * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License on www.gnu.org for more details. + * ==================================================================== + */ + +package openrpg2.common.dice; + +/** + * Base interface defining the api for all values used by the dice package + * @author markt + */ +public interface DiceValue { + /** + * Determines whether or not this value is an integer + * @return true if an integer, false otherwise + */ + public boolean isInt(); + /** + * Gets the number of elements in this value. + * @return the number of elements in this value ( 0 means that the value is atomic ) + */ + public int getSize(); + /** + * Gets the base for this value (ie, all groups are evaluated to atomic values). + * @return a base value that represents this value after it is fully evaluated + */ + public DiceValue getBaseValue(); +} Property changes on: trunk/src/openrpg2/common/dice/DiceValue.java ___________________________________________________________________ Name: svn:eol-style + native Deleted: trunk/src/openrpg2/common/dice/Die.java =================================================================== --- trunk/src/openrpg2/common/dice/Die.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/Die.java 2006-06-06 21:25:58 UTC (rev 71) @@ -1,39 +0,0 @@ -/* - * Die.java - * - * Created on April 3, 2006, 6:15 PM - * - * ==================================================================== - * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License on www.gnu.org for more details. - * ==================================================================== - */ -package openrpg2.common.dice; - -import java.util.Vector; - -/** - * Interface that specifies the minimum functionality for a die - * @author markt - */ -public interface Die { - /** - * Gets the list of values on the different sides of the die - * @return a vector of Strings each containing the label on one side of the die - */ - public Vector getSides(); - /** - * gets the name of the die - * @return the name of the die - */ - public String getName(); -} Modified: trunk/src/openrpg2/common/dice/DivExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/DivExpr.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/DivExpr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -33,7 +33,7 @@ * @param a Dividend * @param b Divisor */ - public DivExpr(Expr a,Expr b) { + public DivExpr(DiceExpr a,DiceExpr b) { super(a,b,'/'); if (!(b instanceof ConstExpr && b.isInt())) throw new IllegalArgumentException("Cannot divide by anything other than integer constants"); Deleted: trunk/src/openrpg2/common/dice/Expr.java =================================================================== --- trunk/src/openrpg2/common/dice/Expr.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/Expr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -1,90 +0,0 @@ -/* - * Expr.java - * - * Created on April 2, 2006, 3:00 PM - * - * ==================================================================== - * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License on www.gnu.org for more details. - * ==================================================================== - */ - -package openrpg2.common.dice; - -/** - * Base class forming the root of all possible expressions in this package - * @author markt - */ -public class Expr { - /** - * The base value, to be determined once dice are rolled - */ - protected Value value; - /** - * Default constructor. Basic initialization. - */ - protected Expr() { - value=null; - } - /** - * gets the value associated with this expression after rolling any dice in it - * @return the value associated with this expression - */ - public Value getValue() { - return value; - } - /** - * gets the details of this expression - * @return the details of this expression - */ - public String getDetails() { - return getValue().toString(); - } - /** - * whether or not this expression is an integer - * @return true if an integer, false otherwise - */ - public boolean isInt() { - return false; - } - /** - * gets the size of this expression - * @return the number of subelements in this expression, or 0 if atomic. - */ - public int getSize() { - return 0; - } - /** - * Rolls all the dice in this expression - */ - public void roll() { - } - /** - * Gets the integer value of this expression after rolling the dice - * @return the integer value for this expression. 0 if it is not an integer. - */ - public int getIntValue() { - try { - return Integer.parseInt(value.getBaseValue().toString()); - } - catch(NumberFormatException e) { - return 0; - } - } - /** - * Gets the string form of the value for this expression after rollind dice - * @return a string showing the value of this expression - */ - public String getStrValue() { - return value.getBaseValue().toString(); - } -} Modified: trunk/src/openrpg2/common/dice/FuncExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/FuncExpr.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/FuncExpr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -24,8 +24,8 @@ * Function expressions, of the form id(parm,parm,...) * @author markt */ -public class FuncExpr extends Expr { - private Expr []exprs; +public class FuncExpr extends DiceExpr { + private DiceExpr[]exprs; private Function func; private int size; private boolean isint; @@ -34,9 +34,9 @@ * @param f The function to create * @param e The list of expression parameters to the function */ - public FuncExpr(Function f,Expr []e) { + public FuncExpr(Function f,DiceExpr[]e) { func=f; - if (e==null) exprs=new Expr[0]; + if (e==null) exprs=new DiceExpr[0]; else exprs=e; size=func.getSize(exprs); isint=func.isInt(exprs); @@ -57,7 +57,7 @@ * Rolls any dice in this expression */ public void roll() { - Value[] vals=new Value[exprs.length]; + DiceValue[] vals=new DiceValue[exprs.length]; for(int i=0;i<exprs.length;i++) { exprs[i].roll(); vals[i]=exprs[i].getValue(); Modified: trunk/src/openrpg2/common/dice/Function.java =================================================================== --- trunk/src/openrpg2/common/dice/Function.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/Function.java 2006-06-06 21:25:58 UTC (rev 71) @@ -61,7 +61,7 @@ * @param expr the parameters to this expression * @return the number of elements that this function will return */ - public abstract int getSize(Expr[] expr); + public abstract int getSize(DiceExpr[] expr); /** * Determines if the expression is an integer or not * This function will also be called when the expression is first parsed, @@ -76,7 +76,7 @@ * @param exprs the parameters to this function * @return true if an integer, false otherwise */ - public abstract boolean isInt(Expr[] exprs); + public abstract boolean isInt(DiceExpr[] exprs); /** * Executes the function. * This function should actually do whatever the function is normally @@ -93,14 +93,14 @@ * @param vals The values to pass to this function (already evaluated) * @return The result of the function */ - public abstract Value exec(Value []vals); + public abstract DiceValue exec(DiceValue[]vals); /** * utility function which can be called by subclasses to compare values * @param a Arg1 * @param b Arg2 * @return Returns negative if Arg1 < Arg2, positive if Arg1 > Arg2, and 0 if equal */ - public static int compareTo(Value a,Value b) { + public static int compareTo(DiceValue a,DiceValue b) { String x=a.getBaseValue().toString(); String y=b.getBaseValue().toString(); if (a.isInt() && b.isInt()) Modified: trunk/src/openrpg2/common/dice/GroupValue.java =================================================================== --- trunk/src/openrpg2/common/dice/GroupValue.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/GroupValue.java 2006-06-06 21:25:58 UTC (rev 71) @@ -24,14 +24,14 @@ * Defines a collection of values * @author markt */ -public class GroupValue implements Value { - private Value[] values; +public class GroupValue implements DiceValue { + private DiceValue[] values; /** * Creates a new instance of GroupValue * @param v List of values to put in this group */ - public GroupValue(Value[] v) { - if (v==null) values=new Value[0]; + public GroupValue(DiceValue[] v) { + if (v==null) values=new DiceValue[0]; else values=v; } /** @@ -49,7 +49,7 @@ * Gets the list of values in this group * @return the list of values in this group */ - public Value[] getValues() { + public DiceValue[] getValues() { return values; } /** @@ -73,7 +73,7 @@ * Gets the base value for this expression * @return the base value for this expression */ - public Value getBaseValue() { + public DiceValue getBaseValue() { if (isInt()) { int n=0; for(int i=0;i<values.length;i++) Modified: trunk/src/openrpg2/common/dice/HighestFunc.java =================================================================== --- trunk/src/openrpg2/common/dice/HighestFunc.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/HighestFunc.java 2006-06-06 21:25:58 UTC (rev 71) @@ -38,7 +38,7 @@ * @param exprs The arguments to the function * @return true if function returns an integer, false otherwise */ - public boolean isInt(Expr[] exprs) { + public boolean isInt(DiceExpr[] exprs) { return exprs[1].isInt(); } /** @@ -46,7 +46,7 @@ * @param expr The arguments to this function * @return The number of elements selected */ - public int getSize(Expr[] expr) { + public int getSize(DiceExpr[] expr) { if (expr.length!=2) throw new IllegalArgumentException("Expecting two arguments to 'highest' function"); if (!(expr[0] instanceof ConstExpr && expr[0].isInt())) @@ -64,10 +64,10 @@ * @param vals The parameters to the function after evaluation * @return the result of the function */ - public Value exec(Value[] vals) { + public DiceValue exec(DiceValue[] vals) { int num=Integer.parseInt(vals[0].getBaseValue().toString()); - Value[] group=((GroupValue)vals[1]).getValues(); - Value []result=new Value[num]; + DiceValue[] group=((GroupValue)vals[1]).getValues(); + DiceValue []result=new DiceValue[num]; boolean[] take=new boolean[group.length]; for(int i=0;i<take.length;i++) take[i]=false; int len=group.length; Modified: trunk/src/openrpg2/common/dice/IntValue.java =================================================================== --- trunk/src/openrpg2/common/dice/IntValue.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/IntValue.java 2006-06-06 21:25:58 UTC (rev 71) @@ -24,7 +24,7 @@ * An integer value * @author markt */ -public class IntValue implements Value { +public class IntValue implements DiceValue { private int value; /** * Creates a new instance of IntValue @@ -54,7 +54,7 @@ * Gets the base value for this value * @return this */ - public Value getBaseValue() { + public DiceValue getBaseValue() { return this; } Modified: trunk/src/openrpg2/common/dice/LowestFunc.java =================================================================== --- trunk/src/openrpg2/common/dice/LowestFunc.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/LowestFunc.java 2006-06-06 21:25:58 UTC (rev 71) @@ -38,7 +38,7 @@ * @param exprs Parameters to this function * @return true if an integer, false otherwise */ - public boolean isInt(Expr[] exprs) { + public boolean isInt(DiceExpr[] exprs) { return exprs[1].isInt(); } /** @@ -46,7 +46,7 @@ * @param expr The (unevaluated) expressions in this function. * @return the number of elements selected */ - public int getSize(Expr[] expr) { + public int getSize(DiceExpr[] expr) { if (expr.length!=2) throw new IllegalArgumentException("Expecting two arguments to 'lowest' function"); if (!(expr[0] instanceof ConstExpr && expr[0].isInt())) @@ -62,10 +62,10 @@ * @param vals The arguments to the function * @return The result of the function */ - public Value exec(Value[] vals) { + public DiceValue exec(DiceValue[] vals) { int num=Integer.parseInt(vals[0].getBaseValue().toString()); - Value[] group=((GroupValue)vals[1]).getValues(); - Value []result=new Value[num]; + DiceValue[] group=((GroupValue)vals[1]).getValues(); + DiceValue []result=new DiceValue[num]; boolean[] take=new boolean[group.length]; for(int i=0;i<take.length;i++) take[i]=false; int len=group.length; Modified: trunk/src/openrpg2/common/dice/MaxFunc.java =================================================================== --- trunk/src/openrpg2/common/dice/MaxFunc.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/MaxFunc.java 2006-06-06 21:25:58 UTC (rev 71) @@ -35,7 +35,7 @@ * @param exprs Arguments to the function * @return true if result is an integer, false otherwise */ - public boolean isInt(Expr[] exprs) { + public boolean isInt(DiceExpr[] exprs) { boolean r=true; if (exprs.length<1) for(int i=0;r && i<exprs.length;i++) @@ -47,8 +47,8 @@ * @param vals arguments to the function * @return maximum argument listed in vals */ - public Value exec(Value []vals) { - Value result=null; + public DiceValue exec(DiceValue[]vals) { + DiceValue result=null; for(int i=0;i<vals.length;i++) if (result==null || compareTo(vals[i],result)>0) result=vals[i]; return result; @@ -59,7 +59,7 @@ * @param exprs arguments to this function * @return 0, always */ - public int getSize(Expr[] exprs) { + public int getSize(DiceExpr[] exprs) { if (exprs.length<1) throw new IllegalArgumentException("Expecting at least one value "); return 0; Modified: trunk/src/openrpg2/common/dice/MinFunc.java =================================================================== --- trunk/src/openrpg2/common/dice/MinFunc.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/MinFunc.java 2006-06-06 21:25:58 UTC (rev 71) @@ -35,7 +35,7 @@ * @param exprs arguments to this function * @return true if an integer, false otherwise */ - public boolean isInt(Expr[] exprs) { + public boolean isInt(DiceExpr[] exprs) { boolean r=true; if (exprs.length<1) for(int i=0;r && i<exprs.length;i++) @@ -47,8 +47,8 @@ * @param vals the arguments to the function * @return minimum value specified in vals */ - public Value exec(Value []vals) { - Value result=null; + public DiceValue exec(DiceValue[]vals) { + DiceValue result=null; for(int i=0;i<vals.length;i++) if (result==null || compareTo(vals[i],result)<0) result=vals[i]; return result; @@ -59,7 +59,7 @@ * @param exprs The arguments to this function * @return 0, always */ - public int getSize(Expr[] exprs) { + public int getSize(DiceExpr[] exprs) { if (exprs.length<1) throw new IllegalArgumentException("Expecting at least one value "); return 0; Modified: trunk/src/openrpg2/common/dice/MultExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/MultExpr.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/MultExpr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -30,7 +30,7 @@ * @param a Multiplicand * @param b Multiplier */ - public MultExpr(Expr a,Expr b) { + public MultExpr(DiceExpr a,DiceExpr b) { super(a,b,'*'); if (!x.isInt() || !y.isInt()) throw new IllegalArgumentException("Cannot multiply non integers"); Modified: trunk/src/openrpg2/common/dice/NegExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/NegExpr.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/NegExpr.java 2006-06-06 21:25:58 UTC (rev 71) @@ -24,13 +24,13 @@ * Negation expression, a normal expression preceeded by a unary - sign * @author markt */ -public class NegExpr extends Expr { - private Expr expr; +public class NegExpr extends DiceExpr { + private DiceExpr expr; /** * Creates a new instance of NegExpr * @param e The expression to be negated. Must be an integer expression */ - public NegExpr(Expr e) { + public NegExpr(DiceExpr e) { expr=e; if (!e.isInt()) throw new IllegalArgumentException("Cannot negate a non-integer expression"); Modified: trunk/src/openrpg2/common/dice/StrValue.java =================================================================== --- trunk/src/openrpg2/common/dice/StrValue.java 2006-05-30 21:41:49 UTC (rev 70) +++ trunk/src/openrpg2/common/dice/StrValue.java 2006-06-06 21:25:58 UTC (rev 71) @@ -24,7 +24,7 @@ * A value representing a string * @author markt */ -public class StrValue implements Value { +public class StrValue implements DiceValue { private String value; /** * Creates a new instance of StrValue @@ -54,7 +54,7 @@ * Gets the base value for this expression * @return this */ - public Value getBaseValue() { + public DiceValue getBaseValue() { return this; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2006-05-30 21:41:53
|
Revision: 70 Author: snowdog_ Date: 2006-05-30 14:41:49 -0700 (Tue, 30 May 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=70&view=rev Log Message: ----------- Merging in SF Patch # 1495963 (Dice rolling package restructuring) for Mark Tarrabain Modified Paths: -------------- trunk/src/openrpg2/common/dice/DiceParser.java trunk/src/openrpg2/common/dice/Expr.java Modified: trunk/src/openrpg2/common/dice/DiceParser.java =================================================================== --- trunk/src/openrpg2/common/dice/DiceParser.java 2006-05-26 21:38:09 UTC (rev 69) +++ trunk/src/openrpg2/common/dice/DiceParser.java 2006-05-30 21:41:49 UTC (rev 70) @@ -25,91 +25,90 @@ /** * Class that parses a string to return an expression used by this package - * + * * Current implementation only understands numeric dice, but arbitrary labelled - * dice can be added by using the addDice() call and implementing the Die + * dice can be added by using the addDice() call and implementing the Die * interface. * Default implemented functions include min(...) which selects the minimum - * of its arguments, max(...) which selects the max of its arguments, + * of its arguments, max(...) which selects the max of its arguments, * highest(#,group) which selects the highest # dice in the group and * lowest(#,group) which selects the lowest # dice in the group. - * highest and lowest functions can be used anywhere a group expression may + * highest and lowest functions can be used anywhere a group expression may * be used. Also, there are individual dice checking functions min, max, * and reroll, which specify minimum values, maximum values, and values to * reroll on for each individual die. Viewing the details of a dice roll * does not show these individual functions, since the dice are already rolled. - * + * * An example expression might be * highest(3,4d6.reroll(1)) - * which rolls 4 six-sided dice, rerolling any 1's, and then takes the highest 3 - * of them. Calling the getDetails method of diceParser might return, for example: + * which rolls 4 six-sided dice, rerolling any 1's, and then takes the highest 3 + * of them. Calling the getDetails method of the expression created might + * return, for example: * highest(3,[4,6,3,1]) - * and calling getFinalValue() would return in this case "13", since that is the - * sum of the three highest dice rolls. - * - * Additional functions can be created by extending the abstract Function class - * in this package and implementing the abstract methods. They can be added - * to the DiceParser's symbol table by calling addFunction(). - * + * and calling getStrValue() on the expression would return in this case "13", + * since that is the sum of the three highest dice rolls. + * + * Symbols (either die types or functions) can be removed from the symbol + * table by calling clearSymbol(name). Removing standard numeric dice (that + * is die types appearing like d#), will have no effect. + * + * To use this class, create an instance of it by calling + * parser=new DiceParser() + * This creates a standard parser with the default functions that are supported + * ready to be used, and no die types supported beyond the regular numeric die + * types. If new functions or die types are desired, they may be added at this + * time as follows: * The policy for defining new functions is: - * 1) Create a class that extends the abstract Function class in this package. - * 2) Implement the following functions in the Function decendant: + * 1) Create a class that extends the abstract Function class in this package. + * 2) Implement the following functions in the Function decendant: * a) a constructor that calls super(name) as its first instruction * b) void getSize(Expr[] exprs) * c) void isInt(Expr[] exprs) * d) Value exec(Value[] vals) * 3) create an instance of the class defined in step 2 - * 4) call the static function DiceParser.addFunction(name,instance) - * - * Additional Die types can be created by implementing the Die interface in this - * package. New Die type ars added to the DiceParser's symbol tgable by calling - * addDice(). - * + * 4) call parser.addFunction(name,instance) * The policy for creating new Die types is: * 1) Create a class that implements the Die interface from this package. * 2) Implement the following functions the the Die decendant: * a) Vector getSides() * b) String getName() * 3) Create an instance of the class defined in step 2 - * 4) call the static function DiceParser.addDice(name,instance) - * - * Symbols (either die types or functions) can be removed from the symbol - * table by calling clearSymbol(name). Removing standard numeric dice (that - * is die types appearing like d#), will have no effect. - * - * To use this class, create an instance of it by calling - * dice=new DiceParser(string-expression) - * You can then reuse this diceparser as often as you wish by calling - * dice.getString(), which returns the original string expression that the - * constructor was called with; dice.roll(), which rolls any dice in the - * expression, dice.getDetails() which returns in the form of a string the - * details behind the most recent roll, and dice.getFinalValue() which returns - * in the form of a string the most recent roll fully evaluated as a single - * value. Calling getDetails() or getFinalValue() before calling roll will - * result in a NullPointerException. All parsing of the string is done in the - * constructor, so if the constructor does not fail by throwing either an - * IllegalArgumentException or NumberFormatException then the syntax for the - * Die was okay. - * - * Integer expressions are any sequence of digits (up to 6 digits long) and - * may be preceeded by a '-' sign. Strings are represented in the expression - * by a doublequote followed by any number of characters except a doublequote. - * Double quotes may be put into string expressions by using two doublequotes - * in a row (sort of like Pascal, but with doublequotes instead of single - * quotes). Whitespace outside of a string is ignored by the parser. An id - * is any uninterrupted sequence of alphanumeric characters beginning with a - * letter. - * + * 4) call parser.addDice(name,instance) + * + * Once created you can then reuse this DiceParser as often as you wish by + * calling expr=parser.createDiceExpression(s), which takes the string to + * parse, and returns an instance of an Expr class. You can roll the dice in + * this expression by calling expr.roll(). Dice may be rerolled for a given + * expression any number of times without having to reparse the original + * string expression. expr.getDetails() returns a string that shows the + * details of the most recent roll for that expression, and dice.getStrValue() + * returns a string that summarizes the value rolled. All parsing of the string + * is done within the call to createDiceExpression, so if that function does not + * fail by throwing either an IllegalArgumentException or NumberFormatException + * then the syntax for the dice expression was okay and the dice in it can be + * safely rolled any number of times. Division is only accepted by constants, + * so there is no chance of an unexpected division by 0 error. + * + * Integer expressions are any sequence of digits and may be preceeded by a '-' + * sign. Strings are represented in the expression by a doublequote followed + * by any number of characters except a doublequote. Double quotes may be put + * into string expressions by using two doublequotes in a row (sort of like + * Pascal, but with doublequotes instead of single quotes). There are no + * string manipulation functions in the standard parser, but they may be added + * as desired. Whitespace outside of a string is ignored by the parser. + * An id is any uninterrupted sequence of alphanumeric characters outside of a + * string that begins with a letter. + * * I am not entirely sure how to best explain the syntax for dice expressions * in plain english, but I can fairly easily present an explanation in EBNF. - * I'll attempt to annotate each line of the EBNF, but if somebody else can - * translate this into more humanly readable form, feel free to do so. + * I'll attempt to annotate each line of the EBNF, but if somebody else can + * translate this into more humanly readable form, feel free to do so. * * expression: term-expression ( '+'|'-' term-expression )* - * an expression can be an arbitrarily long sequence of sub-expressions that + * an expression can be an arbitrarily long sequence of sub-expressions that * are separated by either a plus or minus sign * term-expression: factor-expression ( '*'|'/' factor-expression )* - * this can be an arbitrarily long sequence of sub-expressions that are + * this can be an arbitrarily long sequence of sub-expressions that are * separated by a star or slash. Star represents multiplication, slash * represents division. The right hand side of a division operation must * be a constant integer expression. @@ -124,10 +123,10 @@ * expression, followed by 0 or more modifiers, or a function call * dice: [ integer ] 'd'|'D' [ integer ] | * [ integer ] id - * a dice expression is an optional integer followed by a symbol that + * a dice expression is an optional integer followed by a symbol that * represents that die type. Standard numeric dice are represented via the * convention D# notation, which is automatically understood by the parser. - * other id's are only recognized as dice if they were added to the + * other id's are only recognized as dice if they were added to the * DiceParser class's symbol table via an addDice call. Groups of non-numeric * dice, if evaluated to one value, are the concatenation of the values within * it, separated by a single space. @@ -145,8 +144,8 @@ * display of the dice roll, and the originally rolled value can be lost. If * you need to see it, use either the 'min' or 'max' function calls that can * be applied to an entire expression, and not individual dice. - * * + * * @author markt */ public class DiceParser { @@ -170,11 +169,16 @@ private static final Token TMAX=new Token(); private static final Token TREROLL=new Token(); - private static Hashtable symbols=new Hashtable(); + private Hashtable symbols=new Hashtable(); // for holding special die-specific functions. - private static Hashtable dicetable=new Hashtable(); + private Hashtable dicetable=new Hashtable(); - static { + + /** + * Creates a new instance of DiceParser + */ + public DiceParser() { + // add capabilities common to all DiceParser objects dicetable.put("min",TMIN); dicetable.put("max",TMAX); dicetable.put("reroll",TREROLL); @@ -185,361 +189,328 @@ addFunction("max",new MaxFunc()); } - private Reader in; - private String input; - private Token temptoken=null; - private Token token; - private String word; - private int number; - private int nc=-1; - private Expr expr; - /** - * Creates a new instance of DiceParser + * Creates a new dice Expression * @param s The string to parse * @throws java.lang.NumberFormatException if an integer expresion within the string failed to parse correctly * @throws java.lang.IllegalArgumentException if the parameter failed to evaluate to a dice expression + * @return an instance of Expr that contains the dice expression. */ - public DiceParser(String s) throws IllegalArgumentException, NumberFormatException { - in=new StringReader(s); - input=s; - nc=-1; - scan(); - expr=parseExpr(); - if (token!=TEOF) + public Expr createDiceExpression(String s) throws IllegalArgumentException, NumberFormatException { + Scanner scanner=new Scanner(s); + Expr expr=scanner.parseExpr(); + if (scanner.token!=TEOF) throw new IllegalArgumentException("Expected end of expression"); + return expr; } /** * Adds a type of Die to the parser's symbol table * @param name Name of die (d6, weather, etc) - * * @param die The type of die that has this name */ - public static void addDice(String name,Die die) { + public void addDice(String name,Die die) { symbols.put(name,die); } /** - * Removes a symbol from the parser's symbol table - * @param name symbol to remove - */ - public static void clearSymbol(String name) { - symbols.remove(name); - } - - /** * Adds a function to the parser's symbol table * @param name the name of the function * @param func the Function decendant class that implements the function */ - public static void addFunction(String name,Function func) { + public void addFunction(String name,Function func) { symbols.put(name,func); } /** - * Gets the string that created this DiceParser - * @return the original string that was passed into the constructor + * Removes a symbol from the parser's symbol table + * @param name symbol to remove */ - - public String getString() { - return input; + public void clearSymbol(String name) { + symbols.remove(name); } - - /** - * Gets the details for the expression after rolling any dice in it. This - * function tries to preserve all die rolls in the original expression, - * showing exactly which results were obtained in each dice expression. - * @return a string describing the dice rolls - */ - public String getDetails() { - return expr.getDetails(); - } - /** - * Gets the final value for the expression after rolling any dice - * @return a string describing the final result of this expression - */ - public String getFinalValue() { - return expr.getValue().getBaseValue().toString(); - } + // private helper functions below this point assist with parsing the + // string that is passed into the createDiceExpression function - /** - * rolls any dice found in this DiceParser's expression - */ - public void roll() { - expr.roll(); - } - private void scanInteger(char ch) { - number=Character.getNumericValue(ch)-Character.getNumericValue('0'); - try { - while((nc=in.read())!=-1 && Character.isDigit((char)nc)) - number=number*10+Character.getNumericValue((char)nc)-Character.getNumericValue('0'); - } catch(IOException e) { + private class Scanner { + Reader in; + int nc; + Token temptoken=null; + Token token; + int number; + String word; + + public Scanner(String s) { + in=new StringReader(s); + nc=-1; } - token=TINT; - } - - private void scanId(char ch) { - word=""+ch; - try { - while((nc=in.read())!=-1 && Character.isLetterOrDigit((char)nc)) - word=word+(char)nc; - } catch(IOException e) { - - } - token=TID; - } - - private boolean isDice() { - Object result=symbols.get(word); - // Parse expressions of the form 'd#' - if (result==null && word.length()>1 && (word.charAt(0)=='d' || word.charAt(0)=='D')) { - boolean good=true; - for(int j=1;good && j<word.length();j++) good=good&Character.isDigit(word.charAt(j)); - if (good) { - result=new NumberedDie(Integer.parseInt(word.substring(1))); - symbols.put(word,result); + private void scanInteger(char ch) { + number=Character.getNumericValue(ch)-Character.getNumericValue('0'); + try { + while((nc=in.read())!=-1 && Character.isDigit((char)nc)) + number=number*10+Character.getNumericValue((char)nc)-Character.getNumericValue('0'); + } catch(IOException e) { } + token=TINT; } - return (result!=null && result instanceof Die); - } - - private void scan() { - if (temptoken!=null) { - token=temptoken; - return; - } - int c; - char ch; - do { + + private void scanId(char ch) { + word=""+ch; try { - if (nc!=-1) c=nc; - else c=in.read(); + while((nc=in.read())!=-1 && Character.isLetterOrDigit((char)nc)) + word=word+(char)nc; + } catch(IOException e) { + } - catch(IOException e) { - token=TEOF; + token=TID; + } + + private boolean isDice() { + Object result=symbols.get(word); + // Parse expressions of the form 'd#' + if (result==null && word.length()>1 && (word.charAt(0)=='d' || word.charAt(0)=='D')) { + boolean good=true; + for(int j=1;good && j<word.length();j++) good=good&Character.isDigit(word.charAt(j)); + if (good) { + result=new NumberedDie(Integer.parseInt(word.substring(1))); + symbols.put(word,result); + } + } + return (result!=null && result instanceof Die); + } + + private void scan() { + if (temptoken!=null) { + token=temptoken; return; } - nc=-1; - if (c==-1) { - token=TEOF; + int c; + char ch; + do { + try { + if (nc!=-1) c=nc; + else c=in.read(); + } catch(IOException e) { + token=TEOF; + return; + } + nc=-1; + if (c==-1) { + token=TEOF; + return; + } + ch=(char)c; + } while(Character.isSpaceChar(ch)); + if (Character.isDigit(ch)) { + scanInteger(ch); + if (nc!=-1 && Character.isLetter((char)nc)) { + c=nc; + scanId((char)nc); + if (isDice()) + token=TDICE; + else { + temptoken=TID; + token=TINT; + } + } return; } - ch=(char)c; - } while(Character.isSpaceChar(ch)); - if (Character.isDigit(ch)) { - scanInteger(ch); - if (nc!=-1 && Character.isLetter((char)nc)) { - c=nc; - scanId((char)nc); - if (isDice()) + if (Character.isLetter(ch)) { + scanId(ch); + if (isDice()) { + number=1; token=TDICE; - else { - temptoken=TID; - token=TINT; } + return; } - return; - } - if (Character.isLetter(ch)) { - scanId(ch); - if (isDice()) { - number=1; - token=TDICE; + if (ch=='"') { + word=""; + try { + do { + while((c=in.read())!=-1 && c!=(int)'"') + word=word+(char)c; + nc=in.read(); + if (nc==(int)'"') + word=word+(char)nc; + } while (nc!=(int)'"'); + } catch(IOException e) { + } + token=TSTR; + return; } - return; - } - if (ch=='"') { - word=""; - try { - do { - while((c=in.read())!=-1 && c!=(int)'"') - word=word+(char)c; - nc=in.read(); - if (nc==(int)'"') - word=word+(char)nc; - } while (nc!=(int)'"'); + switch(ch) { + case '*': + token=TSTAR; + break; + case '/': + token=TSLASH; + break; + case '+': + token=TPLUS; + break; + case '-': + token=TMINUS; + break; + case '(': + token=TLPAR; + break; + case ')': + token=TRPAR; + break; + case ',': + token=TCOMMA; + break; + case '.': + token=TDOT; + break; + default: + token=TERROR; + break; + } - catch(IOException e) { - } - token=TSTR; - return; } - switch(ch) { - case '*': - token=TSTAR; - break; - case '/': - token=TSLASH; - break; - case '+': - token=TPLUS; - break; - case '-': - token=TMINUS; - break; - case '(': - token=TLPAR; - break; - case ')': - token=TRPAR; - break; - case ',': - token=TCOMMA; - break; - case '.': - token=TDOT; - break; - default: - token=TERROR; - break; - - } - } - - private Expr parseUnary() { - Expr e=null; - if (token==TLPAR) { - scan(); - e=parseExpr(); - if (token!=TRPAR) - throw new IllegalArgumentException("Expected ')'"); - scan(); - } else if (token==TINT) { - e=new ConstExpr(number); - scan(); - } - else if (token==TSTR) { - e=new ConstExpr(word); - scan(); - } - else if (token==TID) { - Function func=(Function)symbols.get(word); - if (func==null) - throw new IllegalArgumentException("Illegal Function Specification '"+word+"'"); - scan(); - if (token!=TLPAR) - throw new IllegalArgumentException("Expecting '('"); - scan(); - Vector parms=new Vector(); - if(token!=TERROR && token!=TRPAR) - parms.add(parseExpr()); - while(token==TCOMMA) { + + private Expr parseUnary(Reader in) { + Expr e=null; + if (token==TLPAR) { scan(); - parms.add(parseExpr()); - } - if (token!=TRPAR) - throw new IllegalArgumentException("Expecting ')'"); - scan(); - Expr []exprs=new Expr[parms.size()]; - for(int i=0;i<exprs.length;i++) exprs[i]=(Expr)parms.get(i); - e=new FuncExpr(func,exprs); - } else if (token==TDICE) { - Dice dice=new Dice(number,(Die)symbols.get(word)); - scan(); - String low=null,high=null; - Vector rerolls=new Vector(); - while(token==TDOT) { + e=parseExpr(); + if (token!=TRPAR) + throw new IllegalArgumentException("Expected ')'"); scan(); - if (token==TID) { - Token t=(Token)dicetable.get(word); - if (t==null) - throw new IllegalArgumentException("Invalid dice adjustment function"); + } else if (token==TINT) { + e=new ConstExpr(number); + scan(); + } else if (token==TSTR) { + e=new ConstExpr(word); + scan(); + } else if (token==TID) { + Function func=(Function)symbols.get(word); + if (func==null) + throw new IllegalArgumentException("Illegal Function Specification '"+word+"'"); + scan(); + if (token!=TLPAR) + throw new IllegalArgumentException("Expecting '('"); + scan(); + Vector parms=new Vector(); + if(token!=TERROR && token!=TRPAR) + parms.add(parseExpr()); + while(token==TCOMMA) { scan(); - if (token!=TLPAR) - throw new IllegalArgumentException("Expecting '('"); + parms.add(parseExpr()); + } + if (token!=TRPAR) + throw new IllegalArgumentException("Expecting ')'"); + scan(); + Expr []exprs=new Expr[parms.size()]; + for(int i=0;i<exprs.length;i++) exprs[i]=(Expr)parms.get(i); + e=new FuncExpr(func,exprs); + } else if (token==TDICE) { + Dice dice=new Dice(number,(Die)symbols.get(word)); + scan(); + String low=null,high=null; + Vector rerolls=new Vector(); + while(token==TDOT) { scan(); - if (token==TMINUS) { + if (token==TID) { + Token t=(Token)dicetable.get(word); + if (t==null) + throw new IllegalArgumentException("Invalid dice adjustment function"); scan(); - if (token!=TINT) - throw new IllegalArgumentException("Expecting integer"); - number=-number; - } - if (token==TINT) - word=""+number; - else if (token!=TSTR) - throw new IllegalArgumentException("Expecting constant"); - if (t==TMIN) { - if (low==null) low=word; - else throw new IllegalArgumentException("More than one 'min' specification"); + if (token!=TLPAR) + throw new IllegalArgumentException("Expecting '('"); scan(); - } else if (t==TMAX) { - if (high==null) high=word; - else throw new IllegalArgumentException("More than one 'max' specification"); - scan(); - } else if (t==TREROLL) { - rerolls.add(word); - scan(); - while(token==TCOMMA) { + if (token==TMINUS) { scan(); - if (token==TMINUS) { - scan(); - if (token!=TINT) - throw new IllegalArgumentException("Expecting integer"); - number=-number; - } - if (token==TINT) - word=""+number; - else if (token!=TSTR) - throw new IllegalArgumentException("Expecting constant"); + if (token!=TINT) + throw new IllegalArgumentException("Expecting integer"); + number=-number; + } + if (token==TINT) + word=""+number; + else if (token!=TSTR) + throw new IllegalArgumentException("Expecting constant"); + if (t==TMIN) { + if (low==null) low=word; + else throw new IllegalArgumentException("More than one 'min' specification"); + scan(); + } else if (t==TMAX) { + if (high==null) high=word; + else throw new IllegalArgumentException("More than one 'max' specification"); + scan(); + } else if (t==TREROLL) { rerolls.add(word); scan(); + while(token==TCOMMA) { + scan(); + if (token==TMINUS) { + scan(); + if (token!=TINT) + throw new IllegalArgumentException("Expecting integer"); + number=-number; + } + if (token==TINT) + word=""+number; + else if (token!=TSTR) + throw new IllegalArgumentException("Expecting constant"); + rerolls.add(word); + scan(); + } } + if (token!=TRPAR) + throw new IllegalArgumentException("Expecting ')'"); + scan(); + String[] rers=new String[rerolls.size()]; + for(int i=0;i<rers.length;i++) rers[i]=(String)rerolls.get(i); + dice.addRerolls(rers); } - if (token!=TRPAR) - throw new IllegalArgumentException("Expecting ')'"); + } + dice.setMinMax(low,high); + e=dice; + } + return e; + } + + private Expr parseFactor() { + if (token==TMINUS) { + scan(); + if (token==TINT) { + ConstExpr result=new ConstExpr(-number); scan(); - String[] rers=new String[rerolls.size()]; - for(int i=0;i<rers.length;i++) rers[i]=(String)rerolls.get(i); - dice.addRerolls(rers); + return result; + } else { + Expr e=parseUnary(in); + return new NegExpr(e); } + } else + return parseUnary(in); + } + + private Expr parseTerm() { + Expr e=parseFactor(); + while(token==TSTAR || token==TSLASH) { + char c=(token==TSTAR?'*':'/'); + scan(); + Expr f=parseFactor(); + if (c=='*') + e=new MultExpr(e,f); + else + e=new DivExpr(e,f); } - dice.setMinMax(low,high); - e=dice; + return e; } - return e; - } - - private Expr parseFactor() { - if (token==TMINUS) { - scan(); - if (token==TINT) { - ConstExpr result=new ConstExpr(-number); + + public Expr parseExpr() { + Expr e=parseTerm(); + while(token==TPLUS || token==TMINUS) { + char c=(token==TPLUS?'+':'-'); scan(); - return result; + Expr f=parseTerm(); + e=new AddExpr(e,f,c); } - else { - Expr e=parseUnary(); - return new NegExpr(e); - } - } else - return parseUnary(); - } - - private Expr parseTerm() { - Expr e=parseFactor(); - while(token==TSTAR || token==TSLASH) { - char c=(token==TSTAR?'*':'/'); - scan(); - Expr f=parseFactor(); - if (c=='*') - e=new MultExpr(e,f); - else - e=new DivExpr(e,f); + return e; } - return e; } - - private Expr parseExpr() { - Expr e=parseTerm(); - while(token==TPLUS || token==TMINUS) { - char c=(token==TPLUS?'+':'-'); - scan(); - Expr f=parseTerm(); - e=new AddExpr(e,f,c); - } - return e; - } } Modified: trunk/src/openrpg2/common/dice/Expr.java =================================================================== --- trunk/src/openrpg2/common/dice/Expr.java 2006-05-26 21:38:09 UTC (rev 69) +++ trunk/src/openrpg2/common/dice/Expr.java 2006-05-30 21:41:49 UTC (rev 70) @@ -86,5 +86,5 @@ */ public String getStrValue() { return value.getBaseValue().toString(); - } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Snowdog <sn...@ga...> - 2006-05-30 17:43:45
|
Dj Gilcrease wrote: > Re: Custom Layout Manager (2006-04-10) > http://sourceforge.net/mailarchive/message.php?msg_id=15365904 > > I dont know how open you all are to including other open source, or > even closed source frameworks into 2.x, but a quick search of docking > frameworks for Java lead me to one Open source MDI based framework, > and one closed source (MDI, SDI, Panel) based framework. > As Mark pointed out in his response close source should not be included in any open source project as it defeats the purpose and spirit of open source. With regard to using other open source libraries/frameworks within openrpg2. We'd like to avoid it if at all possible. We want to avoid situations that will lead us to 'version chasing' of other projects. We want to reduce OpenRPG2's reliance on other projects where possible. --Snowdog |
From: Mark T. <ma...@ly...> - 2006-05-27 17:22:22
|
JIDE cannot reasonably be used in a GPL project. While it's good that they are supportive of open source, their licensing policy for open source projects wouldn't be compatible with the GPL unless they were willing to supply all the source code, not limit the developers from redistributing all the source code, and further not limit anyone else from redistributing all the source code, which wouldn't make any sense at all for them to do, since the developers of JIDE have a special licensing policy for open source projects in the first place. >> Mark |
From: Dj G. <dig...@gm...> - 2006-05-27 12:53:57
|
Just finished reading though all of the Archive messages in the list and figured I would comment on a few of them Re: Sub modules (2006-04-01) http://sourceforge.net/mailarchive/message.php?msg_id=3D15284736 Message filtering order was an issue with a plugin I was trying to create that redirected the text from the main chat window to a tab, but that was the only issue I ever experienced where the order mattered. And this can be a non issue if the sub-module API is created to take this into account, or prevent it all together. Re: Custom Layout Manager (2006-04-10) http://sourceforge.net/mailarchive/message.php?msg_id=3D15365904 I dont know how open you all are to including other open source, or even closed source frameworks into 2.x, but a quick search of docking frameworks for Java lead me to one Open source MDI based framework, and one closed source (MDI, SDI, Panel) based framework. The open source one is part of another project, but just looking though their code does not appear to be too hard to extract so it would be usable by 2.x. You can find it http://relayirc.sourceforge.net/javadocs/org/relayirc/swingutil/MDIPanel.ht= ml The closed source one is specifically a Docking framework for swing and can be used in all three interface types that I have seen discussed on the list. They provide free use of the framework for Open source projects as long as you mention them stemware in the app. I was playing around with their Demos and looking at their code and the code is very similar to how the GUI code for 2.x is setup now, with a Manager class and modules registering with it, so it may not be too hard to implement. You can find it http://www.jidesoft.com/products/dock.htm <quote> Free License for Open Source Project JIDE Software has always been supportive of open source projects. Open source project developers can obtain free single developer licenses, allowing them to use JIDE products in their projects. Please contact sales department with the following information to apply for a free license. * Open source project name * Project web site * Which JIDE products you wish to use The free single developer license is exactly the same as the purchased single developer license, except for the following conditions. * You agree to have a link to our website on your web site and acknowledge the use of JIDE products after successfully integrating them into your project. * This license is tied to the open source project you applied for in your email. You cannot use this developer license in any other non-open-source projects. If you have any other open source projects, please apply for another free developer license. </quote> Anyway thats all I came up with after reading every message in the list :) --=20 Dj Gilcrease OpenRPG Developer ~~http://www.openrpg.com OpenRPG++ Lead Developer ~~http://www.digitalxero.net XeroWiki Creator ~~http://www.digitalxero.net Web Admin for Thewarcouncil.us ~~http://www.thewarcouncil.us |
From: Dj G. <dig...@gm...> - 2006-05-27 11:23:16
|
Well After talking with Snowdog I now completely understand why the switch to java was made and have decided to look into Java a bit. Looking though the code thats in SVN java seems very similar to C++ so it should not take me long to understand whats going on. Dont worry though I dont plan on doing any development on 2.x until I feel I wont be writing "Functional Pasta" (as my brother called the 1.x source code when he was helping me rewrite some of it) Anyway just figured I would drop a line to the list, since I had not registered on this list untill today, and let yall know I have have abandon the rewite of 1.x in Python. --=20 Dj Gilcrease OpenRPG Developer ~~http://www.openrpg.com OpenRPG++ Lead Developer ~~http://www.digitalxero.net XeroWiki Creator ~~http://www.digitalxero.net Web Admin for Thewarcouncil.us ~~http://www.thewarcouncil.us |
From: <sno...@us...> - 2006-05-26 21:38:15
|
Revision: 69 Author: snowdog_ Date: 2006-05-26 14:38:09 -0700 (Fri, 26 May 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=69&view=rev Log Message: ----------- Added log messages for operations. Reworked ORPGSettingManager to remove some redundant code. Modified Paths: -------------- trunk/src/openrpg2/common/core/ORPGSettingManager.java trunk/src/openrpg2/common/core/ORPGUserDirs.java Modified: trunk/src/openrpg2/common/core/ORPGSettingManager.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGSettingManager.java 2006-05-22 21:13:19 UTC (rev 68) +++ trunk/src/openrpg2/common/core/ORPGSettingManager.java 2006-05-26 21:38:09 UTC (rev 69) @@ -27,7 +27,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; -import openrpg2.common.core.ORPGUserDirs; +import java.util.logging.Logger; /** * ORPGSettingManager offers a simple interface to handle saving and loading of Properties for the current user. @@ -36,6 +36,8 @@ public class ORPGSettingManager { + static private Logger log = Logger.getLogger(ORPGSettingManager.class.getName()); + /** Creates a new instance of ORPGSetting */ public ORPGSettingManager() { } @@ -47,16 +49,11 @@ * @see ORPGUserDirs */ public static Properties loadSettings(String filename){ - Properties p = new Properties(); File pf = new File(ORPGUserDirs.getSettingDir(true)+filename); - if( pf.exists()){ - try { - p.load(new FileInputStream(pf)); - } catch (FileNotFoundException ex) { - ex.printStackTrace(); - } catch (IOException ex) { - ex.printStackTrace(); - } + Properties p = loadSettings(pf); + if( p == null){ + log.info("Using empty settings for \""+filename+"\""); + p = new Properties(); } return p; } @@ -69,17 +66,16 @@ * @return Properties Object. If the filename does not exist it will return the properties from the template file instead. If the template file cannot be used an empty properties object will be returned. */ public static Properties loadSettings(String filename, File template){ - Properties p = new Properties(); + File pf = new File(ORPGUserDirs.getSettingDir(true)+filename); - if( pf.exists()){ - p = loadSettings(filename); - } else { //load properties from template file - try { - p.load(new FileInputStream(template)); - } catch (FileNotFoundException ex) { - ex.printStackTrace(); - } catch (IOException ex) { - ex.printStackTrace(); + Properties p = loadSettings(pf); + if( p == null){ + log.info("Using default template file for \""+filename+"\" settings"); + //load properties from template + p = loadSettings(template); + if( p == null){ + log.info("Using empty settings for \""+filename+"\""); + p = new Properties(); } } return p; @@ -93,17 +89,40 @@ * @return Properties Object. Either the contents of the specified file or the default template properties object. */ public static Properties loadSettings(String filename, Properties template){ - Properties p = new Properties(); File pf = new File(ORPGUserDirs.getSettingDir(true)+filename); - if( pf.exists()){ - p = loadSettings(filename); - } else { //load properties from template + Properties p = loadSettings(pf); + if( p == null){ + log.info("Using default settings template for \""+filename+"\""); + //load properties from template p = template; } return p; } /** + * Attempts to load properties from the given File. + * + * @param File refference properties file + * @return Properties Object. Will return null if file not found. + */ + public static Properties loadSettings(File file){ + Properties p = new Properties(); + if( file.exists()){ + try { + p.load(new FileInputStream(file)); + } catch (FileNotFoundException ex) { + log.info("Setting file \""+file.getName()+"\" cannot be found."); + return null; + } catch (IOException ex) { + log.warning("IOException reading setting file \""+file.getName()+"\" ("+ex.getMessage()+")"); + ex.printStackTrace(); + return null; + } + } + return p; + } + + /** * Saves the supplied Properties object to the users OpenRPG2 settings directory using the supplied filename. In the event of a filename conflict the existing file will be overwritten. * @param p Properties object to save. * @param filename Simple filename to use when saving properties (ie. 'mysettings.properties'} Modified: trunk/src/openrpg2/common/core/ORPGUserDirs.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGUserDirs.java 2006-05-22 21:13:19 UTC (rev 68) +++ trunk/src/openrpg2/common/core/ORPGUserDirs.java 2006-05-26 21:38:09 UTC (rev 69) @@ -22,6 +22,7 @@ package openrpg2.common.core; import java.io.File; +import java.util.logging.Logger; /** * Group of static class methods for obtaining openrpg2 user paths. @@ -44,11 +45,12 @@ static private String orpg2settings = orpg2dir+File.separator+ORPG2_SETTINGS; static private String orpg2data = orpg2dir+File.separator+ORPG2_DATA; + static private Logger log = Logger.getLogger(ORPGUserDirs.class.getName()); + /** * ORPGuserDirs is a static class. It can be used without creating an instance of the class first. */ public ORPGUserDirs() { - } /** @@ -103,9 +105,12 @@ File dir = new File(directory); if (!dir.exists()){ //need to create home dir - if( !dir.mkdirs() ){ - //TODO REPORT/LOG ERRORS!! + if( dir.mkdirs() ){ + log.info("Created "+directory+" directory."); } + else{ + log.warning("Unable to create "+directory+" directory. Check permissions."); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Mark T. <ma...@ly...> - 2006-05-24 04:10:09
|
NeoSkye wrote: > I completely support the file based Preferences > system. I just wanted to mention that I think we > should avoid the default implementation of > java.util.prefs if my understanding is correct about > the registry. I'll look into that. I can see how that would be a problem. > > Also, it's only my personal opinion, but I usually > don't see a need to try and hide preferences files > from my users. It's less of an issue of "hiding" them as much as it is following a convention that is almost 20 years older than Windows itself. As it happens, the convetion also hides the directory that contains the proferences if one is using the default directory listing command without any options on Unix. In Windows, it;'s just another directory. >> Mark |
From: NeoSkye <djj...@ya...> - 2006-05-24 04:01:23
|
I'm sorry, I was definately not clear enough in that last post. What I meant to say is that it is my understanding(and correct me if I'm wrong here) that the java.util.prefs package by default uses the windows registry as it's backstore when running on windows systems. I realize that it allows someone to implement it differently. What I was trying to say, is that I believe we should stay away from allowing our program to write values to the Windows Registry on windows based machines. This has proven in the past for me with C++ programs to be difficult to clean up at uninstall time, and I would imagine it would be esp difficult to clean up with this program. I completely support the file based Preferences system. I just wanted to mention that I think we should avoid the default implementation of java.util.prefs if my understanding is correct about the registry. Also, it's only my personal opinion, but I usually don't see a need to try and hide preferences files from my users. If they are going to edit them, they will, be it hex editor or notepad. And those users will find the directory no matter what stealth we put on it. The other users who don't want to edit their settings won't even look in those other directories unless told to during a support session, and in that case, I would rather they have easy access than to try and explain to them how to find the directory they are looking for. But that's just my personal preference. And that's my 2c lol (sorry about the not being clear in my last message) NeoSkye __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |
From: Mark T. <ma...@ly...> - 2006-05-23 17:17:26
|
Snowdog wrote: > Mark Tarrabain wrote: >> mDuo13 wrote: >>> I second Tom. It's always nice to be able to tell people to backup >>> their settings, or to allow them to replace configurations manually. >> >> The only reason that the files should be visible is if they are >> designed to be edited. Although they may be plaintext files, they >> would be fully maintained by the software. >> >> I believe that convention would be better to follow convention in this >> case, as I said before. Files within the .openrpg2 directory need not >> be hidden, of course... and if people want to back up their setting >> they can do it anyways, even though the simplistic stealth feature of >> preceding the filename with a period is being used (does windows even >> consider that a stealth file? Or is that just Unix?) >> >> >> Mark > > > I checked this out.. Win2k and XP do not treat 'dot' directories as > stealth anyway.. so its largely a moot point as far as windows users are > concerned. The even on unix systems where they are treated as stealth > they aren't inaccessible. A simply 'ls -a' reveals their presence. Yes... I know that they aren't inaccessible. Not by any stretch. There are even other Windows apps which do this.... putting dot-directories in the directory which would be specified by the System property "user.home", which on windows systems usually defaults to C:\Documents and Settings\username. I believe that it's a good approach, personally. It follows the standard unix convention, and isn't really different from any approach that a windows app might otherwise take (because windows doesn't really have any one convention that is most common other than to use the registry). The directory is very easily backed up if one wants to, and it handles cases nicely where different users may not have shared write access to the directory that holds the application. Also, to others who have been concerned about Java using the Windows registry to back things up, there's no actual _requirement_ that the preferences API use the registry, even on Windows. You can import an xml file into a Preferences object as well as export a Preferences object into an XML file, which would, of course, be located in .openrpg2/ off of the user's home directory. Anyways... my 2c. >> Mark |
From: Snowdog <sn...@ga...> - 2006-05-23 16:37:43
|
Mark Tarrabain wrote: > NeoSkye wrote: >> I'm partial to the viewable myself, if they are gonna >> mess with them, they'll find them anyways. >> >> And even though it hasn't been mentioned, and prbly >> don't need to say anything...I'm against using the >> Java API Preferences stuff. In windows it saves to >> registry which in my experience is a pain. > > Why is it a pain, exactly? The Java registry API works the same on windows as it does with other systems (like unix) that don't have a defined 'registry'. So I'm with mark in asking why it's a pain. OpenRPG won't be using the 'Registry' anyway. Like in openrpg1 we will be using a dedicated directory in the users home to hold plain text properties files. This makes them easy to manually edit and simplifies loading/saving of preference info. --Snowdog |
From: Snowdog <sn...@ga...> - 2006-05-23 16:27:31
|
Mark Tarrabain wrote: > mDuo13 wrote: >> I second Tom. It's always nice to be able to tell people to backup >> their settings, or to allow them to replace configurations manually. > > The only reason that the files should be visible is if they are designed > to be edited. Although they may be plaintext files, they would be fully > maintained by the software. > > I believe that convention would be better to follow convention in this > case, as I said before. Files within the .openrpg2 directory need not > be hidden, of course... and if people want to back up their setting they > can do it anyways, even though the simplistic stealth feature of > preceding the filename with a period is being used (does windows even > consider that a stealth file? Or is that just Unix?) > > >> Mark I checked this out.. Win2k and XP do not treat 'dot' directories as stealth anyway.. so its largely a moot point as far as windows users are concerned. The even on unix systems where they are treated as stealth they aren't inaccessible. A simply 'ls -a' reveals their presence. None of the files within the top level dir would be hidden (stealth). --Snowdog |
From: Mark T. <ma...@ly...> - 2006-05-23 08:04:13
|
NeoSkye wrote: > I'm partial to the viewable myself, if they are gonna > mess with them, they'll find them anyways. > > And even though it hasn't been mentioned, and prbly > don't need to say anything...I'm against using the > Java API Preferences stuff. In windows it saves to > registry which in my experience is a pain. Why is it a pain, exactly? |
From: Mark T. <ma...@ly...> - 2006-05-23 08:02:19
|
mDuo13 wrote: > I second Tom. It's always nice to be able to tell people to backup their > settings, or to allow them to replace configurations manually. The only reason that the files should be visible is if they are designed to be edited. Although they may be plaintext files, they would be fully maintained by the software. I believe that convention would be better to follow convention in this case, as I said before. Files within the .openrpg2 directory need not be hidden, of course... and if people want to back up their setting they can do it anyways, even though the simplistic stealth feature of preceding the filename with a period is being used (does windows even consider that a stealth file? Or is that just Unix?) >> Mark |
From: mDuo13 <md...@ya...> - 2006-05-23 06:03:37
|
Java API puts stuff in the registry? Eeeeeew. That's a terrible idea, if you want to make OpenRPG portable via thumb-drives, if you want to back up your settings, etc. etc. etc. Hopefully we weren't considering this. --mDuo13 NeoSkye wrote: > I'm partial to the viewable myself, if they are gonna > mess with them, they'll find them anyways. > > And even though it hasn't been mentioned, and prbly > don't need to say anything...I'm against using the > Java API Preferences stuff. In windows it saves to > registry which in my experience is a pain. > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Openrpg-v2-dev mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openrpg-v2-dev > > |
From: NeoSkye <djj...@ya...> - 2006-05-23 06:01:33
|
I'm partial to the viewable myself, if they are gonna mess with them, they'll find them anyways. And even though it hasn't been mentioned, and prbly don't need to say anything...I'm against using the Java API Preferences stuff. In windows it saves to registry which in my experience is a pain. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |
From: mDuo13 <md...@ya...> - 2006-05-23 03:37:52
|
I second Tom. It's always nice to be able to tell people to backup their settings, or to allow them to replace configurations manually. --mDuo13 Baleno wrote: > If it is possible to edit the files then they should be visible. If they are > going to be binary then hidden won't be a bad idea. > > Tom > > > ---------- Original Message ----------- > From: Snowdog <sn...@ga...> > To: ope...@li... > Sent: Mon, 22 May 2006 13:14:54 -0700 > Subject: [Openrpg2 dev] A matter of preferences > > >> Just wanted to shoot this out to the rest of you for some feedback. >> Should the preferences/settings for openrpg follow standard unix >> convention and reside in a hidden directory in the users home dir (ie >> '.openrpg2' ) or should the directory be visible (id. 'openrpg2') >> >> Personally I'm for using the stealth version and sticking with >> convention. User files (like the gametrees in whatever form they end up >> being) may/may not be in this directory. Primarily this is for the >> OpenRPG cache and preferences/settings that need to be retained on a >> per-user basis. >> >> opinions? >> --Snowdog >> >> ------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, security? >> Get stuff done quickly with pre-integrated technology to make your job easier >> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >> _______________________________________________ >> Openrpg-v2-dev mailing list >> Ope...@li... >> https://lists.sourceforge.net/lists/listinfo/openrpg-v2-dev >> > ------- End of Original Message ------- > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Openrpg-v2-dev mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openrpg-v2-dev > > |