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: Mark T. <ma...@ly...> - 2006-04-06 21:31:35
|
Snowdog wrote: > Mark Tarrabain wrote: > >> Whups. Sorry about the valueOf/parseInt issue. I never even THOUGHT >> about it. >> >> I'll pay closer attention in the future. > > Not a big deal. Under java 1.5 the compiler doesn't even bat an eye when > you hand an Integer to a function that requires an int. So there would > be no reason for you really to question it. > > I am wondering why it seems you've based your die roller on string > rather than int at its base levels though. Seems to me a die is > mechanical random number generator and that says 'int' to me. Despite my > ponderings I'm going to leave the implementation to you and take a 'as > long as it works' stance. Actually, that's a perfectly valid question. And it would have been far easier to do just that. But I did it to support the creation of dice whose sides are not labeled with integers. For example, a die to show different types of weather, or a deck of many things die. Although no such dice are implemented in the code I submitted, it's fairly straightforward to add them. You simply implement the Die interface, and add it to DiceParser's symboltable via DiceParser.addDice(name,custom-dice-instance). Any expressions of the form 'd#' are automatically converted to instances of NumberedDie, which implements the interface and could serve as an example of how to write a Die implementation (although NumberedDie does some additional stuff to create a sort of Singleton pattern for the actual values on the sides of any particular type of Die). By the way, is there a particular reason you took out DiceParser.main()? > I would ask that you work on fleshing out the documentation for how the > dieroller works (format of input strings in particular) and some > instructions about how to create new 'functions' and dice so that others > using/extending the dice package can keep true to your original design. Sure thing... I'll work on that tonight and tomorrow. Where should I put such documentation though? > One thing I noticed is that your not catching many of the runtime > exceptions (NumberFormatExceptions in particular) within the dice > package. Are you intending for the caller to handle these exceptions > externally? If you are they should really be declared as thrown to give > other programmers a heads up when using your code. Good point. Yeah... my docs suck. Or blow. Or something. (weak grin) Anyways, I'll get on that right away too. Snowdog wrote: > NeoSkye wrote: >> Nice dice stuff, looks really robust. Anyone want to >> write a quick module for Client side private rolls?(I >> find sometimes I like to make a roll that has no real >> bearing on the gameplay and no one else would ever >> need to or care to see) > I presume die rolls like you mention would be worked into the chat like > they are in OpenRPG1 (i.e. whispering rolls to self). Lets try to stay > focused on getting the OpenRPG up and functioning first before expanding > it. We want the core to drive the development of the modules not the > other way around. ;-) Oh, but it's so much more FUN that way.... ;) >> Mark |
From: Snowdog <sn...@ga...> - 2006-04-06 21:18:32
|
NeoSkye wrote: > Nice dice stuff, looks really robust. Anyone want to > write a quick module for Client side private rolls?(I > find sometimes I like to make a roll that has no real > bearing on the gameplay and no one else would ever > need to or care to see) I presume die rolls like you mention would be worked into the chat like they are in OpenRPG1 (i.e. whispering rolls to self). Lets try to stay focused on getting the OpenRPG up and functioning first before expanding it. We want the core to drive the development of the modules not the other way around. ;-) > > Also, just a quick update, after fixing a quick bug in > the GUIManager pertaining to adding menu items I have > almost finished the "Window" menu. I'll prbly post the > patch sometime tonight. I'll keep my eye out for it. |
From: <sno...@us...> - 2006-04-06 21:14:34
|
Revision: 46 Author: snowdog_ Date: 2006-04-06 14:14:31 -0700 (Thu, 06 Apr 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=46&view=rev Log Message: ----------- Fixed two minor errors in Javadoc comment parsing. Modified Paths: -------------- trunk/src/openrpg2/common/dice/DiceParser.java trunk/src/openrpg2/common/dice/Value.java Modified: trunk/src/openrpg2/common/dice/DiceParser.java =================================================================== --- trunk/src/openrpg2/common/dice/DiceParser.java 2006-04-06 19:54:41 UTC (rev 45) +++ trunk/src/openrpg2/common/dice/DiceParser.java 2006-04-06 21:14:31 UTC (rev 46) @@ -165,7 +165,7 @@ /** * Testing function - * @param args the command line arguments + * @param dieString dieroll String to parse */ public static void diceParserTest(String dieString) { DiceParser dp=new DiceParser(dieString); Modified: trunk/src/openrpg2/common/dice/Value.java =================================================================== --- trunk/src/openrpg2/common/dice/Value.java 2006-04-06 19:54:41 UTC (rev 45) +++ trunk/src/openrpg2/common/dice/Value.java 2006-04-06 21:14:31 UTC (rev 46) @@ -31,8 +31,8 @@ */ public boolean isInt(); /** - * Gets the number of elements in this value. 0 means that the value is atomic - * @return the number of elements in this value + * 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(); /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: NeoSkye <djj...@ya...> - 2006-04-06 21:07:09
|
Nice dice stuff, looks really robust. Anyone want to write a quick module for Client side private rolls?(I find sometimes I like to make a roll that has no real bearing on the gameplay and no one else would ever need to or care to see) Also, just a quick update, after fixing a quick bug in the GUIManager pertaining to adding menu items I have almost finished the "Window" menu. I'll prbly post the patch sometime tonight. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |
From: Snowdog <sn...@ga...> - 2006-04-06 21:05:35
|
Mark Tarrabain wrote: > Whups. Sorry about the valueOf/parseInt issue. I never even THOUGHT > about it. > > I'll pay closer attention in the future. Not a big deal. Under java 1.5 the compiler doesn't even bat an eye when you hand an Integer to a function that requires an int. So there would be no reason for you really to question it. I am wondering why it seems you've based your die roller on string rather than int at its base levels though. Seems to me a die is mechanical random number generator and that says 'int' to me. Despite my ponderings I'm going to leave the implementation to you and take a 'as long as it works' stance. I would ask that you work on fleshing out the documentation for how the dieroller works (format of input strings in particular) and some instructions about how to create new 'functions' and dice so that others using/extending the dice package can keep true to your original design. One thing I noticed is that your not catching many of the runtime exceptions (NumberFormatExceptions in particular) within the dice package. Are you intending for the caller to handle these exceptions externally? If you are they should really be declared as thrown to give other programmers a heads up when using your code. -Snowdog |
From: Mark T. <ma...@ly...> - 2006-04-06 20:32:24
|
sno...@us... wrote: > Revision: 45 > Author: snowdog_ > Date: 2006-04-06 12:54:41 -0700 (Thu, 06 Apr 2006) > ViewCVS: http://svn.sourceforge.net/openrpg/?rev=45&view=rev > > Log Message: > ----------- > Integrating dice rolling package supplied by Mark Tarrabain (Sourceforge [Patches] tracker #1465531). Converted a number of Integer.valueOf() calls to Integer.parseInt() calls to make the code compile and function under java 1.4.x. Minor reoganization of DiceParser class to place constructor at top of file and group instance-scoped variables together above constructor declaration. Whups. Sorry about the valueOf/parseInt issue. I never even THOUGHT about it. I'll pay closer attention in the future. >> Mark |
From: <sno...@us...> - 2006-04-06 19:54:54
|
Revision: 45 Author: snowdog_ Date: 2006-04-06 12:54:41 -0700 (Thu, 06 Apr 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=45&view=rev Log Message: ----------- Integrating dice rolling package supplied by Mark Tarrabain (Sourceforge [Patches] tracker #1465531). Converted a number of Integer.valueOf() calls to Integer.parseInt() calls to make the code compile and function under java 1.4.x. Minor reoganization of DiceParser class to place constructor at top of file and group instance-scoped variables together above constructor declaration. Added Paths: ----------- trunk/src/openrpg2/common/dice/ trunk/src/openrpg2/common/dice/AddExpr.java trunk/src/openrpg2/common/dice/BinaryExpr.java trunk/src/openrpg2/common/dice/ConstInt.java trunk/src/openrpg2/common/dice/ConstStr.java trunk/src/openrpg2/common/dice/Dice.java trunk/src/openrpg2/common/dice/DiceParser.java trunk/src/openrpg2/common/dice/Die.java trunk/src/openrpg2/common/dice/DivExpr.java trunk/src/openrpg2/common/dice/Expr.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/NumberedDie.java trunk/src/openrpg2/common/dice/StrValue.java trunk/src/openrpg2/common/dice/Value.java Added: trunk/src/openrpg2/common/dice/AddExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/AddExpr.java (rev 0) +++ trunk/src/openrpg2/common/dice/AddExpr.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,61 @@ +/* + * AddExpr.java + * + * Created on April 2, 2006, 8:07 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; + +/** + * Creates an add expression, which is either one expression plus + * another, or else one integer expression minus another + * @author markt + */ +public class AddExpr extends BinaryExpr { + private Expr x,y; + private char join; + /** + * Creates a new instance of AddExpr + * @param a The left hand parameter + * @param b The right hand parameter + * @param j The type of operation ('+' or '-') + */ + public AddExpr(Expr a,Expr b,char j) { + super(a,b,j); + x=a; + y=b; + join=j; + if (j!='+' && j!='-') + throw new IllegalArgumentException("Add Expression must be '+' or '-'"); + if (j=='-' && !(x.isInt()&&y.isInt())) + throw new IllegalArgumentException("Cannot subtract non integer expressions"); + } + /** + * Rolls any dice found in the expression + */ + public void roll() { + super.roll(); + if (join=='+') { + if (isInt()) + value=new IntValue(x.getIntValue()+y.getIntValue()); + else + value=new StrValue(x.getStrValue()+y.getStrValue()); + } + else + value=new IntValue(x.getIntValue()-y.getIntValue()); + } +} Added: trunk/src/openrpg2/common/dice/BinaryExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/BinaryExpr.java (rev 0) +++ trunk/src/openrpg2/common/dice/BinaryExpr.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,69 @@ +/* + * BinaryExpr.java + * + * Created on April 2, 2006, 8:28 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 for binary operators + * @author markt + */ +public class BinaryExpr extends Expr { + protected Expr x; + /** + * Right hand argument + */ + protected Expr y; + /** + * Operator character + */ + protected char join; + /** + * Creates a new instance of BinaryExpr + * @param a Left hand parameter + * @param b Right hand parameter + * @param c The operator to join them + */ + public BinaryExpr(Expr a,Expr b,char c) { + x=a; + y=b; + join=c; + } + /** + * Evaluates whether or not the expression is an integer + * @return true if an int, false otherwise + */ + public boolean isInt() { + return x.isInt()&y.isInt(); + } + /** + * Gets the details of the last roll + * @return the details of the last roll + */ + public String getDetails() { + return x.getDetails()+join+y.getDetails(); + } + /** + * Rolls all dice in this expression + */ + public void roll() { + x.roll(); + y.roll(); + } +} Added: trunk/src/openrpg2/common/dice/ConstInt.java =================================================================== --- trunk/src/openrpg2/common/dice/ConstInt.java (rev 0) +++ trunk/src/openrpg2/common/dice/ConstInt.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,43 @@ +/* + * ConstInt.java + * + * Created on April 2, 2006, 6:29 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; + +/** + * A constant integer expression + * @author markt + */ +public class ConstInt extends Expr { + /** + * Creates a new instance of ConstInt + * @param n the integer to initialize this expression to + */ + public ConstInt(int n) { + value=new IntValue(n); + } + /** + * Declare whether or not this expression is an integer + * @return true, always + */ + public boolean isInt() { + return true; + } + +} Added: trunk/src/openrpg2/common/dice/ConstStr.java =================================================================== --- trunk/src/openrpg2/common/dice/ConstStr.java (rev 0) +++ trunk/src/openrpg2/common/dice/ConstStr.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,36 @@ +/* + * ConstStr.java + * + * Created on April 2, 2006, 6:30 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; + +/** + * Constrant string express + * @author markt + */ +public class ConstStr extends Expr { + + /** + * Creates a new instance of ConstStr + * @param s The string to initialize the string expression to + */ + public ConstStr(String s) { + value=new StrValue(s); + } +} Added: trunk/src/openrpg2/common/dice/Dice.java =================================================================== --- trunk/src/openrpg2/common/dice/Dice.java (rev 0) +++ trunk/src/openrpg2/common/dice/Dice.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,131 @@ +/* + * Dice.java + * + * Created on April 2, 2006, 6:44 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.*; + + + +/** + * Class for managing a group of identical dice + * @author markt + */ +public class Dice extends Expr { + private int num; + private Die die; + private Vector sides; + private boolean isint; + /** + * Creates a new instance of Dice + * @param n Number of dice + * @param d Type of Dice + */ + protected Dice(int n,Die d) { + die=d; + num=n; + sides=new Vector(); + sides.addAll(die.getSides()); + isint=true; + for(int i=0;i<sides.size();i++) { + String s=(String)sides.get(i); + int j=0; + if (s.length()>1 && s.charAt(0)=='-') j++; + for(;j<s.length();j++) if (!Character.isDigit(s.charAt(j))) + isint=false; + } + } + /** + * Sets minimum and maximum rolls for this dice expression + * @param l Low roll value, or null if none + * @param h High roll value, or null if none + */ + public void setMinMax(String l,String h) { + for(int i=0;i<sides.size();i++) { + String s=(String)sides.get(i); + if (isint) { + if (l!=null && Integer.parseInt(s)<Integer.parseInt(l)) + sides.set(i,l); + if (h!=null && Integer.parseInt(s)>Integer.parseInt(h)) + sides.set(i,h); + + } else { + if (l!=null && s.compareTo(l)<0) + sides.set(i,l); + if (h!=null && s.compareTo(h)>0) + sides.set(i,h); + } + } + } + /** + * Adds some values to be rerolled if they come up + * @param rerolls Vector containing Strings that are the values to be rerolled + */ + public void addRerolls(String []rerolls) { + Vector s=new Vector(); + for(int i=0;i<rerolls.length;i++) + s.add(rerolls[i]); + sides.removeAll(s); + } + private static Random random; + /** + * Gets a random number generator + * @return the current random number generator + */ + public static Random getRandom() { + if (random==null) random=new Random(); + return random; + } + /** + * Sets the current random number generator + * @param r The random number generator to use or null for default + */ + public static void setRandom(Random r) { + random=r; + } + /** + * Gets the size of the group for this expression + * @return the number of dice in this expression + */ + public int getSize() { + return num; + } + /** + * Tells whether or not this expression has an integer value + * @return true if die type was integer, false otherwise + */ + public boolean isInt() { + return isint; + } + /** + * Rolls all the dice in this expression + */ + public void roll() { + Value[] vals=new Value[num]; + for(int i=0;i<num;i++) { + String s=(String)sides.get(getRandom().nextInt(sides.size())); + if (isint) + vals[i]=new IntValue(Integer.parseInt(s)); + else + vals[i]=new StrValue(s); + } + value=new GroupValue(vals); + } +} Added: trunk/src/openrpg2/common/dice/DiceParser.java =================================================================== --- trunk/src/openrpg2/common/dice/DiceParser.java (rev 0) +++ trunk/src/openrpg2/common/dice/DiceParser.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,424 @@ +/* + * DiceParser.java + * + * Created on April 2, 2006, 11:18 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.io.*; +import java.util.*; + +/** + * 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 + * interface. + * Default implemented functions include min(...) which selects the minimum + * 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 + * 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: + * highest(3,[4,6,3,1]) + * and calling finalValue() 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() + * + * + * @author markt + */ +public class DiceParser { + private static class Token { + } + private static final Token TEOF=new Token(); + private static final Token TINT=new Token(); + private static final Token TSTR=new Token(); + private static final Token TPLUS=new Token(); + private static final Token TMINUS=new Token(); + private static final Token TSTAR=new Token(); + private static final Token TSLASH=new Token(); + private static final Token TLPAR=new Token(); + private static final Token TRPAR=new Token(); + private static final Token TCOMMA=new Token(); + private static final Token TDOT=new Token(); + private static final Token TDICE=new Token(); + private static final Token TID=new Token(); + private static final Token TERROR=new Token(); + private static final Token TMIN=new Token(); + private static final Token TMAX=new Token(); + private static final Token TREROLL=new Token(); + + private static Hashtable symbols=new Hashtable(); + // for holding special die-specific functions. + private static Hashtable dicetable=new Hashtable(); + + static { + dicetable.put("min",TMIN); + dicetable.put("max",TMAX); + dicetable.put("reroll",TREROLL); + + addFunction("highest",new HighestFunc()); + addFunction("lowest",new LowestFunc()); + addFunction("min",new MinFunc()); + addFunction("max",new MaxFunc()); + } + + private Reader in; + 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 + * @param s The string to parse + */ + public DiceParser(String s) { + in=new StringReader(s); + nc=-1; + scan(); + expr=parseExpr(); + if (token!=TEOF) + throw new IllegalArgumentException("Expected end of expression"); + } + + /** + * 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) { + 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) { + symbols.put(name,func); + } + + /** + * 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 finalValue() { + return expr.getValue().getBaseValue().toString(); + } + + /** + * rolls any dice found in this DiceParser's expression + */ + public void roll() { + expr.roll(); + } + + /** + * Testing function + * @param args the command line arguments + */ + public static void diceParserTest(String dieString) { + DiceParser dp=new DiceParser(dieString); + dp.roll(); + System.out.println(dp.getDetails()+" --> "+dp.finalValue()); + } + + + private void scanInteger(char ch) { + number=(int)ch-(int)'0'; + try { + while((nc=in.read())!=-1 && Character.isDigit((char)nc)) + number=number*10+nc-(int)'0'; + } catch(IOException e) { + } + 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); + } + } + return (result!=null && result instanceof Die); + } + + private void scan() { + if (temptoken!=null) { + token=temptoken; + return; + } + 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; + } + if (Character.isLetter(ch)) { + scanId(ch); + if (isDice()) { + number=1; + token=TDICE; + } + return; + } + if (ch=='"') { + word=""; + try { + while((c=in.read())!=-1 && c!=(int)'"') + word=word+(char)c; + } + 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 ConstInt(number); + scan(); + } + else if (token==TSTR) { + e=new ConstStr(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(); + 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==TID) { + Token t=(Token)dicetable.get(word); + if (t==null) + throw new IllegalArgumentException("Invalid dice adjustment function"); + scan(); + if (token!=TLPAR) + throw new IllegalArgumentException("Expecting '('"); + scan(); + 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==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); + } + } + dice.setMinMax(low,high); + e=dice; + } + return e; + } + + private Expr parseFactor() { + if (token==TMINUS) { + scan(); + 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; + } + + 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; + } +} Added: trunk/src/openrpg2/common/dice/Die.java =================================================================== --- trunk/src/openrpg2/common/dice/Die.java (rev 0) +++ trunk/src/openrpg2/common/dice/Die.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,39 @@ +/* + * 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(); +} Added: trunk/src/openrpg2/common/dice/DivExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/DivExpr.java (rev 0) +++ trunk/src/openrpg2/common/dice/DivExpr.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,66 @@ +/* + * DivExpr.java + * + * Created on April 2, 2006, 8:32 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; + +/** + * Division expression (two expressions separated by a /). Integer math + * only, will ignore any fractions. The right hand argument MUST be a + * constant integer. + * @author markt + */ +public class DivExpr extends BinaryExpr { + + /** + * Creates a new instance of DivExpr + * @param a Dividend + * @param b Divisor + */ + public DivExpr(Expr a,Expr b) { + super(a,b,'/'); + if (!(b instanceof ConstInt)) + throw new IllegalArgumentException("Cannot divide by anything other than integer constants"); + if (b.getIntValue()==0) + throw new IllegalArgumentException("Division by zero"); + if (!a.isInt()) + throw new IllegalArgumentException("Cannot divide non integer expressions"); + } + /** + * Gets the details for this expression + * @return the details for this expression after any dice rolls + */ + public String getDetails() { + String r; + if (x instanceof AddExpr) + r="("+x.getDetails()+")"; + else + r=x.getDetails(); + r=r+"/"+y.getDetails(); + return r; + } + /** + * Rolls any dice in this expression + */ + public void roll() { + super.roll(); + value=new IntValue(x.getIntValue()/y.getIntValue()); + } + +} Added: trunk/src/openrpg2/common/dice/Expr.java =================================================================== --- trunk/src/openrpg2/common/dice/Expr.java (rev 0) +++ trunk/src/openrpg2/common/dice/Expr.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,85 @@ +/* + * 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 + */ + public int getIntValue() { + return Integer.parseInt(value.getBaseValue().toString()); + } + /** + * Gets the string form of the value for this expression + * @return a string showing the value of this expression + */ + public String getStrValue() { + return value.getBaseValue().toString(); + } +} Added: trunk/src/openrpg2/common/dice/FuncExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/FuncExpr.java (rev 0) +++ trunk/src/openrpg2/common/dice/FuncExpr.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,81 @@ +/* + * FuncExpr.java + * + * Created on April 2, 2006, 7:23 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; + +/** + * Function expressions, of the form id(parm,parm,...) + * @author markt + */ +public class FuncExpr extends Expr { + private Expr []exprs; + private Function func; + private int size; + private boolean isint; + /** + * Creates a new instance of FuncExpr + * @param f The function to create + * @param e The list of expression parameters to the function + */ + public FuncExpr(Function f,Expr []e) { + func=f; + if (e==null) exprs=new Expr[0]; + else exprs=e; + size=func.getSize(exprs); + isint=func.isInt(exprs); + } + /** + * Gets the details for this expression + * @return details for this FuncExpr, of the form "name(expr,expr,...)" + */ + public String getDetails() { + String r=func.getName()+"("; + for (int i=0;i<exprs.length;i++) { + if (i>0) r=r+","; + r=r+exprs[i].getDetails(); + } + return r+")"; + } + /** + * Rolls any dice in this expression + */ + public void roll() { + Value[] vals=new Value[exprs.length]; + for(int i=0;i<exprs.length;i++) { + exprs[i].roll(); + vals[i]=exprs[i].getValue(); + } + value=func.exec(vals); + } + /** + * Determines if expression is an integer. + * @return true if funcexpr is integer, false otherwise + */ + public boolean isInt() { + return isint; + } + /** + * Gets the number of elements in this expression + * @return the number of elements in this expression + */ + public int getSize() { + return size; + } +} \ No newline at end of file Added: trunk/src/openrpg2/common/dice/Function.java =================================================================== --- trunk/src/openrpg2/common/dice/Function.java (rev 0) +++ trunk/src/openrpg2/common/dice/Function.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,80 @@ +/* + * Function.java + * + * Created on April 2, 2006, 7: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; + +/** + * Base class for all functions added to the parser. + * @author markt + */ +public abstract class Function { + private String name; + /** + * Creates a new instance of Function + * @param n name of function + */ + public Function(String n) { + name=n; + } + /** + * getter function for the function name + * @return the name of the function + */ + public String getName() { + return name; + } + /** + * gets the number of elements in the resulting value. This function should + * verify the number and type of arguments supplied, and should throw an + * IllegalArgumentException if something is not right. + * @param expr the parameters to this expression + * @return the number of elements that this function will return + */ + public abstract int getSize(Expr[] expr); + /** + * Determines if the expression is an integer or not + * @param exprs the parameters to this function + * @return true if an integer, false otherwise + */ + public abstract boolean isInt(Expr[] exprs); + /** + * Executes the function. Note that the parameters are evaluated, but not + * necessarily reduced to simplest terms, so a collection of values is still + * a collection and not simplified to one value. Use getBaseValue() on any + * argument to simplify any argument to its base if that is what is desired. + * @param vals The values to pass to this function (already evaluated) + * @return The result of the function + */ + public abstract Value exec(Value []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) { + String x=a.getBaseValue().toString(); + String y=b.getBaseValue().toString(); + if (a.isInt() && b.isInt()) + return Integer.parseInt(x)-Integer.parseInt(y); + else + return x.compareTo(y); + } +} Added: trunk/src/openrpg2/common/dice/GroupValue.java =================================================================== --- trunk/src/openrpg2/common/dice/GroupValue.java (rev 0) +++ trunk/src/openrpg2/common/dice/GroupValue.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,92 @@ +/* + * GroupValue.java + * + * Created on April 2, 2006, 2:54 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; + +/** + * Defines a collection of values + * @author markt + */ +public class GroupValue implements Value { + private Value[] 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]; + else values=v; + } + /** + * Determines if this expression is an integer + * @return true if it is an integer, false otherwise + */ + public boolean isInt() { + if (values.length==0) return false; + boolean r=true; + for(int i=0;i<values.length;i++) + r=r&values[i].isInt(); + return r; + } + /** + * Gets the list of values in this group + * @return the list of values in this group + */ + public Value[] getValues() { + return values; + } + /** + * Gets the size of this expression + * @return the number of values in this group + */ + public int getSize() { return values.length; } + /** + * Gets a string version of this expression + * @return the concatenation or sum of the values in this group + */ + public String toString() { + String r="["; + for(int i=0;i<values.length;i++) { + if (i>0) r=r+","; + r=r+values[i].toString(); + } + return r+"]"; + } + /** + * Gets the base value for this expression + * @return the base value for this expression + */ + public Value getBaseValue() { + if (isInt()) { + int n=0; + for(int i=0;i<values.length;i++) + n=n+Integer.parseInt(values[i].getBaseValue().toString()); + return new IntValue(n); + } + else { + String r=""; + for(int i=0;i<values.length;i++) { + if (i>0) r=r+" "; + r=r+values[i].getBaseValue().toString(); + } + return new StrValue(r); + } + } +} Added: trunk/src/openrpg2/common/dice/HighestFunc.java =================================================================== --- trunk/src/openrpg2/common/dice/HighestFunc.java (rev 0) +++ trunk/src/openrpg2/common/dice/HighestFunc.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,88 @@ +/* + * HighestFunc.java + * + * Created on April 4, 2006, 10:02 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; + +/** + * Function to get the highest 'n' dice from an expression. + * For example highest(3,4d6) + * @author markt + */ +public class HighestFunc extends Function { + + /** + * Creates a new instance of HighestFunc + */ + public HighestFunc() { + super("highest"); + } + /** + * Determins if function is an integer + * @param exprs The arguments to the function + * @return true if function returns an integer, false otherwise + */ + public boolean isInt(Expr[] exprs) { + return exprs[1].isInt(); + } + /** + * Gets the size of the expression + * @param expr The arguments to this function + * @return The number of elements selected + */ + public int getSize(Expr[] expr) { + if (expr.length!=2) + throw new IllegalArgumentException("Expecting two arguments to 'highest' function"); + if (!(expr[0] instanceof ConstInt)) + throw new IllegalArgumentException("Expecting constant integer as first argument"); + if (expr.length!=2) + throw new IllegalArgumentException("Expecting two arguments to 'highest' function"); + if (expr[1].getSize()<expr[0].getIntValue()) + throw new IllegalArgumentException("Cannot collect more values than in the 2nd argument to 'highest'"); + if (!expr[1].isInt()) + throw new IllegalArgumentException("Expecting integer expressions"); + return expr[0].getIntValue(); + } + /** + * Executes the function + * @param vals The parameters to the function after evaluation + * @return the result of the function + */ + public Value exec(Value[] vals) { + int num=Integer.parseInt(vals[0].getBaseValue().toString()); + Value[] group=((GroupValue)vals[1]).getValues(); + Value []result=new Value[num]; + boolean[] take=new boolean[group.length]; + for(int i=0;i<take.length;i++) take[i]=false; + int len=group.length; + while(len>result.length) { + int out=-1; + for(int i=0;i<take.length;i++) if (!take[i]) { + if (out==-1) out=i; + else if (compareTo(group[i],group[out])<0) out=i; + } + len--; + take[out]=true; + } + len=0; + for(int i=0;i<take.length;i++) if (!take[i]) + result[len++]=group[i]; + return new GroupValue(result); + } +} Added: trunk/src/openrpg2/common/dice/IntValue.java =================================================================== --- trunk/src/openrpg2/common/dice/IntValue.java (rev 0) +++ trunk/src/openrpg2/common/dice/IntValue.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,61 @@ +/* + * IntValue.java + * + * Created on April 2, 2006, 2:52 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; + +/** + * An integer value + * @author markt + */ +public class IntValue implements Value { + private int value; + /** + * Creates a new instance of IntValue + * @param n the integer to initialize it to + */ + public IntValue(int n) { + value=n; + } + /** + * Determines if expression is an integer + * @return true, always + */ + public boolean isInt() { return true; } + /** + * gets the size of this value + * @return 0, always + */ + public int getSize() { return 0; } + /** + * Gets the string form of this value + * @return the integer converted to a string + */ + public String toString() { + return ""+value; + } + /** + * Gets the base value for this value + * @return this + */ + public Value getBaseValue() { + return this; + } + +} Added: trunk/src/openrpg2/common/dice/LowestFunc.java =================================================================== --- trunk/src/openrpg2/common/dice/LowestFunc.java (rev 0) +++ trunk/src/openrpg2/common/dice/LowestFunc.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,86 @@ +/* + * LowestFunc.java + * + * Created on April 4, 2006, 11:52 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; + +/** + * Function to select the lowest 'n' dice from a group. Note functions + * can be chained, ie, highest(3,lowest(4,6d6)) + * @author markt + */ +public class LowestFunc extends Function{ + + /** + * Creates a new instance of LowestFunc + */ + public LowestFunc() { + super("lowest"); + } + /** + * Finds out if this function is an integer + * @param exprs Parameters to this function + * @return true if an integer, false otherwise + */ + public boolean isInt(Expr[] exprs) { + return exprs[1].isInt(); + } + /** + * Gets the number of elements returned by this function + * @param expr The (unevaluated) expressions in this function. + * @return the number of elements selected + */ + public int getSize(Expr[] expr) { + if (expr.length!=2) + throw new IllegalArgumentException("Expecting two arguments to 'lowest' function"); + if (!(expr[0] instanceof ConstInt)) + throw new IllegalArgumentException("Expecting constant integer as first argument"); + if (expr[1].getSize()<expr[0].getIntValue()) + throw new IllegalArgumentException("Cannot collect more values than in the 2nd argument to 'lowest'"); + if (!expr[1].isInt()) + throw new IllegalArgumentException("Expecting integer expressions"); + return expr[0].getIntValue(); + } + /** + * Executes the function + * @param vals The arguments to the function + * @return The result of the function + */ + public Value exec(Value[] vals) { + int num=Integer.parseInt(vals[0].getBaseValue().toString()); + Value[] group=((GroupValue)vals[1]).getValues(); + Value []result=new Value[num]; + boolean[] take=new boolean[group.length]; + for(int i=0;i<take.length;i++) take[i]=false; + int len=group.length; + while(len>result.length) { + int out=-1; + for(int i=0;i<take.length;i++) if (!take[i]) { + if (out==-1) out=i; + else if (compareTo(group[i],group[out])>0) out=i; + } + len--; + take[out]=true; + } + len=0; + for(int i=0;i<take.length;i++) if (!take[i]) + result[len++]=group[i]; + return new GroupValue(result); + } +} Added: trunk/src/openrpg2/common/dice/MaxFunc.java =================================================================== --- trunk/src/openrpg2/common/dice/MaxFunc.java (rev 0) +++ trunk/src/openrpg2/common/dice/MaxFunc.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,68 @@ +/* + * MaxFunc.java + * + * Created on April 5, 2006, 11:40 AM + * + * ==================================================================== + * 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; + +/** + * Function gets the maximum value in its arguments + * @author markt + */ +public class MaxFunc extends Function { + + /** Creates a new instance of MaxFunc */ + public MaxFunc() { + super("max"); + } + /** + * Finds out if this function returns an integer + * @param exprs Arguments to the function + * @return true if result is an integer, false otherwise + */ + public boolean isInt(Expr[] exprs) { + boolean r=true; + if (exprs.length<1) + for(int i=0;r && i<exprs.length;i++) + r=r&exprs[i].isInt(); + return r; + } + /** + * Executes the function + * @param vals arguments to the function + * @return maximum argument listed in vals + */ + public Value exec(Value []vals) { + Value result=null; + for(int i=0;i<vals.length;i++) + if (result==null || compareTo(vals[i],result)>0) result=vals[i]; + return result; + } + + /** + * Gets the size of this expression + * @param exprs arguments to this function + * @return 0, always + */ + public int getSize(Expr[] exprs) { + if (exprs.length<1) + throw new IllegalArgumentException("Expecting at least one value "); + return 0; + + } +} Added: trunk/src/openrpg2/common/dice/MinFunc.java =================================================================== --- trunk/src/openrpg2/common/dice/MinFunc.java (rev 0) +++ trunk/src/openrpg2/common/dice/MinFunc.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,68 @@ +/* + * MinFunc.java + * + * Created on April 5, 2006, 11:31 AM + * + * ==================================================================== + * 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; + +/** + * Function gets the minimum value in its arguments + * @author markt + */ +public class MinFunc extends Function { + + /** Creates a new instance of MinFunc */ + public MinFunc() { + super("min"); + } + /** + * Finds out if this function returns an integer + * @param exprs arguments to this function + * @return true if an integer, false otherwise + */ + public boolean isInt(Expr[] exprs) { + boolean r=true; + if (exprs.length<1) + for(int i=0;r && i<exprs.length;i++) + r=r&exprs[i].isInt(); + return r; + } + /** + * Executes the function + * @param vals the arguments to the function + * @return minimum value specified in vals + */ + public Value exec(Value []vals) { + Value result=null; + for(int i=0;i<vals.length;i++) + if (result==null || compareTo(vals[i],result)<0) result=vals[i]; + return result; + } + + /** + * Gets the number of elements returned by this function + * @param exprs The arguments to this function + * @return 0, always + */ + public int getSize(Expr[] exprs) { + if (exprs.length<1) + throw new IllegalArgumentException("Expecting at least one value "); + return 0; + + } +} Added: trunk/src/openrpg2/common/dice/MultExpr.java =================================================================== --- trunk/src/openrpg2/common/dice/MultExpr.java (rev 0) +++ trunk/src/openrpg2/common/dice/MultExpr.java 2006-04-06 19:54:41 UTC (rev 45) @@ -0,0 +1,63 @@ +/* + * MultExpr.java + * + * Created on April 2, 2006, 8:20 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; + +/** + * Multiplication Expression + * @author markt + */ +public class MultExpr extends BinaryExpr { + /** + * Creates a new instance of MultExpr + * @param a Multiplicand + * @param b Multiplier + */ + public MultExpr(Expr a,Expr b) { + super(a,b,'*'); + if (!x.isInt() || !y.isInt()) + throw new IllegalArgumentException("Cannot multiply non integers"); + + } + /** + * Rolls the dice in this expression + */ + public void roll() { + super.roll(); + value=new IntValue(x.getIntValue()*y.getIntValue()); + } + /** + * Gets the details for this expression + * @return the details for this multiplication expression + */ + public String getDetails() { + String r; + if (x instanceof AddExpr) + r="("+x.ge... [truncated message content] |
From: Mark T. <ma...@ly...> - 2006-04-06 06:55:17
|
Mark Tarrabain wrote: > Okay... I have some code that's ready to be inserted. A dice rolling > library that should hopefully be robust enough to be expandable to suit > any future requirements. There's no direct calls to it in the > application yet because the framework for inserting it (ie a chat > system) has not yet been created. I've been debugging it by invoking > the primary class's main() method, and it seems to work. > > So how, exactly, do I submit it? > > >> Mark Never mind. I figured it out. >> Mark |
From: Mark T. <ma...@ly...> - 2006-04-06 06:31:33
|
Okay... I have some code that's ready to be inserted. A dice rolling library that should hopefully be robust enough to be expandable to suit any future requirements. There's no direct calls to it in the application yet because the framework for inserting it (ie a chat system) has not yet been created. I've been debugging it by invoking the primary class's main() method, and it seems to work. So how, exactly, do I submit it? >> Mark |
From: <sno...@us...> - 2006-04-05 21:16:06
|
Revision: 44 Author: snowdog_ Date: 2006-04-05 14:15:55 -0700 (Wed, 05 Apr 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=44&view=rev Log Message: ----------- Very minor tweaks to network modules. Modified Paths: -------------- trunk/src/openrpg2/common/core/network/NetworkClientModule.java trunk/src/openrpg2/common/core/network/NetworkServerModule.java Modified: trunk/src/openrpg2/common/core/network/NetworkClientModule.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2006-04-05 18:11:32 UTC (rev 43) +++ trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2006-04-05 21:15:55 UTC (rev 44) @@ -30,7 +30,7 @@ * The NetworkClientModule is a special client loadable module to provide network information to other modules * in a controled and safe manner. This class is loaded into the module manager and provides an API through which * network related information can be obtained by other modules and thus keep other modules from relying directly - * on the network's specific implementation. This module also provides support for message based requests for + * on the network's specific implementation. This module also provides support for message based requests for * graceful disconnection of/by a client or server. * @author Snowdog */ @@ -38,28 +38,30 @@ private final static String HEADER_OP = "OP"; private final static int OP_NOOP = 0; - private final static int OP_DISCONNECT = 1; + private final static int OP_DISCONNECT = 1; private final static int OP_ALERT = 2; + private final static int OP_SHUTDOWN = 3; private NetworkClient network = null; - /** Creates a new instance of NetworkServerModule */ + /** Creates a new instance of NetworkClientModule */ public NetworkClientModule(NetworkClient networkReference ) { network = networkReference; } public void doRegistration(){ - modCom.registerMessageType(ORPGConstants.TYPE_NETWORK, this); + modCom.registerMessageType(ORPGConstants.TYPE_NETWORK, this); } public void processMessage(ORPGMessage msg){ //NOTE messages of this type ALWAYS come from the server - int operation = Integer.parseInt(msg.getHeader("OP")); + int operation = Integer.parseInt(msg.getHeader(HEADER_OP)); switch(operation){ case(OP_NOOP):{ break; } case(OP_DISCONNECT):{ handleDisconnectMessage(msg);break; } case(OP_ALERT):{ handleAlertMessage(msg); break; } + case(OP_SHUTDOWN):{ handleShutdownMessage(msg); break; } default: {break;} } } @@ -73,6 +75,9 @@ //TODO: handle network level alert message (these would be warnings of impending server shutdown and the like) } + private void handleShutdownMessage(ORPGMessage msg){ + //TODO: handle shutdown message from server. (Disconnect from server with special notification about server shutdown) + } } Modified: trunk/src/openrpg2/common/core/network/NetworkServerModule.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkServerModule.java 2006-04-05 18:11:32 UTC (rev 43) +++ trunk/src/openrpg2/common/core/network/NetworkServerModule.java 2006-04-05 21:15:55 UTC (rev 44) @@ -31,7 +31,7 @@ * The NetworkServerModule is a special server loadable module to provide network information to other modules * in a controled and safe manner. This class is loaded into the module manager and provides an API through which * network related information can be obtained by other modules and thus keep other modules from relying directly - * on the network's specific implementation. This module also provides support for message based requests for + * on the network's specific implementation. This module also provides support for message based requests for * graceful disconnection of/by a client. * @author Snowdog */ @@ -39,8 +39,9 @@ private final static String HEADER_OP = "OP"; private final static int OP_NOOP = 0; - private final static int OP_DISCONNECT = 1; + private final static int OP_DISCONNECT = 1; private final static int OP_ALERT = 2; + private final static int OP_SHUTDOWN = 3; private NetworkServer network = null; @@ -50,16 +51,17 @@ } public void doRegistration(){ - modCom.registerMessageType(ORPGConstants.TYPE_NETWORK, this); + modCom.registerMessageType(ORPGConstants.TYPE_NETWORK, this); } public void processMessage(ORPGMessage msg){ int clientId = msg.getOriginatorId(); - int operation = Integer.parseInt(msg.getHeader("OP")); + int operation = Integer.parseInt(msg.getHeader(HEADER_OP)); switch(operation){ case(OP_NOOP):{ break; } case(OP_DISCONNECT):{ handleDisconnectMessage(msg);break; } case(OP_ALERT):{ handleAlertMessage(msg); break; } + case(OP_SHUTDOWN):{ handleShutdownMessage(msg); break; } default: {break;} } } @@ -70,6 +72,12 @@ } private void handleAlertMessage(ORPGMessage msg){ - //TODO: handle network level alert message (these would be warnings of impending server shutdown and the like) + // Ignore this message. Server does not recieve Alert Messages from clients. + // (May be used in future if server to server communication implemented at a later date) } + + private void handleShutdownMessage(ORPGMessage msg){ + // Ignore this message. Server does not recieve Shutdown Messages from clients. + // (May be used in future if server to server communication implemented at a later date) + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Snowdog <sn...@ga...> - 2006-04-05 18:15:35
|
I updated the MenuManager for you. I noticed however while I tested it that we'll have to add some sort of callback or observer object to the GUI so that it can repaint itself when the MenuManager changes the JMenuBar contents. Currently menu's added/removed at runtime don't show up until the JMenuBar's parent frame is repainted. > NeoSkye wrote: >> Hi, working on the GUI I realized that we may want a >> "Window" Menu, which I can handle just fine through >> the MenuManager, except for one thing. The "Window" >> menu (which may evolve into a "Module" menu >> someday...it aspires to greatness) needs to be able to >> remove MenuItems from a Menu, and the current >> MenuManager gives no way to do this. |
From: <sno...@us...> - 2006-04-05 18:11:36
|
Revision: 43 Author: snowdog_ Date: 2006-04-05 11:11:32 -0700 (Wed, 05 Apr 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=43&view=rev Log Message: ----------- Added JMenu and JMenuItem removal support to MenuManager per NeoSkye's request. Modified Paths: -------------- trunk/src/openrpg2/common/core/gui/MenuManager.java Modified: trunk/src/openrpg2/common/core/gui/MenuManager.java =================================================================== --- trunk/src/openrpg2/common/core/gui/MenuManager.java 2006-04-04 21:27:21 UTC (rev 42) +++ trunk/src/openrpg2/common/core/gui/MenuManager.java 2006-04-05 18:11:32 UTC (rev 43) @@ -37,8 +37,9 @@ public class MenuManager { private JMenuBar menubar; - + final static int MAX_REPAINT_DELAY = 100; //in milliseconds + /** Creates a new instance of MenuManager */ public MenuManager() { menubar = new JMenuBar(); @@ -49,25 +50,45 @@ return menubar; } + public boolean removeMenu(String menuName ){ + + JMenu j = getMenuWithName(menuName); + if (j != null){ + menubar.remove(j); + menubar.repaint(MAX_REPAINT_DELAY); + return true; + } + return false; + } + public boolean removeMenuItem(String menuName, String menuItemName){ + JMenu j = getMenuWithName(menuName); + if (j != null){ + JMenuItem i = getMenuItemWithName(j, menuItemName); + if (i != null){ + j.remove(i); + menubar.repaint(MAX_REPAINT_DELAY); + return true; + } + } + return false; + } + public boolean registerMenu( String menuname ){ try{ - Component[] c = menubar.getComponents(); - boolean oktoadd = true; - for (int i = c.length -1 ; i > -1;i--){ - String n = ((JMenu)c[i]).getText(); - if (menuname.equals(n)){ - oktoadd = false; - break; + Component[] c = menubar.getComponents(); + + if (!hasMenu(menuname)){ + menubar.add(new JMenu(menuname)); + menubar.repaint(MAX_REPAINT_DELAY); + return true; } - } - if (oktoadd){ menubar.add(new JMenu(menuname)); return true; } - + }catch(Exception e){ System.err.println("Exception = "+e.getMessage()); e.printStackTrace(); } - return false; + return false; } public boolean registerMenuItem(String menuname, JMenuItem mi){ @@ -76,6 +97,7 @@ String n = ((JMenu)c[i]).getText(); if (menuname.equals(n)){ ((JMenu)c[i]).add(mi); + menubar.repaint(MAX_REPAINT_DELAY); return true; } } @@ -88,4 +110,49 @@ registerMenu("Help"); } + public boolean hasMenu(String menuName){ + Component[] c = menubar.getComponents(); + for (int i = c.length -1 ; i > -1;i--){ + String n = ((JMenu)c[i]).getText(); + if (menuName.equals(n)){ + return true; + } + } + return false; + } + + public boolean hasMenuItem(String menuName, String menuItemName){ + JMenu m = getMenuWithName(menuName); + if (m != null){ + JMenuItem i = getMenuItemWithName(m, menuItemName); + if (i != null){ + return true; + } + } + return false; + } + + private JMenu getMenuWithName(String menuName){ + Component[] c = menubar.getComponents(); + for (int i = c.length -1 ; i > -1;i--){ + JMenu n = (JMenu)c[i]; + if (menuName.equals(n.getText())){ + return n; + } + } + return null; + } + + + private JMenuItem getMenuItemWithName(JMenu m, String menuItemName){ + if(m == null){ return null; } //no such menu (bailout) + Component[] c = m.getMenuComponents(); + for (int i = c.length -1 ; i > -1;i--){ + JMenuItem n = (JMenuItem)c[i]; + if (menuItemName.equals(n.getText())){ + return n; + } + } + return null; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Snowdog <sn...@ga...> - 2006-04-05 16:37:27
|
Mark Tarrabain wrote: > On a different note... > > At the moment, I'm trying to put together what is a fairly robust dice > rolling library that might be used by the system (tentatively placed in > openrpg2.common.core.dice), and I think I am almost done. > > The dice system I'm working on supports textual as well as numeric dice, > and a programming level API for defining new types of dice and new > functions that can operate on either individual values or collections of > dice rolls. It supports minimum and maximum rolls, as well as rerolling > values that should be excluded (but the way I handle dice rerolling is > handled in a deterministic fashion, so that it always completes > immediately, in case the code needs to be executed by the server). > Great news. Keep us posted on your progress. |
From: Snowdog <sn...@ga...> - 2006-04-05 16:20:39
|
NeoSkye wrote: > Hi, working on the GUI I realized that we may want a > "Window" Menu, which I can handle just fine through > the MenuManager, except for one thing. The "Window" > menu (which may evolve into a "Module" menu > someday...it aspires to greatness) needs to be able to > remove MenuItems from a Menu, and the current > MenuManager gives no way to do this. > > I'll leave that to the creator if they want to tackle > it, or I can throw it in, if they're so inclined. Just > let me know so I can get that in as soon as possible. I'll see if I can't throw that into the MenuManager for you today. > > Also, right now I have cascade and tile planned, are > there any other window arrangements people would like > to see? "Minimize All"? (so its easy to get things out of the way.) |
From: Mark T. <ma...@ly...> - 2006-04-05 08:46:11
|
NeoSkye wrote: > This is probably a good time to let everyone know that > I am using(and intend to continue to use) JSKD 1.4 so > I had no idea that show() was deprecated. Well, to be honest, I didn't know that it was only deprecated as of 1.5. or else I would have also mentioned something about that when I commented. > I'll get > right on that. Let me know if there are any other > deprecated things i can fix. Other than the addition of generics, the API differences between 1.4 and 1.5 are fairly slight, and I'd say that the chances of stumbling across something else that is deprecated in 1.5 that isn't in 1.4 and there exists another way of doing it in 1.4 that ISN'T deprecated in 1.5 is going to be pretty small. Don't worry though... I'll let you know. :) --- On a different note... At the moment, I'm trying to put together what is a fairly robust dice rolling library that might be used by the system (tentatively placed in openrpg2.common.core.dice), and I think I am almost done. The dice system I'm working on supports textual as well as numeric dice, and a programming level API for defining new types of dice and new functions that can operate on either individual values or collections of dice rolls. It supports minimum and maximum rolls, as well as rerolling values that should be excluded (but the way I handle dice rerolling is handled in a deterministic fashion, so that it always completes immediately, in case the code needs to be executed by the server). >> Mark |
From: NeoSkye <djj...@ya...> - 2006-04-05 06:47:40
|
Hi, working on the GUI I realized that we may want a "Window" Menu, which I can handle just fine through the MenuManager, except for one thing. The "Window" menu (which may evolve into a "Module" menu someday...it aspires to greatness) needs to be able to remove MenuItems from a Menu, and the current MenuManager gives no way to do this. I'll leave that to the creator if they want to tackle it, or I can throw it in, if they're so inclined. Just let me know so I can get that in as soon as possible. Also, right now I have cascade and tile planned, are there any other window arrangements people would like to see? __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |
From: NeoSkye <djj...@ya...> - 2006-04-05 03:50:54
|
This is probably a good time to let everyone know that I am using(and intend to continue to use) JSKD 1.4 so I had no idea that show() was deprecated. I'll get right on that. Let me know if there are any other deprecated things i can fix. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |
From: <sno...@us...> - 2006-04-04 21:27:28
|
Revision: 42 Author: snowdog_ Date: 2006-04-04 14:27:21 -0700 (Tue, 04 Apr 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=42&view=rev Log Message: ----------- Added support for command line -debug option to set default logging level so DevConsole can catch messages that occur at startup. Made the splashscreen reflect actual operations rather than just placeholders. Modified Paths: -------------- trunk/src/openrpg2/Client.java trunk/src/openrpg2/Server.java trunk/src/openrpg2/client/core/ORPGClient.java trunk/src/openrpg2/common/core/logging/DevConsole.java trunk/src/openrpg2/server/core/ORPGServer.java Added Paths: ----------- trunk/src/openrpg2/common/util/LogLevelSetter.java Modified: trunk/src/openrpg2/Client.java =================================================================== --- trunk/src/openrpg2/Client.java 2006-04-04 18:02:03 UTC (rev 41) +++ trunk/src/openrpg2/Client.java 2006-04-04 21:27:21 UTC (rev 42) @@ -60,6 +60,7 @@ helpString.append("--help Display this help message and exit\n"); helpString.append("-v Print version information and exit\n"); helpString.append("-check Does system checks and diagnostics then exits\n"); + helpString.append("-debug [ALL] Sets initial logging level for debugging startup issues."); //handled by DevConsole class System.out.println(helpString.toString()); System.exit(ORPGConstants.NORMAL_TERMINATION); } Modified: trunk/src/openrpg2/Server.java =================================================================== --- trunk/src/openrpg2/Server.java 2006-04-04 18:02:03 UTC (rev 41) +++ trunk/src/openrpg2/Server.java 2006-04-04 21:27:21 UTC (rev 42) @@ -81,6 +81,7 @@ helpString.append("-v Print version information and exit\n"); helpString.append("-c Run the server in nongraphical console mode\n"); helpString.append("-check Does system checks and diagnostics then exits\n"); + helpString.append("-debug [ALL] Sets initial logging level for debugging startup issues."); //handled by DevConsole class System.out.println(helpString.toString()); System.exit(ORPGConstants.NORMAL_TERMINATION); } Modified: trunk/src/openrpg2/client/core/ORPGClient.java =================================================================== --- trunk/src/openrpg2/client/core/ORPGClient.java 2006-04-04 18:02:03 UTC (rev 41) +++ trunk/src/openrpg2/client/core/ORPGClient.java 2006-04-04 21:27:21 UTC (rev 42) @@ -35,57 +35,69 @@ public class ORPGClient { private JMenuItem menuItem_quit = null; - private DevConsole devconsole = new DevConsole(); + private DevConsole devconsole = null; private SystemLogger sysLogger = null; private HashMap argMap = null; public ORPGClient(HashMap argmap) { argMap = argmap; - sysLogger = new SystemLogger(devconsole); + + + } + + private void setUpLogging(){ + devconsole = new DevConsole(); + sysLogger = new SystemLogger(devconsole); + devconsole.setSystemLoggerCallback(sysLogger); devconsole.postSystemInfo(); devconsole.postUserInfo(); } + public void execute(){ SplashScreen splash = new SplashScreen(); - splash.setProgress("OpenRPG2 Initializing", 0); - ___DEBUG___SIMULATE_LOADING_TIME(500000); - //shared.devconsole.post("Loading Preferences"); - splash.setProgress("Preferences Loaded", 10); + /* SPLASH SCREEN UPDATE */splash.setProgress("OpenRPG2 Initializing", 0); + setUpLogging(); + + + /* SPLASH SCREEN UPDATE */splash.setProgress("Initializing Network", 10); + NetworkClient nc = new NetworkClient(); + + /* SPLASH SCREEN UPDATE */splash.setProgress("Initializing Modules", 20); + ClientModuleLoader ml = new ClientModuleLoader(); + ml.setNetworkModule(new NetworkClientModule(nc)); + + + /* SPLASH SCREEN UPDATE */splash.setProgress("Initializing Engine", 40); + Engine zeus = new Engine(nc, ml, devconsole, ORPGConstants.OPMODE_CLIENT); + + + /* SPLASH SCREEN UPDATE */splash.setProgress("Starting Engine", 50); + zeus.start(); + + + /* SPLASH SCREEN UPDATE */splash.setProgress("Loading Preferences", 70); ___DEBUG___SIMULATE_LOADING_TIME(300000); - // TODO create message queue object - splash.setProgress("Message Queue Created",20); - ___DEBUG___SIMULATE_LOADING_TIME(300000); - // TODO start processing object - splash.setProgress("Message Processors Created",30); - ___DEBUG___SIMULATE_LOADING_TIME(300000); - // TODO create network object - splash.setProgress("Starting Network Engine",40); - ___DEBUG___SIMULATE_LOADING_TIME(300000); - // TODO instance UI manager - splash.setProgress("Building UI",50); - ___DEBUG___SIMULATE_LOADING_TIME(300000); - // TODO load/register all modules - splash.setProgress("Loading Modules",70); - ___DEBUG___SIMULATE_LOADING_TIME(300000); - splash.setProgress("Checking for updates",85); + + + /* SPLASH SCREEN UPDATE */splash.setProgress("Checking for updates",85); ___DEBUG___SIMULATE_LOADING_TIME(500000); - // TODO attempt to contact openrpg.com for updates - splash.setProgress("Welcome to OpenRPG2",100); + + + /* SPLASH SCREEN UPDATE */splash.setProgress("Welcome to OpenRPG2",100); ___DEBUG___SIMULATE_LOADING_TIME(300000); + splash.dismiss(); splash = null; System.gc(); //force a garbage collector sweep to clean things up - NetworkClient nc = new NetworkClient(); - ClientModuleLoader ml = new ClientModuleLoader(); - ml.setNetworkModule(new NetworkClientModule(nc)); - Engine zeus = new Engine(nc, ml, devconsole, ORPGConstants.OPMODE_CLIENT); - zeus.start(); + + + if ( ! nc.connect() ){ System.out.println("DEBUG: ORPGClient::execute() connection in NetworkClient failed!!"); } @@ -100,7 +112,7 @@ while (a < (x*multiplier)) { a=a+1; for (int i = 0; i < multiplier; i++ ){ - b = ((x*x)/(x*3+3))*x; + b = ((x*x)/(x*3+3))*x; } } } Modified: trunk/src/openrpg2/common/core/logging/DevConsole.java =================================================================== --- trunk/src/openrpg2/common/core/logging/DevConsole.java 2006-04-04 18:02:03 UTC (rev 41) +++ trunk/src/openrpg2/common/core/logging/DevConsole.java 2006-04-04 21:27:21 UTC (rev 42) @@ -43,6 +43,7 @@ private static JMenuItem devmenuitem = null; private static final int MAXLINES = 200; //maximum number of text lines allowed in textdisplay private static SystemLogger sysLogger = null; + private static final String[] loglevels = {"SEVERE","WARNING","INFO","CONFIG","FINE","FINER","FINEST","ALL" }; private Logger log = Logger.getLogger(this.getClass().getName()); @@ -71,6 +72,21 @@ } } + private void updateCurrentLoggingLevel(){ + if (loglevelbox == null){ return; } + if (sysLogger != null){ + String logl = sysLogger.getLoggingLevel(); + for (int i = 0; i < loglevels.length; i++){ + if (logl.compareToIgnoreCase(loglevels[i])==0){ + loglevelbox.setSelectedIndex(i); + return; + } + } + } + loglevelbox.setSelectedIndex(2); //hardcoded to match default in SystemLogger.java (info level); + } + + /** Creates the DevConsole window if required */ private void buildConsoleWindow(){ if (devconsole == null){ @@ -82,10 +98,8 @@ textdisplay.setForeground(Color.BLACK); textdisplay.setMargin(new java.awt.Insets(4, 4, 4,4)); textdisplay.setFont(new Font("Arial",Font.PLAIN,10)); - String[] loglevels = {"SEVERE","WARNING","INFO","CONFIG","FINE","FINER","FINEST","ALL" }; loglevelbox = new JComboBox(loglevels); loglevelbox.setEditable(false); - loglevelbox.setSelectedIndex(2); //hardcoded to match default in SystemLogger.java loglevelbox.setFont(new Font("Arial",Font.PLAIN,10)); loglevelbox.setSize(100, 0); loglevelbox.addActionListener(this); @@ -135,6 +149,7 @@ * Show the developers console */ public void show(){ + updateCurrentLoggingLevel(); devmenuitem.setText("Hide Developer Console"); devconsole.setVisible(true); } @@ -176,5 +191,6 @@ public void setSystemLoggerCallback(SystemLogger ref){ sysLogger = ref; + updateCurrentLoggingLevel(); } } Added: trunk/src/openrpg2/common/util/LogLevelSetter.java =================================================================== --- trunk/src/openrpg2/common/util/LogLevelSetter.java (rev 0) +++ trunk/src/openrpg2/common/util/LogLevelSetter.java 2006-04-04 21:27:21 UTC (rev 42) @@ -0,0 +1,53 @@ +/* + * LogLevelSetter.java + * + * Author: snowdog + * Created: April 4, 2006, 11:10 AM + * + * $Id$ + * + * ==================================================================== + * 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.util; + +import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import openrpg2.common.core.logging.SystemLogger; + +/** + * + * @author snowdog + */ + +public class LogLevelSetter { + private Logger log = Logger.getLogger(this.getClass().getName()); + + /** Creates a new instance of LogLevelSetter */ + public LogLevelSetter(HashMap argmap, SystemLogger logger) { + if (argmap.containsKey("debug")){ + String level = (String)argmap.get("debug"); + if (level == null){ + logger.setLoggingLevel(Level.FINE); + }else if (level.compareToIgnoreCase("all")==0){ + logger.setLoggingLevel(Level.ALL); + }else { + log.info("Invalid debug level supplied on command line"); + } + } + } + +} Modified: trunk/src/openrpg2/server/core/ORPGServer.java =================================================================== --- trunk/src/openrpg2/server/core/ORPGServer.java 2006-04-04 18:02:03 UTC (rev 41) +++ trunk/src/openrpg2/server/core/ORPGServer.java 2006-04-04 21:27:21 UTC (rev 42) @@ -29,6 +29,7 @@ import openrpg2.common.core.network.NetworkConnection; import openrpg2.common.core.network.NetworkServer; import openrpg2.common.core.network.NetworkServerModule; +import openrpg2.common.util.LogLevelSetter; /** @@ -41,8 +42,9 @@ public ORPGServer(HashMap argmap) { DevConsole d = new DevConsole(); SystemLogger sysLogger = new SystemLogger(d); + new LogLevelSetter(argmap, sysLogger); + d.setSystemLoggerCallback(sysLogger); //allows for log level checking in DevConsole - System.out.println("ORPGServer class init"); d.postSystemInfo(); d.postUserInfo(); d.post("----------------------------------------"); @@ -55,7 +57,6 @@ server.setServerAddress(new InetSocketAddress(NetworkConnection.DEFAULT_HOST, NetworkConnection.DEFAULT_PORT)); server.startServer(); - System.out.println("ORPGServer constructor exit"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2006-04-04 18:02:15
|
Revision: 41 Author: snowdog_ Date: 2006-04-04 11:02:03 -0700 (Tue, 04 Apr 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=41&view=rev Log Message: ----------- Made changes required to integrate the Developer Console into the new GUI system. Modified Paths: -------------- trunk/src/openrpg2/client/core/ORPGClient.java trunk/src/openrpg2/common/core/ORPGConstants.java trunk/src/openrpg2/common/core/engine/Engine.java trunk/src/openrpg2/common/core/gui/GUIManager.java trunk/src/openrpg2/common/core/network/NetworkServer.java trunk/src/openrpg2/server/core/ORPGServer.java Modified: trunk/src/openrpg2/client/core/ORPGClient.java =================================================================== --- trunk/src/openrpg2/client/core/ORPGClient.java 2006-04-04 00:54:00 UTC (rev 40) +++ trunk/src/openrpg2/client/core/ORPGClient.java 2006-04-04 18:02:03 UTC (rev 41) @@ -84,7 +84,8 @@ NetworkClient nc = new NetworkClient(); ClientModuleLoader ml = new ClientModuleLoader(); ml.setNetworkModule(new NetworkClientModule(nc)); - Engine zeus = new Engine(nc, ml, ORPGConstants.OPMODE_CLIENT); + Engine zeus = new Engine(nc, ml, devconsole, ORPGConstants.OPMODE_CLIENT); + zeus.start(); if ( ! nc.connect() ){ System.out.println("DEBUG: ORPGClient::execute() connection in NetworkClient failed!!"); } Modified: trunk/src/openrpg2/common/core/ORPGConstants.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGConstants.java 2006-04-04 00:54:00 UTC (rev 40) +++ trunk/src/openrpg2/common/core/ORPGConstants.java 2006-04-04 18:02:03 UTC (rev 41) @@ -46,6 +46,7 @@ //OPERATION MODE CONSTANTS + static final public int OPMODE_UNDEFINED = 0; static final public int OPMODE_CLIENT = 1; static final public int OPMODE_SERVER = 2; static final public int OPMODE_DEFAULT = OPMODE_CLIENT; //default as client @@ -55,7 +56,10 @@ static final public int FATAL_NO_NETWORK_HOOK = 10; static final public int FATAL_NO_MODULE_LOADER = 11; static final public int FATAL_NETWORK_MODULE_FAIL = 12; + static final public int FATAL_OPMODE_INVALID = 13; + static final public int FATAL_LOGGING_ENVIRONMENT = 14; + /** * Creates a new instance of ORPGConstants */ Modified: trunk/src/openrpg2/common/core/engine/Engine.java =================================================================== --- trunk/src/openrpg2/common/core/engine/Engine.java 2006-04-04 00:54:00 UTC (rev 40) +++ trunk/src/openrpg2/common/core/engine/Engine.java 2006-04-04 18:02:03 UTC (rev 41) @@ -21,9 +21,11 @@ package openrpg2.common.core.engine; +import java.util.logging.Logger; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.ORPGMessage; import openrpg2.common.core.gui.GUIManager; +import openrpg2.common.core.logging.DevConsole; import openrpg2.common.core.network.NetworkMessageRelay; import openrpg2.common.core.route.RouteManager; @@ -38,17 +40,68 @@ private ModuleManager moduleManager; private RouteManager routeManager; - private NetworkMessageRelay networkRelay; + private NetworkMessageRelay networkRelay = null;; private GUIManager guiManager; + private ModuleLoader moduleLoader = null; + private DevConsole developerConsole = null; + private int OperationMode = ORPGConstants.OPMODE_UNDEFINED; + private Logger log = Logger.getLogger(this.getClass().getName()); + /** * Creates a new instance of Engine */ - public Engine(NetworkMessageRelay network, ModuleLoader modLoader, int OperationMode) { + public Engine(){ + } + + public Engine(NetworkMessageRelay network, ModuleLoader modLoader, DevConsole devCon, int OpMode) { networkRelay = network; + moduleLoader = modLoader; + OperationMode = OpMode; + developerConsole = devCon; - guiManager = new GUIManager(); - moduleManager = new ModuleManager(modLoader) ; + + } + public void setNetwork(NetworkMessageRelay network){ + networkRelay = network; + } + + public void setModuleLoader(ModuleLoader modLoader){ + moduleLoader = modLoader; + } + + public void setOpMode(int OpMode){ + OperationMode = OpMode; + } + + public void setDevConsole(DevConsole d){ + developerConsole = d; + } + + private void performPrestartCheck(){ + if (developerConsole == null){ + log.severe("Engine Prestart Failed: No Developer Console Set"); + System.exit(ORPGConstants.FATAL_LOGGING_ENVIRONMENT); + } + if (networkRelay == null){ + log.severe("Engine Prestart Failed: No Network Relay Set"); + System.exit(ORPGConstants.FATAL_NO_NETWORK_HOOK); + } + if (moduleLoader == null){ + log.severe("Engine Prestart Failed: No Module Loader Set"); + System.exit(ORPGConstants.FATAL_NO_MODULE_LOADER); + } + if (OperationMode == ORPGConstants.OPMODE_UNDEFINED ){ + log.severe("Engine Prestart Failed: Invalid Engine Operation Mode"); + System.exit(ORPGConstants.FATAL_OPMODE_INVALID); + } + } + + + public void start(){ + performPrestartCheck(); + guiManager = new GUIManager(developerConsole); + moduleManager = new ModuleManager(moduleLoader) ; moduleManager.setGUIManager(guiManager); moduleManager.setMode(OperationMode); moduleManager.registerNetwork(networkRelay); @@ -56,15 +109,15 @@ moduleManager.initialize(); }catch (NoNetworkHookException nnhe ){ //a serious error occured!! - System.err.println("ORPG2 Fatal Error! Cause: "+nnhe.getMessage()); + log.severe("ORPG2 Fatal Error! Cause: "+nnhe.getMessage()); nnhe.printStackTrace(); System.exit(ORPGConstants.FATAL_NO_NETWORK_HOOK); }catch (NoModuleLoaderException nmle){ - System.err.println("ORPG2 Fatal Error! Cause: "+nmle.getMessage()); + log.severe("ORPG2 Fatal Error! Cause: "+nmle.getMessage()); nmle.printStackTrace(); System.exit(ORPGConstants.FATAL_NO_MODULE_LOADER); }catch (NoSuchModuleException nsme){ - System.err.println("ORPG2 Fatal Error! Cause: "+nsme.getMessage()); + log.severe("ORPG2 Fatal Error! Cause: "+nsme.getMessage()); nsme.printStackTrace(); System.exit(ORPGConstants.FATAL_NETWORK_MODULE_FAIL); } Modified: trunk/src/openrpg2/common/core/gui/GUIManager.java =================================================================== --- trunk/src/openrpg2/common/core/gui/GUIManager.java 2006-04-04 00:54:00 UTC (rev 40) +++ trunk/src/openrpg2/common/core/gui/GUIManager.java 2006-04-04 18:02:03 UTC (rev 41) @@ -26,6 +26,7 @@ import javax.swing.JMenuItem; import javax.swing.JPanel; import openrpg2.common.core.gui.mdi.MDIManager; +import openrpg2.common.core.logging.DevConsole; /** * This class handles starting the GUI based on user settings and preferences and acts as @@ -39,10 +40,12 @@ private ManageableGUI managedGui; private JMenuItem menuItem_quit; + /** Creates a new instance of GUIManager */ - public GUIManager() { + public GUIManager(DevConsole devConsole) { menuManager = new MenuManager(); menuManager.createBaseMenus(); + menuManager.registerMenuItem("Developer", devConsole.getMenuItem()); managedGui = locatePreferedGUI(); initGUI(); managedGui.showGUI(); Modified: trunk/src/openrpg2/common/core/network/NetworkServer.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkServer.java 2006-04-04 00:54:00 UTC (rev 40) +++ trunk/src/openrpg2/common/core/network/NetworkServer.java 2006-04-04 18:02:03 UTC (rev 41) @@ -35,6 +35,7 @@ import java.util.Observable; import java.util.Observer; import java.util.Set; +import java.util.logging.Logger; import openrpg2.common.core.ORPGMessage; import openrpg2.common.core.ORPGMessageQueue; @@ -64,6 +65,7 @@ private NetworkThreadPool threadPool; private Hashtable clients = new Hashtable(); private Object monitorLock = new Object(); + private Logger log = Logger.getLogger(this.getClass().getName()); static final int DEFAULT_THREAD_POOL_SIZE = 5; private int threadPoolSize = DEFAULT_THREAD_POOL_SIZE; @@ -149,7 +151,7 @@ } } } - System.out.println("[DEBUG] NetworkServer - Monitor thread terminating"); + log.finer("Monitor thread terminating"); } }; monitorThread.start(); @@ -176,11 +178,11 @@ selector = Selector.open(); ssc = ServerSocketChannel.open(); ssc.socket().bind(serverAddress); - System.out.println("SERVER: Bound to "+ssc.socket().getInetAddress().getHostAddress()+" on port "+ssc.socket().getLocalPort()); + log.info("SERVER: Bound to "+ssc.socket().getInetAddress().getHostAddress()+" on port "+ssc.socket().getLocalPort()); ssc.configureBlocking(false); ssc.register(selector,SelectionKey.OP_ACCEPT); } catch (Exception e){ - System.out.println("EXCEPTION IN SERVER: "+e.getMessage()); + log.warning("EXCEPTION DURING INIT: "+e.getMessage()); e.printStackTrace(); return false; } @@ -207,11 +209,11 @@ try{ readyKeys = selector.select(1000); }catch( ClosedSelectorException e){ - System.out.println("CLOSED SELECTOR EXCEPTION IN SERVER: "+e.getMessage()); + log.warning("CLOSED SELECTOR EXCEPTION IN SERVER: "+e.getMessage()); e.printStackTrace(); stopServer(); }catch( IOException ioe){ - System.out.println("EXCEPTION IN SERVER: "+ioe.getMessage()); + log.warning("EXCEPTION IN SERVER: "+ioe.getMessage()); ioe.printStackTrace(); } if ((readyKeys > 0)&&(runFlag)){ @@ -248,7 +250,7 @@ // server should be considered "idle" in this situation } } - System.out.println("[DEBUG] NetworkServer - Main select thread terminating"); + log.finer("[DEBUG] Main select thread terminating"); } }; serverThread.start(); @@ -269,7 +271,7 @@ } try{ Thread.sleep(1000); }//wait 2 seconds to let threads finish closing catch(InterruptedException e){} - System.out.println("[DEBUG] NetworkServer::stopServer() killing connections"); + log.finer("[DEBUG] killing connections"); Enumeration en = clients.keys(); while(en.hasMoreElements()){ Integer i = (Integer)en.nextElement(); Modified: trunk/src/openrpg2/server/core/ORPGServer.java =================================================================== --- trunk/src/openrpg2/server/core/ORPGServer.java 2006-04-04 00:54:00 UTC (rev 40) +++ trunk/src/openrpg2/server/core/ORPGServer.java 2006-04-04 18:02:03 UTC (rev 41) @@ -39,21 +39,19 @@ /** Creates a new instance of ORPGServer */ public ORPGServer(HashMap argmap) { - DevConsole d = new DevConsole(); + DevConsole d = new DevConsole(); SystemLogger sysLogger = new SystemLogger(d); System.out.println("ORPGServer class init"); d.postSystemInfo(); d.postUserInfo(); d.post("----------------------------------------"); - d.post("SERVER STARTED"); - d.show(); NetworkServer server = new NetworkServer(); ServerModuleLoader ml = new ServerModuleLoader(); ml.setNetworkModule(new NetworkServerModule(server)); - Engine thor = new Engine(server, ml, ORPGConstants.OPMODE_SERVER); - + Engine thor = new Engine(server, ml, d, ORPGConstants.OPMODE_SERVER); + thor.start(); server.setServerAddress(new InetSocketAddress(NetworkConnection.DEFAULT_HOST, NetworkConnection.DEFAULT_PORT)); server.startServer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Snowdog <sn...@ga...> - 2006-04-04 16:21:16
|
Mark Tarrabain wrote: > At line 60 of MDIManager.java > > mainMDIFrame.show(); > > According to the java api docs, show() should be replaced by > setVisible(true). It was depreciated as of 1.5, being as we are targeting 1.4 its not technically a problem. However setVisible(boolean) is supported by 1.4 also so it should be switched (*pokes NeoSkye*) > Hmm... why does it seem like most of my comments to this list are some > sort of whacked out attempt at source code quality control? > > >> Mark Only you can answer that question. --Snowdog |
From: Mark T. <ma...@ly...> - 2006-04-04 05:56:18
|
At line 60 of MDIManager.java mainMDIFrame.show(); According to the java api docs, show() should be replaced by setVisible(true). Hmm... why does it seem like most of my comments to this list are some sort of whacked out attempt at source code quality control? >> Mark |
From: <sno...@us...> - 2006-04-04 00:54:11
|
Revision: 40 Author: snowdog_ Date: 2006-04-03 17:54:00 -0700 (Mon, 03 Apr 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=40&view=rev Log Message: ----------- Added basic command line arg handling routines including a switch to run console based server. Modified Paths: -------------- trunk/src/openrpg2/Client.java trunk/src/openrpg2/Server.java trunk/src/openrpg2/client/core/ORPGClient.java trunk/src/openrpg2/common/core/ORPGConstants.java trunk/src/openrpg2/server/core/ORPGServer.java Added Paths: ----------- trunk/src/openrpg2/common/util/ArgumentParser.java Modified: trunk/src/openrpg2/Client.java =================================================================== --- trunk/src/openrpg2/Client.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/Client.java 2006-04-04 00:54:00 UTC (rev 40) @@ -6,7 +6,10 @@ package openrpg2; +import java.util.HashMap; import openrpg2.client.core.ORPGClient; +import openrpg2.common.core.ORPGConstants; +import openrpg2.common.util.ArgumentParser; /** * @@ -14,8 +17,8 @@ */ public class Client { - + /** Startup Class for OpenRPG2. Handles any pre-application start activities that need done.*/ public Client() { } @@ -27,17 +30,42 @@ */ public static void main(String[] args) { + HashMap argMap = ArgumentParser.parseArgs(args); + if (argMap.containsKey("-help")){ showConsoleHelp(); } + if (argMap.containsKey("v")){ showVersion(); } + if (argMap.containsKey("check")){ doDiagnosticCheck(); } - //TODO handle command line args here boolean runclient = true; - - if (runclient == true){ + + + if (runclient == true){ //start the client - ORPGClient orpg = new ORPGClient(); + ORPGClient orpg = new ORPGClient(argMap); orpg.execute(); - } - else{ + } else{ //do some ther function... perhaps auto-testing or diagnostics? } } + + private static void doDiagnosticCheck(){ + //TODO: do some directory checking, network probing, or whatever then exit + System.err.println("ERROR: -check COMMAND NOT IMPLEMENTED YET"); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + private static void showConsoleHelp(){ + StringBuffer helpString = new StringBuffer(); + helpString.append(ORPGConstants.getOpenRPG2Name()); + helpString.append(" Client Command Line Help\n"); + helpString.append("--help Display this help message and exit\n"); + helpString.append("-v Print version information and exit\n"); + helpString.append("-check Does system checks and diagnostics then exits\n"); + System.out.println(helpString.toString()); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + private static void showVersion(){ + System.out.println(ORPGConstants.getVersionString()); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } } \ No newline at end of file Modified: trunk/src/openrpg2/Server.java =================================================================== --- trunk/src/openrpg2/Server.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/Server.java 2006-04-04 00:54:00 UTC (rev 40) @@ -20,6 +20,9 @@ package openrpg2; +import java.util.HashMap; +import openrpg2.common.core.ORPGConstants; +import openrpg2.common.util.ArgumentParser; import openrpg2.server.core.ORPGServer; /** @@ -28,8 +31,8 @@ */ public class Server { - + /** Startup Class for OpenRPG2. Handles any pre-application start activities that need done.*/ public Server() { } @@ -41,18 +44,53 @@ */ public static void main(String[] args) { - System.out.println("Server running"); + boolean runserver = true; + + + HashMap argmap = ArgumentParser.parseArgs(args); //TODO handle command line args here - boolean runserver = true; + + if (argmap.containsKey("-help")){ showConsoleHelp(); } + if (argmap.containsKey("v")){ showVersion(); } + if (argmap.containsKey("check")){ doDiagnosticCheck(); } + - if (runserver == true){ - //start the client - ORPGServer orpg = new ORPGServer(); - + if (argmap.containsKey("c")){ + //Launch the console based server + System.err.println("ERROR: CONSOLE BASED SERVER NOT IMPLEMENTED"); } else{ - //do some ther function... perhaps auto-testing or diagnostics? - } - System.out.println("main() exit"); + //start the GUI-based server + ORPGServer orpg = new ORPGServer(argmap); + + } + } + + private static void doDiagnosticCheck(){ + //TODO: do some directory checking, network probing, or whatever then exit + System.err.println("ERROR: -check COMMAND NOT IMPLEMENTED YET"); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + private static void showConsoleHelp(){ + StringBuffer helpString = new StringBuffer(); + helpString.append(ORPGConstants.getOpenRPG2Name()); + helpString.append(" Server Command Line Help\n"); + helpString.append("--help Display this help message and exit\n"); + helpString.append("-v Print version information and exit\n"); + helpString.append("-c Run the server in nongraphical console mode\n"); + helpString.append("-check Does system checks and diagnostics then exits\n"); + System.out.println(helpString.toString()); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + private static void showVersion(){ + System.out.println(ORPGConstants.getVersionString()); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + + + } \ No newline at end of file Modified: trunk/src/openrpg2/client/core/ORPGClient.java =================================================================== --- trunk/src/openrpg2/client/core/ORPGClient.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/client/core/ORPGClient.java 2006-04-04 00:54:00 UTC (rev 40) @@ -19,14 +19,12 @@ */ package openrpg2.client.core; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.util.HashMap; import javax.swing.JMenuItem; import openrpg2.common.core.SplashScreen; import openrpg2.common.core.logging.DevConsole; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.engine.Engine; -import openrpg2.common.core.gui.GUIManager; import openrpg2.common.core.logging.SystemLogger; import openrpg2.common.core.network.NetworkClient; import openrpg2.common.core.network.NetworkClientModule; @@ -39,9 +37,11 @@ private JMenuItem menuItem_quit = null; private DevConsole devconsole = new DevConsole(); private SystemLogger sysLogger = null; + private HashMap argMap = null; - public ORPGClient() { + public ORPGClient(HashMap argmap) { + argMap = argmap; sysLogger = new SystemLogger(devconsole); devconsole.postSystemInfo(); devconsole.postUserInfo(); Modified: trunk/src/openrpg2/common/core/ORPGConstants.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGConstants.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/common/core/ORPGConstants.java 2006-04-04 00:54:00 UTC (rev 40) @@ -27,7 +27,11 @@ */ public abstract class ORPGConstants { //"official" OpenRPG2 Application Name - static final public String OPENRPG2_NAME = "OpenRPG2 (alpha)"; + static final public String OPENRPG2_NAME = "OpenRPG2"; + static final public String OPENRPG2_NAME_SUFFIX = "(alpha)"; + static final public int OPENRPG2_MAJOR_VERSION = 2; + static final public int OPENRPG2_MINOR_VERSION = 0; + static final public int OPENRPG2_MICRO_VERSION = 1; //ORPGMESSAGE HEADER CONSTANTS @@ -47,6 +51,7 @@ static final public int OPMODE_DEFAULT = OPMODE_CLIENT; //default as client //TERMINATION CODES ( for use with System.Exit() ) + static final public int NORMAL_TERMINATION = 0; static final public int FATAL_NO_NETWORK_HOOK = 10; static final public int FATAL_NO_MODULE_LOADER = 11; static final public int FATAL_NETWORK_MODULE_FAIL = 12; @@ -56,4 +61,23 @@ */ public ORPGConstants() {} + static public String getOpenRPG2Name(){ + return OPENRPG2_NAME+" "+OPENRPG2_NAME_SUFFIX; + } + + static public String getVersionString(){ + StringBuffer n = new StringBuffer(); + n.append(OPENRPG2_NAME); + n.append(" "); + n.append(OPENRPG2_MAJOR_VERSION); + n.append("."); + n.append(OPENRPG2_MINOR_VERSION); + n.append("."); + n.append(OPENRPG2_MICRO_VERSION); + n.append(" "); + n.append(OPENRPG2_NAME_SUFFIX); + + return n.toString(); + } + } Added: trunk/src/openrpg2/common/util/ArgumentParser.java =================================================================== --- trunk/src/openrpg2/common/util/ArgumentParser.java (rev 0) +++ trunk/src/openrpg2/common/util/ArgumentParser.java 2006-04-04 00:54:00 UTC (rev 40) @@ -0,0 +1,76 @@ +/* + * ArgumentParser.java + * + * Author: snowdog + * Created: April 3, 2006, 5:38 PM + * + * $Id$ + * + * ==================================================================== + * 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.util; + +import java.util.HashMap; + +/** + * + * @author snowdog + */ + +public class ArgumentParser { + + /** Creates a new instance of ArgumentParser */ + public ArgumentParser() { + + } + + public static HashMap parseArgs( String[] args ){ + HashMap a = new HashMap(); + String currentKey = null; + String currentValue = null; + + for (int i = 0; i < args.length; i++){ + String c = args[i]; + + if (c.startsWith("-")){ + if (currentKey != null ){ + //close out active key/vals before processing next cmd arg + a.put(currentKey, currentValue); + currentKey = null; + currentValue = null; + } + c = c.substring(1, c.length()); + c.trim(); + currentKey = c; + + }else{ + if (currentKey != null){ + if (currentValue == null){ + currentValue = c; + } else{ + currentValue = currentValue +" "+c; + } + } + } + } + if (currentKey != null ){ + //close out active key/vals before processing next cmd arg + a.put(currentKey, currentValue); + } + + return a; + } +} Modified: trunk/src/openrpg2/server/core/ORPGServer.java =================================================================== --- trunk/src/openrpg2/server/core/ORPGServer.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/server/core/ORPGServer.java 2006-04-04 00:54:00 UTC (rev 40) @@ -21,7 +21,7 @@ package openrpg2.server.core; import java.net.InetSocketAddress; -import javax.swing.JFrame; +import java.util.HashMap; import openrpg2.common.core.logging.DevConsole; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.engine.Engine; @@ -38,7 +38,7 @@ public class ORPGServer { /** Creates a new instance of ORPGServer */ - public ORPGServer() { + public ORPGServer(HashMap argmap) { DevConsole d = new DevConsole(); SystemLogger sysLogger = new SystemLogger(d); @@ -53,6 +53,7 @@ ServerModuleLoader ml = new ServerModuleLoader(); ml.setNetworkModule(new NetworkServerModule(server)); Engine thor = new Engine(server, ml, ORPGConstants.OPMODE_SERVER); + server.setServerAddress(new InetSocketAddress(NetworkConnection.DEFAULT_HOST, NetworkConnection.DEFAULT_PORT)); server.startServer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Snowdog <sn...@ga...> - 2006-04-02 06:47:33
|
Not everyone needs or even likes using a console based server. I for one would prefer to use a GUI based one simply because It would allow for more information to be displayed in a formatted manner (beyond what text can do). Perhaps graphs of clients vs time or being able to view a map server side or whatever. As the JRE contains the graphical components even on a text based terminal bound server there is no harm in leaving them in the code. I am fully aware that the server must be able to operate in a non-graphical environment. However there is no reason why the option can't exist to run it in a graphical one if the operator so chooses. The size of the gui code (as most that will be in the client modules anyway) is probably not going to be significant for the server. The alternative to making the gui components common puts us back into the discussion about separate server client applications. A separate custom client could be created to provide graphical support to the console based server (a server controlling client). While possible I'm not sure its as practical as simply disabling the GUI and using a console interface on the fly as needed. Mark Tarrabain wrote: > Subject line says it all. Server side code doesn't need to maintain a > gui, but putting it in there means that it will be bundled in both jar > files. > > >> Mark > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live > webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > _______________________________________________ > Openrpg-v2-dev mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openrpg-v2-dev > > |
From: Mark T. <ma...@ly...> - 2006-04-02 00:08:46
|
Subject line says it all. Server side code doesn't need to maintain a gui, but putting it in there means that it will be bundled in both jar files. >> Mark |
From: <md...@gm...> - 2006-04-01 23:45:15
|
Snowdog wrote: > I would say thats wise. The only place I can think of where order of > submodules might be important is in a chat module that filters text as > you'll want your filters to run in a defined order. So perhaps > 'undefined, module implementation dependent' is the best way to leave it. Even then, we have a lot of OpenRPG1 plugins that filter chat, and I have yet to encounter a problem with the order in which the plugins run, which is also officially undefined. It's certainly possible, theoretically, but it has not popped up yet, so allow me to reiterate that this is truly a non-issue. --mDuo13 |