• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 10:06
CET 16:06
KST 00:06
  • 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 Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle BW General Discussion What happened to TvZ on Retro? Brood War web app to calculate unit interactions [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33 Beyond All Reason
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Russo-Ukrainian War Thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2279 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 States17265 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 1h 54m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SteadfastSC 350
TKL 341
Reynor 49
mcanning 46
StarCraft: Brood War
Britney 32905
Rain 4173
actioN 1647
Horang2 1446
Jaedong 1184
Shuttle 522
Stork 472
EffOrt 303
firebathero 261
Leta 114
[ Show more ]
Barracks 105
Shinee 97
ggaemo 96
Hyun 80
PianO 66
LaStScan 65
JYJ49
Shine 49
Mong 31
Rock 25
Movie 24
ToSsGirL 22
Bale 20
zelot 15
HiyA 10
soO 10
sorry 8
Sacsri 7
Dota 2
Gorgc5504
qojqva1773
Dendi1127
XcaliburYe145
LuMiX0
Counter-Strike
oskar115
Heroes of the Storm
Khaldor136
Other Games
B2W.Neo1782
DeMusliM470
Hui .333
Lowko306
Pyrionflax240
Fuzer 206
febbydoto6
Organizations
Dota 2
PGL Dota 2 - Main Stream8720
PGL Dota 2 - Secondary Stream3341
Other Games
EGCTV119
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• Berry_CruncH154
• StrangeGG 72
• IndyKCrew
• AfreecaTV YouTube
• intothetv
• Kozan
• sooper7s
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• Michael_bg 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2112
• Ler59
League of Legends
• Nemesis2754
Other Games
• WagamamaTV236
Upcoming Events
IPSL
1h 54m
ZZZero vs rasowy
Napoleon vs KameZerg
OSC
3h 54m
BSL 21
4h 54m
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
18h 54m
RSL Revival
18h 54m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
20h 54m
Cure vs herO
Reynor vs TBD
WardiTV Korean Royale
20h 54m
BSL 21
1d 4h
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
1d 4h
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d 7h
[ Show More ]
Wardi Open
1d 20h
Monday Night Weeklies
2 days
WardiTV Korean Royale
2 days
BSL: GosuLeague
3 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
5 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
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 © 2025 TLnet. All Rights Reserved.