Can someone show me a good way to use a wait() method in java?
[QUOTE=blacksam;44096372]Can someone show me a good way to use a wait() method in java?[/QUOTE]
You can use the [B]wait[/B] and [B]notify[/B] (along with the [I]synchronized[/I] keyword) methods in order to block a specific thread (by calling wait) until a certain criteria is met (as you then call notify). A little example I've done:
[code]
//test variable
final String something = "testing thread locks";
//task thread
Thread taskThread = new Thread()
{
public void run()
{
//do some menial task
for (int i = 0; i < 65536; i++)
System.out.println("Number: " + i + ".");
try
{
//make sure we're synchronized with the test variable
synchronized (something)
{
//notify (unlock) the object
something.notify();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
};
taskThread.start();
//object is being blocked
System.out.println("Waiting for object...");
try
{
//make sure we're synchronized with the test variable again
synchronized (something)
{
//wait (block) for the object
something.wait();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
//object has been released
System.out.println("Object has been released.");
[/code]
It will create a String test object (it doesn't actually matter what the type of the object is, it could be any). It'll then call the wait method on the object while the task thread (which is simulating doing some background work) is active. Once the task thread is finished, it'll call the notify method on the object, therefore unblocking the main thread and thus allowing the rest of the code to execute.
You should get the output along the lines of:
[code]
Waiting for object...
Number: 0.
Number: 1.
Number: 2.
(and so forth)
Object has been released.
[/code]
Excuse me for raging but it's starting to piss me off. I'm trying to make a Quake mod and when i add sometimes stuff that should work and then it FUCKING DOESN'T
[img]http://puu.sh/7g4dA.png[/img]
[editline]2nd March 2014[/editline]
Well i feel a bit stupid now, i'm too much used to GNU99 C and compiling C code in VS sucks. I forgot extern keyword.
[editline]2nd March 2014[/editline]
Okay nope, you just can't use anything typedef'd. (WHYYYY???)
[editline]2nd March 2014[/editline]
Visual Studio supports only C89, that explains everything.
[QUOTE=cartman300;44100956]
Visual Studio supports only C89, that explains everything.[/QUOTE]
Which VS version? 2013 has C99 support afaik.
Is there any way to do proper alpha blending on a transparent render target without using premultiplied alpha?
I know that the correct equation for alpha compositing is:
[code]resultColor = srcColor * srcAlpha + dstColor * dstAlpha * (1 - srcAlpha)
resultAlpha = srcAlpha + dstAlpha * (1 - srcAlpha)[/code]
So the respective blending factors would be:
[code]srcAlpha dstAlpha * (1 - srcAlpha)
1 (1 - srcAlpha)[/code]
Now the obvious problem here is the fact that there is no way to use "dstAlpha * (1 - srcAlpha)" as a blend factor. Most people get away with simply using (1 - srcAlpha) instead because the destination alpha is usually 1, but this isn't acceptable for me since I'm rendering on a render target which has an alpha channel.
Every site about alpha blending recommends using premultiplied alpha, however I am working with Source, which doesn't use that anywhere so I would need to change the entire engine to use premultiplied alpha everywhere, and I'd rather not do that.
So is there any alternative or am I pretty much fucked?
Does anyone know of a way to execute keyboard shortcuts through C++? For example, if a program that uses the shortcut ctrl+s to save is open, could the c++ program execute that combination?
[QUOTE=JakeAM;44111331]Does anyone know of a way to execute keyboard shortcuts through C++? For example, if a program that uses the shortcut ctrl+s to save is open, could the c++ program execute that combination?[/QUOTE]
The reliable method is [URL="http://msdn.microsoft.com/en-us/library/ms646310%28VS.85%29.aspx"]SendInput[/URL], which always hits the active window.
[URL="https://stackoverflow.com/a/1230643/410020"]Apparently you can use messages too, which may or may not work depending on the program.[/URL]
I plan on using the leap SDK and at the moment have the LeapSDK folder. I've never had to use a library before though, where exactly do you put it so that the includes work?
Working in Flash, is there a way to add a movieclip to the stage, where the name of the movieclip is a variable? If not, what's the best way to do it?
This is what I'm trying to do.
[code]
function spawnTile(tileName:String):void
{
spawnSegment = new [tileName]();
buildingArray.push(spawnSegment);
addChild(spawnSegment);
spawnSegment.x = 200;
spawnSegment.y = 200;
}
[/code]
[QUOTE=~ZOMG;44113614]Working in Flash, is there a way to add a movieclip to the stage, where the name of the movieclip is a variable? If not, what's the best way to do it?[/QUOTE]
[url=http://stackoverflow.com/questions/6934141/instantiate-a-class-from-a-string-in-actionscript-3]Instantiate a class from a string in ActionScript 3[/url]
[QUOTE=JakeAM;44111609]I plan on using the leap SDK and at the moment have the LeapSDK folder. I've never had to use a library before though, where exactly do you put it so that the includes work?[/QUOTE]
If you're talking about a VC++ windows project, extract it anywhere you want, and then go to your Project Properties -> C/C++ -> General, and add the header directory to the 'Additional Include Directory' field.
I've seen people add their include directories in the VC++ Directories -> Include Directories field, but I prefer to leave only default dirs there.
[QUOTE=SteveUK;44103431]Which VS version? 2013 has C99 support afaik.[/QUOTE]
I use VS2012, might update to 2013. I still don't know what was the problem but i got it sorted. Mind telling me where you heard VS2013 had C99 support?
Any good modern OpenGL GUI libraries? I know about GWEN, but are there any alternatives? Not that GWEN is bad, but I think there may perhaps be something even simpler for me.
[QUOTE=SteveUK;44103431]Which VS version? 2013 has C99 support afaik.[/QUOTE]
[QUOTE=cartman300;44115336]I use VS2012, might update to 2013. I still don't know what was the problem but i got it sorted. Mind telling me where you heard VS2013 had C99 support?[/QUOTE]
It doesn't. They added a couple standard libraries but the language features are still unsupported.
[QUOTE=ArgvCompany;44115945]Any good modern OpenGL GUI libraries? I know about GWEN, but are there any alternatives? Not that GWEN is bad, but I think there may perhaps be something even simpler for me.[/QUOTE]
AntTweakBar, if you are using SFML 2.1 let me know, I have updated the event file to use it
[QUOTE=Richy19;44116274]AntTweakBar, if you are using SFML 2.1 let me know, I have updated the event file to use it[/QUOTE]
I'm using GLFW. So I thought AntTweakBar only allowed you to "tweak values", period. But I noticed now that it supports, for example, what I think is buttons with events and stuff like that. So thanks!
FYI I'm looking to make something roughly the complexity of the Box2D testbed (in terms of GUI).
[QUOTE=ThePuska;44115979]It doesn't. They added a couple standard libraries but the language features are still unsupported.[/QUOTE]
[url=http://msdn.microsoft.com/en-us/library/hh409293.aspx]What's New for Visual C++ in Visual Studio 2013[/url]
[quote]
Supports these ISO C99 language features:
_Bool
Compound literals.
Designated initializers.
Mixing declarations with code.
[/quote]
Okay, so I accidentally deleted some files in a game I was coding in. I got everything back and fixed, and now XNA is telling me:
"[B]Program[/B] 'C:\Users\Christian\documents\visual studio 2010\Projects\Bonomo Flappy Bird\Bonomo Flappy Bird\Bonomo Flappy Bird\obj\x86\Debug\Bonomo Flappy Bird.exe' [B]does not contain a static 'Main' method suitable for an entry point Bonomo Flappy Bird[/B]"
[QUOTE=Goz3rr;44116726][url=http://msdn.microsoft.com/en-us/library/hh409293.aspx]What's New for Visual C++ in Visual Studio 2013[/url][/QUOTE]
Oh. Nice to know they're not completely ignoring C, though many features are still missing.
So Android is pissing me off.
[t]https://dl.dropboxusercontent.com/u/8416055/DeleteMe/WoweMuchAngerSoFrustration.png[/t]
The circled red box is supposed to be drawing from 60% of the reported screen height to 100%. That is clearly not starting at 60%.
In my custom view class:
[b]GameView[/b]
[code] public int getScreenWidth() {
if (cachedMetrics == null) {
cachedMetrics = new DisplayMetrics();
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(cachedMetrics);
}
return cachedMetrics.widthPixels;
}
public int getScreenHeight() {
if (cachedMetrics == null) {
cachedMetrics = new DisplayMetrics();
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(cachedMetrics);
}
return cachedMetrics.heightPixels;
}[/code]
My draw code:
[code]
public void drawObject(Canvas canvas) {
int sw = MainActivity.gameView.getScreenHeight();
int sh = MainActivity.gameView.getScreenWidth();
ShapeDrawable pathDrawable;
pathDrawable = new ShapeDrawable(new RectShape());
pathDrawable.getPaint().setARGB(255,255,0,0);
pathDrawable.setBounds(30,(int)(sh * 0.6),80,(int)(sh * 1));
pathDrawable.draw(canvas);
}[/code]
Note that I set sh as the width, and sw as the height, because it is a landscape app. I have debugged the values and this is correct, and according to the debug, this box should be drawing properly. The only thing I can think is that the metrics are returning bad values.
I am using the AVD, emulating the Nexus 4 without scaling the display to real size.
Anyone have any ideas on how to fix this?
[QUOTE=Exigent;44117883]Okay, so I accidentally deleted some files in a game I was coding in. I got everything back and fixed, and now XNA is telling me:
"[B]Program[/B] 'C:\Users\Christian\documents\visual studio 2010\Projects\Bonomo Flappy Bird\Bonomo Flappy Bird\Bonomo Flappy Bird\obj\x86\Debug\Bonomo Flappy Bird.exe' [B]does not contain a static 'Main' method suitable for an entry point Bonomo Flappy Bird[/B]"[/QUOTE]
Exactly what it says, make sure you have a static void Main(string[] args), normally this is in Program.cs
-snip-
Nevermind, I'll just choose one on my own.
I'm trying to perform some image correction in C++. The easiest bitmap filetype I've found to load are Targa files, but they don't seem to be loading correctly.
[code]struct Color
{
unsigned char Blue,Green,Red;
};
struct Targa_Header
{
char IDLength;
char ColorMapType;
char ImageType;
char CMapDepth;//should be after the next two shorts
short CMapStart;
short CMapLength;
short XOffset;
short YOffset;
short Width;
short Height;
char PixelDepth;
char ImageDescriptor;
};
Color* Targa(Targa_Header* Header,_TCHAR* FilePath)
{
ifstream File(FilePath);
int Size = sizeof(Targa_Header);
if(!File)
return false;
//Load the Header into a buffer.
char* Buffer = new char[Size];
File.read(Buffer,Size);
//Some of the data is mixed up, it needs to be switched around in order to be useful.
char Holder = Buffer[7];
for(int i=3;i<7;i++) Buffer[i] = Buffer[i+1];
Buffer[3] = Holder;
//Save the header to the loaded data.
*Header = *(Targa_Header*)Buffer;
delete[] Buffer;
//Size = Length * Width * Number of channels
Size = Header->Width * Header->Height * 3;
Buffer = new char[Size];
File.read(Buffer,Size);
if(!File)
{
if(File.failbit)
cout << "Failbit is set to 1." << endl;
if(File.badbit)
cout << "Badbit is set to 1." << endl;
cout << endl;
delete[] Buffer;
return nullptr;
}
return (Color*)Buffer;
}[/code]
It loads the header perfectly, but only loads a random amount of the bitmap itself unique to each file I try. On debug, Failbit and Badbit are both set to 1. I've never had this happen before, and it occurs consistently across multiple computers I run the program on. The rest of the image correction works as it should, but only the loading is giving me errors. Does anyone know how I can get around this problem? Or is there an easier way to load Bitmaps without external libraries?
[QUOTE=Copperbotte;44122359]I'm trying to perform some image correction in C++. The easiest bitmap filetype I've found to load are Targa files, but they don't seem to be loading correctly.
It loads the header perfectly, but only loads a random amount of the bitmap itself unique to each file I try. On debug, Failbit and Badbit are both set to 1. I've never had this happen before, and it occurs consistently across multiple computers I run the program on. The rest of the image correction works as it should, but only the loading is giving me errors. Does anyone know how I can get around this problem? Or is there an easier way to load Bitmaps without external libraries?[/QUOTE]
Did you check that sizeof(Targa_Header) == 18?
Just a wild guess here, but if the compiler adds padding to your struct, then you not only will read wrong data in the header, but in the end also access the file outside its boundaries, which might set the failbits.
In AS3, is there a way to have a function whose parameters (or arguments, all this new lingo is confusing) are of different date types?
This is my function:
[code]
function spawnTile(tileType:String, storyNumber:int, xCoord:int):void //picks either a blank wall or a window
{
code
}
[/code]
This is how I call it:
[code]
aaa.addEventListener(MouseEvent.CLICK, aaaFunc);
function aaaFunc(evt:Event)
{
function spawnTile(door, 1, 400);
}
[/code]
And this is the error I get:
[code]
Scene 1, Layer 'input', Frame 1, Line 13 1084: Syntax error: expecting rightparen before rightbrace.
Scene 1, Layer 'input', Frame 1, Line 12 1084: Syntax error: expecting identifier before 1.
[/code]
Now it spits out:
[code]
Scene 1, Layer 'input', Frame 1, Line 12 1084: Syntax error: expecting identifier before "door".
[/code]
[editline]4th March 2014[/editline]
Oh jesus, I just realized.
Should be
[code]
spawnTile(door, 1, 400);
[/code]
Instead of:
[code]
function spawnTile(door, 1, 400);
[/code]
[editline]4th March 2014[/editline]
[QUOTE=Dienes;44124958][code]function spawnTile(door, 1, 400);[/code]should probably be[code]spawnTile("door", 1, 400);[/code][/QUOTE]
This is right, thank you, I didn't pick up on that.
wow. i accidentally deleted my program.cs.
im such an idiot. :suicide:
[QUOTE=Exigent;44126077]wow. i accidentally deleted my program.cs.
im such an idiot. :suicide:[/QUOTE]
VS moves deleted files into the trash bin, so they aren't really "permanently" lost.
Try version control (Hg or Git), they make mistakes like this a lot less severe.
Oh, yeah, I know that. It's just I can't believe I missed something so obvious
Sorry, you need to Log In to post a reply to this thread.