• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 15:53
CET 20:53
KST 04:53
  • 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
ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
BGE Stara Zagora 2026 cancelled7Blizzard Classic Cup - Tastosis announced as captains12Weekly Cups (March 2-8): ByuN overcomes PvT block4GSL CK - New online series18BSL Season 224
StarCraft 2
General
BGE Stara Zagora 2026 cancelled BGE Stara Zagora 2026 announced ByuL: The Forgotten Master of ZvT Terran AddOns placement Blizzard Classic Cup - Tastosis announced as captains
Tourneys
StarCraft Evolution League (SC Evo Biweekly) https://www.facebook.com/BubaSocks.Official/ [GSL CK] Team Maru vs. Team herO WardiTV Team League Season 10 Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
The PondCast: SC2 News & Results Mutation # 516 Specter of Death Mutation # 515 Together Forever Mutation # 514 Ulnar New Year
Brood War
General
ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion Gypsy to Korea Are you ready for ASL 21? Hype VIDEO
Tourneys
[Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours IPSL Spring 2026 is here! ASL Season 21 Qualifiers March 7-8
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Zealot bombing is no longer popular?
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread PC Games Sales Thread No Man's Sky (PS4 and PC)
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Mexico's Drug War NASA and the Private Sector
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Movie Discussion! [Req][Books] Good Fantasy/SciFi books [Manga] One Piece
Sports
Formula 1 Discussion 2024 - 2026 Football Thread General nutrition recommendations Cricket [SPORT] TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Gaming-Related Deaths
TrAiDoS
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2550 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 States17281 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 4h 7m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 686
IndyStarCraft 107
ProTech107
JuggernautJason78
RushiSC 17
StarCraft: Brood War
sSak 60
scan(afreeca) 51
Dota 2
Gorgc4875
canceldota62
Counter-Strike
fl0m3288
byalli834
Heroes of the Storm
Liquid`Hasu264
Khaldor163
Other Games
gofns46544
tarik_tv16545
Grubby2888
FrodaN2144
summit1g1426
Beastyqt638
B2W.Neo519
KnowMe465
DeMusliM169
C9.Mang0131
Livibee59
Organizations
Dota 2
PGL Dota 2 - Main Stream13987
Other Games
gamesdonequick1755
ComeBackTV 271
BasetradeTV76
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• StrangeGG 48
• Kozan
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• IndyKCrew
StarCraft: Brood War
• blackmanpl 42
• RayReign 8
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• lizZardDota255
League of Legends
• Doublelift1648
• TFBlade1408
Other Games
• imaqtpie1139
• Shiphtur178
Upcoming Events
Replay Cast
4h 7m
CranKy Ducklings
14h 7m
RSL Revival
14h 7m
MaxPax vs Rogue
Clem vs Bunny
WardiTV Team League
16h 7m
uThermal 2v2 Circuit
21h 7m
BSL
1d
Sparkling Tuna Cup
1d 14h
RSL Revival
1d 14h
ByuN vs SHIN
Maru vs Krystianer
WardiTV Team League
1d 16h
Patches Events
1d 21h
[ Show More ]
BSL
2 days
Replay Cast
2 days
Replay Cast
2 days
Wardi Open
2 days
Monday Night Weeklies
2 days
WardiTV Team League
3 days
GSL
4 days
The PondCast
5 days
WardiTV Team League
5 days
Replay Cast
6 days
WardiTV Team League
6 days
Liquipedia Results

Completed

Proleague 2026-03-12
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Jeongseon Sooper Cup
BSL Season 22
Proleague 2026-03-13
RSL Revival: Season 4
Nations Cup 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

CSL Elite League 2026
ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
Acropolis #4
IPSL Spring 2026
CSLAN 4
HSC XXIX
uThermal 2v2 2026 Main Event
NationLESS Cup
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 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.