|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On June 01 2011 17:40 omG.[RaYnE] wrote: well that didn't work, thanks for the help though...ot's time for me to die now
Yup, looks like it. Send me a card from the other side 
OR:
Show how your code now looks and what exactly is not working.
|
ok, a small amount of last strokes in coding this xml stuff and I at least noobly managed to get all those nodes and values, here's the code: + Show Spoiler + <?php $xmlfile = $_GET['xmlfile']; $directory = "dfnnxmlfiles/"; $xmlfile = $directory . $xmlfile ; $xml = simplexml_load_file("$xmlfile");
echo"<pre>"; echo $xml->getName() . "<br />";
foreach($xml->children() as $child) { echo"-"; echo $child->getName() . ": " . $child . "";
foreach($child->children() as $child2){ echo"<br>--"; echo $child2->getName() . ": " . $child2 . ""; foreach($child2->attributes() as $a => $b) { echo " $a: $b "; } foreach($child2->children() as $child3){ echo"<br>---"; echo $child3->getName() . ": " . $child3 . ""; foreach($child3->attributes() as $a => $b) { echo " $a: $b "; } foreach($child3->children() as $child4){ echo"<br>----"; echo $child4->getName() . ": " . $child4 . ""; foreach($child4->attributes() as $a => $b) { echo " $a: $b "; } foreach($child4->children() as $child5){ echo"<br>-----"; echo $child5->getName() . ": " . $child5 . ""; foreach($child5->attributes() as $a => $b) { echo " $a: $b "; } foreach($child5->children() as $child6){ echo"<br>------"; echo $child6->getName() . ": " . $child6 . ""; foreach($child6->attributes() as $a => $b) { echo " $a: $b "; } foreach($child6->children() as $child7){ echo"<br>-------"; echo $child7->getName() . ": " . $child7 . ""; foreach($child7->attributes() as $a => $b) { echo " $a: $b "; } foreach($child7->children() as $child8){ echo"<br>--------"; echo $child8->getName() . ": " . $child8 . ""; foreach($child8->attributes() as $a => $b) { echo " $a: $b "; } foreach($child8->children() as $child9){ echo"<br>---------"; echo $child9->getName() . ": " . $child9 . ""; foreach($child9->attributes() as $a => $b) { echo " $a: $b "; } } } } } } } } } foreach($child->attributes() as $a => $b) { echo " $a: $b "; }echo"<br>"; } ?>
....I beleive I can make a loop statement out of this but err...i'm afraid I might mess it up more, good sir do you know the so called TeamViewer Software? if you do maybe at least you could take a peek at my piece of turd work
|
On June 01 2011 19:21 omG.[RaYnE] wrote:ok, a small amount of last strokes in coding this xml stuff and I at least noobly managed to get all those nodes and values, here's the code: + Show Spoiler + <?php $xmlfile = $_GET['xmlfile']; $directory = "dfnnxmlfiles/"; $xmlfile = $directory . $xmlfile ; $xml = simplexml_load_file("$xmlfile");
echo"<pre>"; echo $xml->getName() . "<br />";
foreach($xml->children() as $child) { echo"-"; echo $child->getName() . ": " . $child . "";
foreach($child->children() as $child2){ echo"<br>--"; echo $child2->getName() . ": " . $child2 . ""; foreach($child2->attributes() as $a => $b) { echo " $a: $b "; } foreach($child2->children() as $child3){ echo"<br>---"; echo $child3->getName() . ": " . $child3 . ""; foreach($child3->attributes() as $a => $b) { echo " $a: $b "; } foreach($child3->children() as $child4){ echo"<br>----"; echo $child4->getName() . ": " . $child4 . ""; foreach($child4->attributes() as $a => $b) { echo " $a: $b "; } foreach($child4->children() as $child5){ echo"<br>-----"; echo $child5->getName() . ": " . $child5 . ""; foreach($child5->attributes() as $a => $b) { echo " $a: $b "; } foreach($child5->children() as $child6){ echo"<br>------"; echo $child6->getName() . ": " . $child6 . ""; foreach($child6->attributes() as $a => $b) { echo " $a: $b "; } foreach($child6->children() as $child7){ echo"<br>-------"; echo $child7->getName() . ": " . $child7 . ""; foreach($child7->attributes() as $a => $b) { echo " $a: $b "; } foreach($child7->children() as $child8){ echo"<br>--------"; echo $child8->getName() . ": " . $child8 . ""; foreach($child8->attributes() as $a => $b) { echo " $a: $b "; } foreach($child8->children() as $child9){ echo"<br>---------"; echo $child9->getName() . ": " . $child9 . ""; foreach($child9->attributes() as $a => $b) { echo " $a: $b "; } } } } } } } } } foreach($child->attributes() as $a => $b) { echo " $a: $b "; }echo"<br>"; } ?>
....I beleive I can make a loop statement out of this but err...i'm afraid I might mess it up more, good sir do you know the so called TeamViewer Software? if you do maybe at least you could take a peek at my piece of turd work  This might sound harsh, but it will be good for you: 1. Stop everything you are currently doing. Have you done that? Ok, next step:
2. Go to the Documentation: http://de3.php.net/manual/en/simplexml.examples-basic.php 3. Begin with the first line and read it. 4. Move to the next line and read it. 5. Repeat Step 4 until you reach the last line. 6. If you still haven't understood the examples, return to step 3.
Alternative: Get another job.
It's obvious that you haven't even read the examples or the basic usage part.
|
I wish I could stop this nonsense too, and thank god this isn't my job
may I also add that it isn't just 1 xml file there would be lots of xml involved in this project and each nodes on a xml file would be different from another. and my main goal is to have a single page capable of displaying all the xml values on all different types of xml.
the flow is like: main page(select a xml file)-->[process all xml nodes,values,attributes etc]-->display
|
System.out.println("Allman Style");
I thought I would be funny
|
Ok more specific help then.
Question 1: I have a program made in Java that uses the Apache POI API to combine multiple .docs into a single one. Problem is, I can't get text formatting right. I'm trying to set up the output text to be 10pt Times New Roman in a 2 column format. Currently, I have no idea how to create the 2 column format and setting InsertAfter(String, CharacterProperties) with CharacterProperties having setFontSize(20) and setBold(true) doesn't change anything, the output is still in default 12pt Cambria font.
Question 2: I'm making a game. I want to start on a main menu, then move into submenus depending on what I select (New Game, Options, Controls, etc). Is there an easy way to do this besides huge if/else ladders? Also can someone give me an example of multithreading in games? I don't really see any uses atm.
Thanks
|
On June 02 2011 08:57 xHassassin wrote: Ok more specific help then.
Question 1: I have a program made in Java that uses the Apache POI API to combine multiple .docs into a single one. Problem is, I can't get text formatting right. I'm trying to set up the output text to be 10pt Times New Roman in a 2 column format. Currently, I have no idea how to create the 2 column format and setting InsertAfter(String, CharacterProperties) with CharacterProperties having setFontSize(20) and setBold(true) doesn't change anything, the output is still in default 12pt Cambria font.
Question 2: I'm making a game. I want to start on a main menu, then move into submenus depending on what I select (New Game, Options, Controls, etc). Is there an easy way to do this besides huge if/else ladders? Also can someone give me an example of multithreading in games? I don't really see any uses atm.
Thanks
For question 2.
You can abstract the different screens into some type (say Screen or GameScreen) and have a stack controlling what screen is currently shown. This will enable you to go backward and so on.
Initially your stack is:
MainMenu
Your user selects "New Game". Fine, you just push "NewGameScreen" ontop of the stack and now you have:
NewGameScreen MainMenu
And so on. It also works while you're currently playing. Say your user pauses; you will go from:
InGameScreen
to:
PauseScreen InGameScreen
You could make cool effects like drawing every screen below top level of the stack with some opacity.
You will have to think about this (hard) for yourself. But you NEED to avoid those huge if-else things. Abstract as much as you can.
As for multithreading, it would only be useful if say you have a heavy physics engine in your game that does a lot of computation where the algorithms used are amendable to parallelization. Even then it's not clear if it's worth creating threads as they may be too heavyweight. Rather than doing that, you can focus on using the GPU to the fullest. It's becoming more and more popular to use the GPU; especially for data parallel tasks (just search GPGPU). I suppose a possible other uses would be to have one thread constantly sending/receiving network traffic but that depends on the type of game you're making.
|
On June 02 2011 09:39 ParasitJonte wrote:Show nested quote +On June 02 2011 08:57 xHassassin wrote: Ok more specific help then.
Question 1: I have a program made in Java that uses the Apache POI API to combine multiple .docs into a single one. Problem is, I can't get text formatting right. I'm trying to set up the output text to be 10pt Times New Roman in a 2 column format. Currently, I have no idea how to create the 2 column format and setting InsertAfter(String, CharacterProperties) with CharacterProperties having setFontSize(20) and setBold(true) doesn't change anything, the output is still in default 12pt Cambria font.
Question 2: I'm making a game. I want to start on a main menu, then move into submenus depending on what I select (New Game, Options, Controls, etc). Is there an easy way to do this besides huge if/else ladders? Also can someone give me an example of multithreading in games? I don't really see any uses atm.
Thanks For question 2. You can abstract the different screens into some type (say Screen or GameScreen) and have a stack controlling what screen is currently shown. This will enable you to go backward and so on. Initially your stack is: MainMenu Your user selects "New Game". Fine, you just push "NewGameScreen" ontop of the stack and now you have: NewGameScreen MainMenu And so on. It also works while you're currently playing. Say your user pauses; you will go from: InGameScreen to: PauseScreen InGameScreen You could make cool effects like drawing every screen below top level of the stack with some opacity. You will have to think about this (hard) for yourself. But you NEED to avoid those huge if-else things. Abstract as much as you can. As for multithreading, it would only be useful if say you have a heavy physics engine in your game that does a lot of computation where the algorithms used are amendable to parallelization. Even then it's not clear if it's worth creating threads as they may be too heavyweight. Rather than doing that, you can focus on using the GPU to the fullest. It's becoming more and more popular to use the GPU; especially for data parallel tasks (just search GPGPU). I suppose a possible other uses would be to have one thread constantly sending/receiving network traffic but that depends on the type of game you're making.
Hmm, I'm not sure how that would work.
Say I have the screen class extending JPanel.
In my main JFrame class, I add the background screen. Then I'll add the mainmenu screen.
So you do stuff in main menu, and then you're done. How would you move to the next screen? Your stack only exists in JFrame, the menu class is unable to push another frame in or pop itself out.
Can you give me an example?
|
When you close main menu the background screen is displayed because it is on top of the stack.
|
On June 03 2011 03:56 xHassassin wrote:Show nested quote +On June 02 2011 09:39 ParasitJonte wrote:On June 02 2011 08:57 xHassassin wrote: Ok more specific help then.
Question 1: I have a program made in Java that uses the Apache POI API to combine multiple .docs into a single one. Problem is, I can't get text formatting right. I'm trying to set up the output text to be 10pt Times New Roman in a 2 column format. Currently, I have no idea how to create the 2 column format and setting InsertAfter(String, CharacterProperties) with CharacterProperties having setFontSize(20) and setBold(true) doesn't change anything, the output is still in default 12pt Cambria font.
Question 2: I'm making a game. I want to start on a main menu, then move into submenus depending on what I select (New Game, Options, Controls, etc). Is there an easy way to do this besides huge if/else ladders? Also can someone give me an example of multithreading in games? I don't really see any uses atm.
Thanks For question 2. You can abstract the different screens into some type (say Screen or GameScreen) and have a stack controlling what screen is currently shown. This will enable you to go backward and so on. Initially your stack is: MainMenu Your user selects "New Game". Fine, you just push "NewGameScreen" ontop of the stack and now you have: NewGameScreen MainMenu And so on. It also works while you're currently playing. Say your user pauses; you will go from: InGameScreen to: PauseScreen InGameScreen You could make cool effects like drawing every screen below top level of the stack with some opacity. You will have to think about this (hard) for yourself. But you NEED to avoid those huge if-else things. Abstract as much as you can. As for multithreading, it would only be useful if say you have a heavy physics engine in your game that does a lot of computation where the algorithms used are amendable to parallelization. Even then it's not clear if it's worth creating threads as they may be too heavyweight. Rather than doing that, you can focus on using the GPU to the fullest. It's becoming more and more popular to use the GPU; especially for data parallel tasks (just search GPGPU). I suppose a possible other uses would be to have one thread constantly sending/receiving network traffic but that depends on the type of game you're making. Hmm, I'm not sure how that would work. Say I have the screen class extending JPanel. In my main JFrame class, I add the background screen. Then I'll add the mainmenu screen. So you do stuff in main menu, and then you're done. How would you move to the next screen? Your stack only exists in JFrame, the menu class is unable to push another frame in or pop itself out. Can you give me an example?
You'll need a way for the menu class to have a reference to the derived JFrame class or some manager. Here's a basic OOP example of how to navigate gamestates (Screens). I don't recommend newing/deleting screens like this though. Preallocate when possible.
There are other ways, but this is the most intuitive IMO.
Pseudcode is c++ based ScreenMgr: + Show Spoiler + class Screen { Screen() {} virtual void Update() = 0; }
class ScreenMgr { static Stack < Screen* > s_screens; ScreenMgr() {} static void Update() { Screen* topScreen = s_screens.Peek(); if(topScreen) topScreen->Update(); }
static void PushScreen(Screen* nextScreen) { s_screens.Push(nextScreen); } static void PopScreen() { Screen* poppedScreen = s_screens.Peek(); s_screens.Pop(); delete poppedScreen; } }
Screens: + Show Spoiler + class MainMenu : public Screen { MainMenu() {} virtual void Update() { if(userSelectedOptions) { ScreenMgr::Push(new Options()); } } }
class Options : public Screen { Options() {} virtual void Update() { if(userIsDoneWithOptions) { ScreenMgr::Pop(); } } }
Game Loop + Show Spoiler + void main() { ScreenMgr screenManager; screenManager.Push(new MainMenu()); while(true) { screenManager.Update(); } }
|
So this is where I'm confused
ScreenMgr::Push(new Options());
What does the :: mean? How would this translate to java?
Also, side question. Does java have a way to manipulate loaded images? I worked with the AP Gridworld code for my class and it had this built in function to redraw sprites in different colors, even though only the default color (red) was loaded. I never really found how this worked since the code is so immense and I couldn't find where the function was implemented. Basically it would take in a Color(R,G,B) and all non black parts of that sprite would be turned into that color.
|
I have a quick question about base and derived classes, so for this example Derived extends Base, and Derived has an additional int member variable called 'A' that is not in Base.
Queue<Base> oBaseQueue = new Queue<Base>();
Derived oDerived = new Derived(); oDerived.A = 1;
oBaseQueue.Enqueue(oDerived);
Now if I call Dequeue the queue, and cast the returned object as a Derived object, will A still be 1, even though the object was a Base object for a bit? I would think it would be, but I'm not sure.
|
On June 03 2011 12:00 xHassassin wrote:So this is where I'm confused ScreenMgr::Push(new Options()); What does the :: mean? How would this translate to java?
ScreenMgr::Push is equivalent to ScreenMgr.Push in Java as long as Push is a static method. To be honest I prefer Singleton classes rather than making everything static.
|
Sup folks, got a big problem on my C++ game, C Run-time mutex thread related.
I have two different 'enemies', which movement are controlled by a mutex function: one can't move if the other one is already moving. I already debugged the program, but the 'enemies' are not respecting the mutex. They move together, never stopping. Here's the movement function:
unsigned WINAPI Enemy::Move1(LPVOID LpParam) /*a static function btw*/{ WaitForSingleObject (mutex_enemy, INFINITE); //... ReleaseMutex (mutex_enemy); } And here's the function that calls it:
HANDLE mutex_enemy, hndThread1, hndThread2; void Enemy::start() { mutex_enemy = CreateMutex (NULL, FALSE, NULL); hndThread_1 = (HANDLE) _beginthreadex(NULL, 0, Move1, NULL, 0, NULL); hndThread_2 = (HANDLE) _beginthreadex(NULL, 0, Move2, NULL, 0, NULL); } The start() function is called inside a while loop, where the whole game runs. Anyone got any idea on how to make Move1 and Move2 functions run separately?
Thanks in advance!
|
On June 04 2011 15:03 Javadocs wrote:I have a quick question about base and derived classes, so for this example Derived extends Base, and Derived has an additional int member variable called 'A' that is not in Base. Queue<Base> oBaseQueue = new Queue<Base>();
Derived oDerived = new Derived(); oDerived.A = 1;
oBaseQueue.Enqueue(oDerived);
Now if I call Dequeue the queue, and cast the returned object as a Derived object, will A still be 1, even though the object was a Base object for a bit? I would think it would be, but I'm not sure. Pretty sure the answer is yes, since that's a major benefit of abstraction.
|
On June 05 2011 08:07 Hoon wrote:Sup folks, got a big problem on my C++ game, C Run-time mutex thread related. I have two different 'enemies', which movement are controlled by a mutex function: one can't move if the other one is already moving. I already debugged the program, but the 'enemies' are not respecting the mutex. They move together, never stopping. Here's the movement function: unsigned WINAPI Enemy::Move1(LPVOID LpParam) /*a static function btw*/{ WaitForSingleObject (mutex_enemy, INFINITE); //... ReleaseMutex (mutex_enemy); } And here's the function that calls it: HANDLE mutex_enemy, hndThread1, hndThread2; void Enemy::start() { mutex_enemy = CreateMutex (NULL, FALSE, NULL); hndThread_1 = (HANDLE) _beginthreadex(NULL, 0, Move1, NULL, 0, NULL); hndThread_2 = (HANDLE) _beginthreadex(NULL, 0, Move2, NULL, 0, NULL); } The start() function is called inside a while loop, where the whole game runs. Anyone got any idea on how to make Move1 and Move2 functions run separately? Thanks in advance!
Are you able to query the state of the mutex prior to stalling for it to see if a stall would occur? You don't check for mutex_enemy being NULL from CreateMutex- but that may just be because you omitted the code from the example you gave. Also, WaitForSingleObject could be returning a failure clause, in which case it would just continue to execute your code.
I'd do a pass on all the API calls to make sure they're behaving properly.
|
On June 05 2011 19:00 Phunkapotamus wrote:Show nested quote +On June 05 2011 08:07 Hoon wrote:Sup folks, got a big problem on my C++ game, C Run-time mutex thread related. I have two different 'enemies', which movement are controlled by a mutex function: one can't move if the other one is already moving. I already debugged the program, but the 'enemies' are not respecting the mutex. They move together, never stopping. Here's the movement function: unsigned WINAPI Enemy::Move1(LPVOID LpParam) /*a static function btw*/{ WaitForSingleObject (mutex_enemy, INFINITE); //... ReleaseMutex (mutex_enemy); } And here's the function that calls it: HANDLE mutex_enemy, hndThread1, hndThread2; void Enemy::start() { mutex_enemy = CreateMutex (NULL, FALSE, NULL); hndThread_1 = (HANDLE) _beginthreadex(NULL, 0, Move1, NULL, 0, NULL); hndThread_2 = (HANDLE) _beginthreadex(NULL, 0, Move2, NULL, 0, NULL); } The start() function is called inside a while loop, where the whole game runs. Anyone got any idea on how to make Move1 and Move2 functions run separately? Thanks in advance! Are you able to query the state of the mutex prior to stalling for it to see if a stall would occur? You don't check for mutex_enemy being NULL from CreateMutex- but that may just be because you omitted the code from the example you gave. Also, WaitForSingleObject could be returning a failure clause, in which case it would just continue to execute your code. I'd do a pass on all the API calls to make sure they're behaving properly. Yes, I check if mutex_enemy isn't NULL right after creating it, just didn't state it on the example, as you said. I didn't think about the WaitForSingleObject, gonna check it.
Thanks a lot man, I'm really new to Threads. I'm an Electronic Engineer Major but my C++ teacher didn't teach us how to implement mutex inside a while loop neither implement it in Objective C++, which is what he is asking us to do in this game.
|
On June 04 2011 15:03 Javadocs wrote:I have a quick question about base and derived classes, so for this example Derived extends Base, and Derived has an additional int member variable called 'A' that is not in Base. Queue<Base> oBaseQueue = new Queue<Base>();
Derived oDerived = new Derived(); oDerived.A = 1;
oBaseQueue.Enqueue(oDerived);
Now if I call Dequeue the queue, and cast the returned object as a Derived object, will A still be 1, even though the object was a Base object for a bit? I would think it would be, but I'm not sure.
Of course. The object was not a Base object for a bit -- that is absolutely wrong. The object never changes. The queue can just contain objects of lots of different types -- anything that derives from Base, and so it happened to have your Derived object in it.
|
On June 06 2011 04:59 catamorphist wrote: Of course. The object was not a Base object for a bit -- that is absolutely wrong. The object never changes. The queue can just contain objects of lots of different types -- anything that derives from Base, and so it happened to have your Derived object in it.
Yea, I was planning to have a lot of different objects in the Base queue, that are derived from the Base object class. I thought it might still be a Derived object in the base queue, but wasn't entirely sure. I think I learned this in one of my classes years ago, but I must have had a brain-fart. Thanks!
|
Usually I won't ask a simple question, but I got a final coming up so I must ask.
My teacher told the class there would be a question of what file I/O (in C) could be used for. The class was cut short because she ran out of time after explaining a few function of file I/O. From what I gathered it's a simple access read/write function. So I was going to answer ("To revise everyone's grades) or something akin to that.
Is there any special features of file I/O I should be aware of to answer the question appropriately?
|
|
|
|