Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Jun 2005
Offline Last Active Jul 18 2013 08:56 PM

Topics I've Started

Java Deadlock Question

17 June 2013 - 12:28 PM

Hello. I've got back into programing with OpenGL (JOGL) since it's so portable. I wanted to make my engine multithreaded so I've read up a Java trail about concurency and stumbled on something interesting here:




How can both threads enter bow if it is synchronized, so that as the article says, they will both be stuck at bowback? Is it possible for threads to enter synchronized methods at the exact same time, but not right after eachother then or wha?


This would completely mess up the whole sync identifier, since threads can pretty much always call the method at the same time...


Really weird, watcha think?

Program Wide Global Vars in C++?

28 December 2012 - 08:48 PM

I've just recently learned from my program that "static" or pointer variables do not neccesseraly mean global program wide. I have a single .h file included for main .cpp and another .cpp file. When I changed the variable in main and read it in the other class it was not the same value as I've set it in the main class, even though it was declared static, or as I've tested even if it is a pointer, in the .h file.


Seems like the only way in C++ to have access to a variable you would like to use in another class is to pass it through a function or a constructor as well as using inheritance. As I recall in Java or C# a static variable or a function can be defined in one class and changed from a class while changing it for all the other classes.


It may be breaking the laws of OOP but I was just wondering if it was possible in C++.


Thank you, and have a nice day!!! smile.png

How to Pass Arrays to Functions for OGL?

06 December 2011 - 05:58 PM

Hello I am having a bit of confusion with C++ and passing a 1D array for vertices into a function when it will be used to fill in the vertex buffer. If I just do this:

GLfloat aVertices[] = {
   -0.8f, -0.8f, 0.0f, 1.0f,
 	0.0f,  0.8f, 0.0f, 1.0f,
 	0.8f, -0.8f, 0.0f, 1.0f


CreateVBO(p_vertices, aVertices);


void CreateVBO(Vertex* theVerts, GLfloat theGLfloat[])
glBufferData(GL_ARRAY_BUFFER, sizeof(theGLfloat), theGLfloat, GL_STATIC_DRAW);

The triangle will not render!!!

but if I insert this code inside the CreateVBO function it works:

void CreateVBO(Vertex* theVerts, GLfloat theGLfloat[])
GLfloat newTestVerArr[12];

for(int i = 0; i < 12; i++)
 	newTestVerArr[i] = theGLfloat[i];
glBufferData(GL_ARRAY_BUFFER, sizeof(newTestVerArr), newTestVerArr, GL_STATIC_DRAW);

It seems like a waste of processing power to copy an array again, so I was wondering if there is a syntax I could use to skip this copy loop. I am confused, since as far as I know the "newTestVerArr" is just a pointer to the first element in the array, just like the "theGLfloat" so why it won't work without the copy I am not sure. If you could explain this to me I would appreciate it.


[.net] Timing with Threads for less than a millisecond

30 September 2010 - 03:25 PM

Heh, I wanted to see if I could make a timer that doesn't use all of the processing power(well at least not one whole core). I was not very successful but technically it should work. I'll explain before posting code. Say you want to have a timer that clicks every 250 microseconds, what you do is create 4 threads at 250 mics intervals and make them sleep for 1 millisecond. You will need more threads if you are doing faster timings or less if you are doing slower timings. That was my idea but the problem is that threads seem to do what ever they want especially when there is other loads on the CPU. So here is the code. I don't know how to make it work better and maybe you have an idea.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Timers;
using System.Runtime.InteropServices;

namespace Imba_Timer
class Program
public Thread[] tCountHF;
public Thread tCountLF;
public static int timeHF = 0;
public static int timeLF = 0;

private static extern bool QueryPerformanceCounter(
out long lpPerformanceCount);

private static extern bool QueryPerformanceFrequency(
out long lpFrequency);

tCountLF = new Thread(ShowTime);

Program(int numThreads)
tCountHF = new Thread[numThreads];

for (int i = 0; i < numThreads; i++)
tCountHF[i] = new Thread(SleepOne);

static void Main(string[] args)
Program myPrg = new Program();



public void StartUpCounter(int microSeconds)
float stepTimeSec = (float)1 * (float)(microSeconds / 1000000) ;
int x = 100;
float secondsPerOpp = 0;
float secondsPerOpp2 = 0;
float incrTime = 0;

long cntsPerSec = 0;
long prevTimeStamp = 0;
long currTimeStamp = 0;

long prevTimeStamp2 = 0;
long currTimeStamp2 = 0;

QueryPerformanceFrequency(out cntsPerSec);


QueryPerformanceCounter(out prevTimeStamp2);

QueryPerformanceCounter(out prevTimeStamp);

while (x > 0)



x = 100;

QueryPerformanceCounter(out currTimeStamp);

secondsPerOpp = (currTimeStamp - prevTimeStamp) * (1.0f / (float)cntsPerSec);

QueryPerformanceCounter(out currTimeStamp2);

secondsPerOpp2 = (currTimeStamp2 - prevTimeStamp2) * (1.0f / (float)cntsPerSec);

incrTime += (secondsPerOpp + secondsPerOpp2);

} while (incrTime < stepTimeSec);


public void ThreadsStartup(int microSec)
int numThreads = 1000 / microSec;

Program start = new Program(numThreads);

Program lowFrequency = new Program();


for (int i = 0; i < numThreads; i++)
start.tCountHF[i].Priority = ThreadPriority.Highest;

public void SleepOne(object obj)

//while (!stop)
for (int g = 0; g < 120000; g++)

public void ShowTime()
//while (!stop);
for (int g = 0; g < 120; g++)
timeLF += 1000;
Console.WriteLine("Hight Frequency Time is: " + timeHF + " ------ " + "Low Frequency Time is: " + timeLF);

For now this code is not very useful since most of these high frequency timings are used in something other than games where you can use the Sleep() function. Plus it is not very precise which I do not know why. Oh well was worth a shot.

[.net] C# Improved Substring with Escape Characters

28 September 2010 - 08:30 AM

I've been trying to use the substring(start, end) function on HTML code, and it doesn't work right because it seems as if this particular function doesn't count the escape characters. So I found a way to go around it. Here is the code I use to get a certain substring from HTML. Maybe this will also ignite Microsoft to put this code in their other form of substring.

public string ImprovedSubstring(string fullString, string startString, string endString)
string theSubstring = "";

int i1 = fullString.IndexOf(startString);

fullString = fullString.Substring(i1);

int i2 = fullString.IndexOf(endString);

theSubstring = fullString.Remove(i2 + endString.Length);

return theSubstring;

LoL there is a plus sign in the last Remove method, some bug on gamedev doesn't show it in preview.

Thank you and hope this helps a little with escape chars.