• What do you need help with? Version 5
    5,752 replies, posted
How would you go about obtaining a mask of the greatest bit position in an integer? Without using any loops or conditional statements. Can somebody lead me on the right track with this.
Does anyone have some good resources with solid example code for writing network code for games? I'm fine with socket code, just the actual syncing and interpolation to make movement/animation between two clients look smooth and proper is really not going well for me. I looked through a few books but most were hundreds of pages long and the stuff I'm interested in is drowned in 400+ pages of setting up directx. I've had no problem setting it up in things like Unity that handle all the fancy interpolation and timing for you, but I find using things like Unity cause me a lot of grief when I want to start doing more complicated things. Any resources you guys know of that could help? To be more specific I mean real time authoritative server/client setups such as is often used for source engine games. The source engine papers are interesting and helpful, but not easy to reproduce for someone's beginner attempts at networked gaming.
Is a sequence detecting FSM with reset one that does look for input overlaps or doesn't? I get reset/non-reset confused.
[QUOTE=Stonecycle;39716922]Is there something similar to endl for input to check the next line of a file? Like instead of [i]while (database >> n >> f >> l >> p >> b >> t)[/i], it would just be [i]while (database >> n >> (what I'm asking for like endl))[/i].[/QUOTE] std::endl is a '\n' character, so just do a equality test against '\n'
Anybody able to tell me how to install Pure Data on windows? Need to for an assignment and have no idea how to do it. The book I have says that it should download an installer but I just get a load of folders so I don't know how to get it working.
C++ homework, our teacher is a bastard who sits at his pc talks to him self, so stuff we haven't even heard of. Have to find the longest simmetrical word in a sentence. But it prints out the only the first word, doesnt check the whole sentence. Any ideas or tips ? [CODE]#include "StdAfx.h" #include <iostream> #include<string> using namespace std; char s[25000]; int i=0, j, first, last, length,subleng, maxi=0; void main () { cout<<"Enter a string to process \n"; cin >> s; length = static_cast<int>(strlen(s)); for(i=0 ; i<length ; i++) { int j,k,n; for (n=0; n<2; n++) { j = i-n; k = i+1; subleng = n; while ( j>=0 && k<length && s[j]==s[k]) { subleng +=2; j--; k++; } if( subleng > maxi) { first= j + 1; maxi= subleng; } } } cout<<"The longest symmetric word is : \n"; for (i=0 ; i<maxi ; i++) { cout<<s[first+i]; } cout<<endl<<endl; system("pause"); }[/CODE]
[QUOTE=Richy19;39715529]I implemented the Fix your timestep thing with the following: [csharp] // Take note of the delta time double deltaTime = (Environment.TickCount - startTime) / 1000.0; startTime = Environment.TickCount; if (deltaTime > 0.25) deltaTime = 0.25; // Only update if in focus, if not dont waste resources if (focused) { Globals.Accumulator += deltaTime; while (Globals.Accumulator>=Globals.Delta) { Update (); Globals.Accumulator -= Globals.Delta; } } // Clear the window window.Clear (); // Draw all elements to the screen Draw (); // Finally, display the rendered frame on screen window.Display ();[/csharp] then in my object class: [csharp] public class PhysicsObject : GameObject { protected Util.Vector2F velocity, direction, force; protected float mass = 1.0f; public PhysicsObject () { velocity = new Util.Vector2F(); direction = new Util.Vector2F(); force = new Util.Vector2F(); } public void ApplyForce(Util.Vector2F force){ this.force += force; } public override void Update() { force /= mass; velocity += force * Globals.Delta; position += velocity * Globals.Delta; oldPosition = position; } public override void Draw(){ drawPosition = Util.Vector2F.Interpolate(oldPosition, position, (float)(Globals.Accumulator/Globals.Delta)); } [/csharp] And use it as: [csharp]SFML.Graphics.CircleShape shape = new SFML.Graphics.CircleShape(20); HGC.Abstracts.PhysicsObject pO = new HGC.Abstracts.PhysicsObject(); public Game () { } public override void Init() { pO.Position = new HGC.Util.Vector2F(-100, 300); } public override void Update() { pO.ApplyForce(new HGC.Util.Vector2F(9.8f, 0)); pO.Update(); } public override void Draw() { pO.Draw(); shape.Position = new SFML.Window.Vector2f(pO.DrawPosition.X, pO.DrawPosition.Y); window.Draw(shape); }[/csharp] but it looks kinda laggy, and not quite right, isthere anything I can do to fix this?[/QUOTE] Well you can take a look at my implementation: [code]bool Application::execute(int argc, char** argv) { m_peer=m_peer=RakNet::RakPeerInterface::GetInstance(); m_peer->AttachPlugin(&m_scene); if(onInit()) { unsigned int t=0; float t_accumulator=0.0f; float t_absolute=0.0f; while(m_running) { float t_new=time(); float t_delta=t_new-t_absolute; if(t_delta<=0.0f) continue; t_absolute=t_new; t_accumulator+=t_delta; while(t_accumulator>=APPLICATION_FIXED_STEP) { onUpdate(); t_accumulator-=APPLICATION_FIXED_STEP; t++; } onRender(t_accumulator/APPLICATION_FIXED_STEP); } m_scene.destroy(); m_peer->Shutdown(100,0); RakNet::RakPeerInterface::DestroyInstance(m_peer); return onCleanup(); } return false; }[/code] You can use the accumulator to interpolate between two ticks, also I think the precision of the timer is very important, I use this... [code]#ifndef TIME_H #define TIME_H #include "windows.h" static float time() { static __int64 S=0; static __int64 F=0; if(S==0) { QueryPerformanceCounter((LARGE_INTEGER*)&S); QueryPerformanceFrequency((LARGE_INTEGER*)&F); return 0.0f; } __int64 counter=0; QueryPerformanceCounter((LARGE_INTEGER*)&counter); return (float) ((counter-S)/double(F)); } #endif[/code]
[QUOTE=MakeR;39703739]It's compiler (and platform) specific, but guaranteed to be at least 32,767.[/QUOTE] If your RAND_MAX is that small, you can't get a uniform distribution between 0 and 1,000,000 with your code either. If RAND_MAX is big enough, modulus is the best way (as I posted). If RAND_MAX is freakishly small, you'd need to do something more clever to get a bigger range.
[QUOTE=Larikang;39726186]If your RAND_MAX is that small, you can't get a uniform distribution between 0 and 1,000,000 with your code either. If RAND_MAX is big enough, modulus is the best way (as I posted). If RAND_MAX is freakishly small, you'd need to do something more clever to get a bigger range.[/QUOTE] You do get an even distribution with my code though, all my code does is normalise the distribution from rand() and then multiply by the range you want. There are also problems with using the modulo operator to fit a random distribution into a range; you will only get an even distribution when RAND_MAX%n == n-1. The best solution is to keep generating numbers until you get one within your range, but obviously in the case above where the range is greater than MAX_RANGE this can not be done.
Hopefully this is the right place to ask, I've just started learning C# (inspired by everyone in this sub-forum, thanks for that!), so far I've created a simple console naughts and crosses game, but I'm stumped on what to have a go at doing next, I was wondering if anyone could give me an idea or two to try?
[QUOTE=MakeR;39726375]You do get an even distribution with my code though, all my code does is normalise the distribution from rand() and then multiply by the range you want. There are also problems with using the modulo operator to fit a random distribution into a range; you will only get an even distribution when RAND_MAX%n == n-1. The best solution is to keep generating numbers until you get one within your range, but obviously in the case above where the range is greater than MAX_RANGE this can not be done.[/QUOTE] Yes, even but not uniform (where each value would be equally likely). Both my code and yours have certain values with 0 probability if RAND_MAX is less than 1,000,000.
I'm trying to get 3/4ths in C by using limited operators (no if statements, loops, multiply)... I am stuck at some corner cases. What is wrong with this? X is some input variable: [CODE] int mb3 = x+x+x; // multiply by three int db4 = mb3>>2; // divide by four return db4; [/CODE]
Shifting right drops the least significant bits i.e. it you will lose any remainder. E.g. 3 >> 2 == 0, 5 >> 2 == 1
[QUOTE=Larikang;39727585]Shifting right drop the least significant bits i.e. it you will lose any remainder. E.g. 3 >> 2 == 0, 5 >> 2 == 1[/QUOTE] So you need to conserve those bits? I'm probably doing this wrong, but is this what you mean: [CODE] int mb3 = x+x+x; int db4 = (mb3>>2) + ((x<<31)>>31); return db4; [/CODE] I'm off by 1 for some numbers. Thanks for the help.
I'm not sure what you mean. If you're using ints, you'll be doing integer division so the result won't be (mathematically) accurate unless x is originally divisible by 4.
[QUOTE=Larikang;39727663]I'm not sure what you mean. If you're using ints, you'll be doing integer division so the result won't be (mathematically) accurate unless x is originally divisible by 4.[/QUOTE] Sorry just not very familiar with this stuff. I'm trying to do exactly what the compiler processes "x*3/4" as in a function. With the original method, I'm off by one for some numbers, such as 0x80000001, where I get 0xe0000000 instead of 0xe0000001. I can't find a way to resolve this issue.
[QUOTE=W00tbeer1;39727728]Sorry just not very familiar with this stuff. I'm trying to do exactly what the compiler processes "x*3/4" as in a function. With the original method, I'm off by one for some numbers, such as 0x80000001, where I get 0xe0000000 instead of 0xe0000001. I can't find a way to resolve this issue.[/QUOTE] Those numbers could be overflowing the size of int.
[QUOTE=Waerlock;39727389]Hopefully this is the right place to ask, I've just started learning C# (inspired by everyone in this sub-forum, thanks for that!), so far I've created a simple console naughts and crosses game, but I'm stumped on what to have a go at doing next, I was wondering if anyone could give me an idea or two to try?[/QUOTE] A calculator?
what's the generally recommended data to send for UDP networking in a game - ID stuff, position, velocity and any important tidbits all at once every server 'update'?
Sorry, you need to Log In to post a reply to this thread.