My fraction adder is having a bit of trouble. If I enter in 1/2 three times, it adds it up to 16/8s
if i enter one 1/2, it says its 10/4s
[url]http://pastebin.com/pyjJYV4P[/url]
Dang it, I need help with a little something for this game project, I'm doing a copter clone (it's for a college thing), But I don't really quite know how to make the walls generate themselfs, I'm assumng it's a new Rectangle, and I could probably randomise the walls a bit but I don't know how to make all the walls move towards the helicopter, if anyone could help, I would be quite the happy chappy.
On each tick just decrement dt * someMultiplier from the x-coordinate.
Man, this is stressing me out, it's for a test thing, and I chose to do this game, It's just the random rectangle blocks I just cannot seem to figure out.
Any help would much much appreciated.
How would I go about writing to a new console screen buffer like when I'm using std::cout to write directly to the screen? Tried searching but couldn't find anything.
Right now I use WriteConsoleOutput and an array that represents each character+property in the buffer. What I want to be able to use something like cout << "string" but instead of writing that to the standard output stream, I want to write it in a new buffer and then swap the two buffers(double buffering).
[code]
COORD bufferSize = {80,25}, bufferOrigin = {0,0}; HANDLE hStdout, hNewBuffer;
CHAR_INFO bufferOutput[2001]; SMALL_RECT srctWriteRect = {0,0,80,25};
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
hNewBuffer = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL
);
SetConsoleScreenBufferSize(hStdout,bufferSize);
SetConsoleActiveScreenBuffer(hStdout);
cout << "test1\n";
SetConsoleActiveScreenBuffer(hNewBuffer);
cout << "test2";
[/code]
This just writes "test1 test 2" to the console.
[QUOTE=WhatTheEf;40639314]How would I go about writing to a new console screen buffer like when I'm using std::cout to write directly to the screen? Tried searching but couldn't find anything.
Right now I use WriteConsoleOutput and an array that represents each character+property in the buffer. What I want to be able to use something like cout << "string" but instead of writing that to the standard output stream, I want to write it in a new buffer and then swap the two buffers(double buffering).
[code]
COORD bufferSize = {80,25}, bufferOrigin = {0,0}; HANDLE hStdout, hNewBuffer;
CHAR_INFO bufferOutput[2001]; SMALL_RECT srctWriteRect = {0,0,80,25};
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
hNewBuffer = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL
);
SetConsoleScreenBufferSize(hStdout,bufferSize);
SetConsoleActiveScreenBuffer(hStdout);
cout << "test1\n";
SetConsoleActiveScreenBuffer(hNewBuffer);
cout << "test2";
[/code]
This just writes "test1 test 2" to the console.[/QUOTE]
You'd have to wrap it yourself, there's no such functionality in the WinAPI
[QUOTE=zeromancer;40639124]Man, this is stressing me out, it's for a test thing, and I chose to do this game, It's just the random rectangle blocks I just cannot seem to figure out.
Any help would much much appreciated.[/QUOTE]
Randomized, how precisely?
And what library are you using for random numbers and rectangles?
[QUOTE=Dr Magnusson;40639849]You'd have to wrap it yourself, there's no such functionality in the WinAPI[/QUOTE]
To expand on this:
Implement std::basic_streambuf in a class that wraps the WINAPI functionality to write to a console screen buffer and use rdbuf(std::basic_streambuf*) to redirect std::cout to an instance of that wrapper.
How do I compare each element in an array and print out the largest one?
I have this and it does nothing.
[code]for(int i=0; i<=9; i++){
if (pancakes[i] > pancakes[i++]) {
cout << pancakes[i];
}
}[/code]
Also how do I use the same array across separate functions? I tried declaring it in the Header file and that didn't work.
[QUOTE=wlitsots;40645954]How do I compare each element in an array and print out the largest one?
I have this and it does nothing.
[code]for(int i=0; i<=9; i++){
if (pancakes[i] > pancakes[i++]) {
cout << pancakes[i];
}
}[/code]
Also how do I use the same array across separate functions? I tried declaring it in the Header file and that didn't work.[/QUOTE]
That loop isn't going to work properly, it just prints the second element if the first one is larger than itself (that is, never), then repeats two positions farther. You need a variable to store the largest value you found so far.
If you want to pass an array to a function use a reference parameter and a parameter with the array size, or if that's not possible a pointer instead of the reference.
[QUOTE=ZeekyHBomb;40640698]Randomized, how precisely?
And what library are you using for random numbers and rectangles?
To expand on this:
Implement std::basic_streambuf in a class that wraps the WINAPI functionality to write to a console screen buffer and use rdbuf(std::basic_streambuf*) to redirect std::cout to an instance of that wrapper.[/QUOTE]
[url]http://www.coptergame.net/[/url]
Like the walls in this game, this is what I'm trying to create.
and I'm using c#...if that helps at all.
[QUOTE=zero_slo;40629634]Nope, resizing doesn't work, all it does is this:
[T]http://shrani.si/f/P/xp/1a9itrNq/brez-naslova.png[/T]
The FPS in the SFML window title do update every second (as they should), but nothing is being displayed in the actual window...
Edit:
Events in the SFML window also work (Console.WriteLine(...) in handlers...)[/QUOTE]
I think this is relevant for you:
[quote]Events must be polled in the window's thread
This is an important limitation of most OSes: the event loop (more precisely, the pollEvent or waitEvent function) must be called in the same thread that created the window. This means that if you want to create a dedicated thread for event handling, you'll have to make sure that the window is created in this thread too. If you really want to split things between threads, it is more convient to keep event handling in the main thread and move the rest (rendering, physics, logic, ...) to a separate thread instead.[/quote]
[QUOTE=Robbis_1;40649662]I think this is relevant for you:[/QUOTE]
Yeah, that solved it. I put Application.DoEvents() in the gameloop and now it works.
Thanks!
[QUOTE=zeromancer;40646383][url]http://www.coptergame.net/[/url]
Like the walls in this game, this is what I'm trying to create.
and I'm using c#...if that helps at all.[/QUOTE]
You keep a list of upper-rectangles, lower-rectangles and obstacles (those occasionally floating in the middle).
The number of rectangles to keep in the upper- and lower-rechtangles list is frame-width / rect-width + 1. + 1 because you need to show another rectangle when all are shifted by less than rect-width.
Whenever one rectangle leaves the frame, you just put it at the other end of the list and modify the height.
Supposing you maintain the list in the order, that the lowest index corresponds to the left-most rect and the highest corresponds to the right-most rect and the copter flies from left to right (so the rects also scroll left to right):
[code]//Pseudocode of course
If LowerRects[0].GetRight() < 0:
Assert(LowerRects[0].GetRight() == UpperRects[0].GetRight())
newRect = LowerRects.Remove(0)
lastRect = LowerRects.Last
newRect.X = lastRect.GetRight()
heightDelta = Random.Next(-maxDelta / 2, maxDelta / 2)
newRect.Height = lastRect.Height() + heightDelta
//TODO: make sure Height doesn't go below 0
LowerRects.Add(newRect)
//TODO: do the same with UpperRects[0], but add to Y instead of Height (unless negative Height is OK, dunno)
Assert(UpperRect[0].GetRight() >= 0)[/code]
Does anyone have experience with Data Mining? My final year project is to data mine some fire brigade road speed data to help guide route and appliance choices to improve response times. I want to get a head start before I set to it fully in September.
[QUOTE=HTF;40650481]Does anyone have experience with Data Mining? My final year project is to data mine some fire brigade road speed data to help guide route and appliance choices to improve response times. I want to get a head start before I set to it fully in September.[/QUOTE]
Not exactly, but you'll want to implement grouping for hard separations (roads) and fuzzing and weights along reference axes (time of day...) to reduce your data set to a solved or known graph traversal problem.
Can anyone help me with c pointers, I have a program that needs to add two registers but for some reason nothing is happening.
[code]
int opcode_add(char *opcode, char *arg1, char *arg2){
*arg1 += *arg2;
return(0);
}
//I've also tried
int opcode_add(char *opcode, char *arg1, char *arg2){
(*arg1) += (*arg2);
return(0);
}
[/code]
Any help would be much appreciated, cheers :)
What do you mean nothing is happening? I copypasted the former into my compiler and it's adding arg2 to arg1 just fine.
[cpp]char left = 5;
char right = 100;
opcode_add(NULL, &left, &right); // left is now 5+100[/cpp]
Decided to create a 2d plane game too, but I'm not sure how I should implement energy and velocity. I'm calculating the energy the plane has (Epotential + Ekinetic), but what should I do with it? I could convert the energy to velocity, but what direction should the velocity have?
I haven't programmed a plane simulation but I'd just simulate the forces. Gravity affects downwards, engine provides thrust directly forwards, movement relative to the air causes lift towards the wing normal, and drag against the air flow.
[QUOTE=Donkie;40654614]Decided to create a 2d plane game too, but I'm not sure how I should implement energy and velocity. I'm calculating the energy the plane has (Epotential + Ekinetic), but what should I do with it? I could convert the energy to velocity, but what direction should the velocity have?[/QUOTE]
Ideally it should point forwards :v:
If you go with storing the energy then the simulation isn't going to be realistic as you can't model inertia. It's enough for arcade gameplay with hard stalls though.
Using forces and inertia is easier.
I'm making a server for a small project in Lua, and it has an infinite while loop, but it's using like 99% CPU all the time. Any way I can lower that?
[QUOTE=Darkwater124;40655351]I'm making a server for a small project in Lua, and it has an infinite while loop, but it's using like 99% CPU all the time. Any way I can lower that?[/QUOTE]
Add a few milliseconds of sleep each tick to lower CPU time a bit.
[QUOTE=Chris220;40655829]Add a few milliseconds of sleep each tick to lower CPU time a bit.[/QUOTE]
I've tried sleeping for like 0.02 secs and it's still >90%
[QUOTE=Darkwater124;40655918]I've tried sleeping for like 0.02 secs and it's still >90%[/QUOTE]
That sounds very unlikely. Are you certain you're sleeping at all? 0.02 secs of sleep after each loop means a maximum of 50 loops per second.
[QUOTE=esalaka;40656104]That sounds very unlikely. Are you certain you're sleeping at all? 0.02 secs of sleep after each loop means a maximum of 50 loops per second.[/QUOTE]
[code]local clock = os.clock
function sleep(n) -- seconds
local t0 = clock()
while clock() - t0 <= n do end
end
...
while true do
...
sleep(0.02)
end
[/code]
I guess
I don't think lua has a sleep function... Instead, maybe try doing your logic stuff only every X milliseconds?
[editline]15th May 2013[/editline]
Telling a thread to sleep is generally considering a bad idea anyways
[QUOTE=Darkwater124;40655351]I'm making a server for a small project in Lua, and it has an infinite while loop, but it's using like 99% CPU all the time. Any way I can lower that?[/QUOTE]
Are you not receiving data in that loop?
If really not, you can perhaps bind to whatever the Windows-equivalent to pthread_yield is and call that.
If you are, you can use select() to wait for data on the socket.
By the way, does anyone know anything about [url=http://terralang.org/]Terra[/url]? Is it usable? Could I remake the server in this?
[t]http://u.cubeupload.com/Chryseus/1TBs7I.png[/t]
Any suggestions on managing code and class layout, I keep ending up losing track of where I am.
If you use LuaSocket there's a sleep function on the socket. I don't know whether it's a busy wait though.
Otherwise you need to expose a function from your runtime to sleep.
[editline]15th May 2013[/editline]
[QUOTE=Chryseus;40656769][t]http://u.cubeupload.com/Chryseus/1TBs7I.png[/t]
Any suggestions on managing code and class layout, I keep ending up losing track of where I am.[/QUOTE]
You don't have to hold onto a shader from the shader program once it's compiled, and you shouldn't need the shader's source after it's loaded.
Otherwise it looks fine, apart from the missing buffers maybe? Are you using deprecated OpenGL?
[editline]15th May 2013[/editline]
Is there any particular reason why you're storing shader_compiled and so on? These should just be calls to OpenGL...
It would make more sense if this was multi-threaded and loading in the background, but as it is now I don't see the benefit to making the classes that heavy.
Sorry, you need to Log In to post a reply to this thread.