• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 08:22
CEST 14:22
KST 21: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
Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists22[ASL21] Ro16 Preview Pt1: Fresh Flow9
Community News
RSL Revival: Season 5 - Qualifiers and Main Event8Code S Season 1 (2026) - RO12 Results02026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced92026 GSL Tour plans announced15
StarCraft 2
General
Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun Code S Season 1 (2026) - RO12 Results Team Liquid Map Contest #22 - The Finalists Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool MaNa leaves Team Liquid
Tourneys
RSL Revival: Season 5 - Qualifiers and Main Event GSL Code S Season 1 (2026) SC2 INu's Battles#15 <BO.9 2Matches> WardiTV Spring Cup SEL Masters #6 - Solar vs Classic (SC: Evo)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base Mutation # 521 Memorable Boss
Brood War
General
Why there arent any 256x256 pro maps? BGH Auto Balance -> http://bghmmr.eu/ ASL21 General Discussion [BSL22] RO16 Group B - Saturday 21:00 CEST BW General Discussion
Tourneys
[Megathread] Daily Proleagues [ASL21] Ro8 Day 2 Escore Tournament StarCraft Season 2 [BSL22] RO16 Group Stage - 02 - 10 May
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread Daigo vs Menard Best of 10 Diablo IV
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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 TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
ramps on octagon
StaticNine
Sexual Health Of Gamers
TrAiDoS
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2106 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
RSL Revival
10:00
Season 5: Group B
TriGGeR vs NightMareLIVE!
Solar vs TBD
Tasteless757
IntoTheiNu 442
Ryung 326
IndyStarCraft 239
Rex131
3DClanTV 95
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Tasteless 757
Ryung 326
IndyStarCraft 239
Rex 131
Railgan 23
StarCraft: Brood War
Britney 64590
Horang2 1508
Shuttle 894
EffOrt 801
Hyuk 507
Soma 368
Rush 345
firebathero 234
Last 216
ggaemo 206
[ Show more ]
Leta 193
Pusan 148
ToSsGirL 96
PianO 91
Sharp 76
Hm[arnc] 64
[sc1f]eonzerg 59
Sea.KH 40
Barracks 33
NaDa 32
Sacsri 31
IntoTheRainbow 21
JulyZerg 18
yabsab 14
GoRush 13
Noble 12
Shine 7
Terrorterran 4
Dota 2
XaKoH 817
XcaliburYe334
monkeys_forever194
Counter-Strike
zeus1264
edward112
byalli0
Other Games
singsing2230
B2W.Neo1363
Liquid`RaSZi969
DeMusliM406
ArmadaUGS97
Livibee92
MindelVK15
Organizations
Other Games
BasetradeTV592
Dota 2
PGL Dota 2 - Main Stream69
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 11 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos2206
Upcoming Events
uThermal 2v2 Circuit
1h 38m
BSL
6h 38m
IPSL
6h 38m
eOnzErG vs TBD
G5 vs Nesh
Patches Events
11h 38m
Replay Cast
20h 38m
Wardi Open
21h 38m
Afreeca Starleague
21h 38m
Jaedong vs Light
Monday Night Weeklies
1d 3h
Replay Cast
1d 11h
Sparkling Tuna Cup
1d 21h
[ Show More ]
Afreeca Starleague
1d 21h
Snow vs Flash
WardiTV Invitational
1d 22h
GSL
2 days
Classic vs Cure
Maru vs Rogue
GSL
3 days
SHIN vs Zoun
ByuN vs herO
OSC
3 days
OSC
4 days
Replay Cast
4 days
Escore
4 days
The PondCast
4 days
WardiTV Invitational
4 days
Replay Cast
5 days
CranKy Ducklings
5 days
RSL Revival
5 days
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
5 days
BSL
6 days
Replay Cast
6 days
Sparkling Tuna Cup
6 days
RSL Revival
6 days
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
6 days
Liquipedia Results

Completed

Proleague 2026-05-02
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
KK 2v2 League Season 1
Acropolis #4
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Escore Tournament S2: W6
BSL 22 Non-Korean Championship
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 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.