• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:22
CET 09:22
KST 17:22
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets0$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)12Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1822
StarCraft 2
General
Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns Spontaneous hotkey change zerg Chinese SC2 server to reopen; live all-star event in Hangzhou SC2 All-Star Invitational: Jan 17-18
Tourneys
$25,000 Streamerzone StarCraft Pro Series announced $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) WardiTV Winter Cup WardiTV Mondays SC2 AI Tournament 2026
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes
Brood War
General
Potential ASL qualifier breakthroughs? BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest Data analysis on 70 million replays
Tourneys
[Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10 SLON Grand Finals – Season 2
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Current Meta [G] How to get started on ladder as a new Z player
Other Games
General Games
Beyond All Reason Nintendo Switch Thread Awesome Games Done Quick 2026! Mechabellum Stormgate/Frost Giant Megathread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine Trading/Investing Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced
Blogs
My 2025 Magic: The Gathering…
DARKING
Physical Exercise (HIIT) Bef…
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1266 users

The Big Programming Thread - Page 58

Forum Index > General Forum
Post a Reply
Prev 1 56 57 58 59 60 1032 Next
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.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
June 01 2011 08:44 GMT
#1141
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.
omG.[RaYnE]
Profile Joined October 2007
Philippines100 Posts
Last Edited: 2011-06-01 10:22:48
June 01 2011 10:21 GMT
#1142
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
omG.[RaYnE] ---> rayne_ph :D
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
June 01 2011 11:04 GMT
#1143
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.
omG.[RaYnE]
Profile Joined October 2007
Philippines100 Posts
Last Edited: 2011-06-01 12:44:04
June 01 2011 12:42 GMT
#1144
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
omG.[RaYnE] ---> rayne_ph :D
hirokashi
Profile Blog Joined March 2011
United Kingdom22 Posts
June 01 2011 13:12 GMT
#1145
System.out.println("Allman Style");










I thought I would be funny
xHassassin
Profile Joined November 2010
United States270 Posts
June 01 2011 23:57 GMT
#1146
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
ParasitJonte
Profile Joined September 2004
Sweden1768 Posts
June 02 2011 00:39 GMT
#1147
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.
Hello=)
xHassassin
Profile Joined November 2010
United States270 Posts
Last Edited: 2011-06-02 18:56:38
June 02 2011 18:56 GMT
#1148
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?
Pawsom
Profile Blog Joined February 2009
United States928 Posts
June 02 2011 20:30 GMT
#1149
When you close main menu the background screen is displayed because it is on top of the stack.
Phunkapotamus
Profile Joined April 2010
United States496 Posts
June 02 2011 20:57 GMT
#1150
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();
}
}


"Do a barrel roll"
xHassassin
Profile Joined November 2010
United States270 Posts
Last Edited: 2011-06-03 03:03:02
June 03 2011 03:00 GMT
#1151
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.
Javadocs
Profile Joined July 2010
United States60 Posts
Last Edited: 2011-06-04 06:05:00
June 04 2011 06:03 GMT
#1152
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.



stafu
Profile Blog Joined January 2009
Australia1196 Posts
Last Edited: 2011-06-04 06:15:29
June 04 2011 06:14 GMT
#1153
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.
Hoon
Profile Joined December 2010
Brazil891 Posts
June 04 2011 23:07 GMT
#1154
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!
SEn Fanclub: http://www.teamliquid.net/forum/viewmessage.php?topic_id=170834
Craton
Profile Blog Joined December 2009
United States17274 Posts
June 05 2011 03:05 GMT
#1155
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.
twitch.tv/cratonz
Phunkapotamus
Profile Joined April 2010
United States496 Posts
June 05 2011 10:00 GMT
#1156
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.
"Do a barrel roll"
Hoon
Profile Joined December 2010
Brazil891 Posts
June 05 2011 16:45 GMT
#1157
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.
SEn Fanclub: http://www.teamliquid.net/forum/viewmessage.php?topic_id=170834
catamorphist
Profile Joined May 2010
United States297 Posts
June 05 2011 19:59 GMT
#1158
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.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Javadocs
Profile Joined July 2010
United States60 Posts
Last Edited: 2011-06-06 01:43:06
June 06 2011 01:42 GMT
#1159
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!
Wala.Revolution
Profile Blog Joined November 2006
7584 Posts
June 08 2011 13:45 GMT
#1160
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?
Stuck.
Prev 1 56 57 58 59 60 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 38m
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
Britney 16355
Larva 301
Mong 199
actioN 186
Nal_rA 89
Shuttle 75
Soma 47
Leta 46
Killer 42
zelot 34
[ Show more ]
ZergMaN 29
EffOrt 21
Bale 12
Dota 2
NeuroSwarm93
League of Legends
JimRising 563
C9.Mang0520
Counter-Strike
shoxiejesuss371
allub111
Super Smash Bros
Mew2King175
Other Games
summit1g8191
ceh9253
Sick183
Happy177
RuFF_SC231
Organizations
Other Games
gamesdonequick3157
StarCraft: Brood War
UltimateBattle 80
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• practicex 58
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• RayReign 51
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1535
• Stunt619
• masondota2416
• HappyZerGling153
Upcoming Events
WardiTV Invitational
3h 38m
PiGosaur Cup
16h 38m
WardiTV Invitational
1d 3h
The PondCast
2 days
OSC
2 days
OSC
3 days
All Star Teams
3 days
INnoVation vs soO
sOs vs Scarlett
uThermal 2v2 Circuit
4 days
All Star Teams
4 days
MMA vs DongRaeGu
Rogue vs Oliveira
Sparkling Tuna Cup
5 days
[ Show More ]
OSC
5 days
Replay Cast
6 days
Wardi Open
6 days
Liquipedia Results

Completed

Proleague 2026-01-12
Big Gabe Cup #3
NA Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
OSC Championship Season 13
Underdog Cup #3
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

Escore Tournament S1: W4
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Thunderfire SC2 All-star 2025
Nations Cup 2026
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.