• What do you need help with? Version 1
    5,001 replies, posted
[url]http://www.mp3-tech.org/patents.html[/url] There's no license stuff about distribution, just encoding and decoding.
-Snip, irrelevant now and wrong thread-
[QUOTE=arienh4;26157214]Don't think it is, really. Use it when its meaning is obvious and you should be okay. The proper term is the ternary operator, by the way.[/QUOTE] No, that's not the proper term, that's the wrong one! EDIT: To clarify, in C# it is called the conditional operator (and they mention dubiously in the spec that it is also called "at times" the ternary operator, but that breaks whenever you have more than one ternary operator. In C++, it is also called "Conditional operator". So it's not 100% incorrect, but definitely not precise or 'proper'.
[QUOTE=gparent;26181500]So it's not 100% incorrect, but definitely not precise or 'proper'.[/QUOTE] Except in C and C++ and the likes where it is [B]the[/B] ternary operator.
[QUOTE=Tobba;26174737]Now this is surely odd, all the handshake data seems to be sent in a second packet, first an empty packet with 0x02 is sent(handshake) then a packet containing all the data is sent[/QUOTE] Some quick googling seems to imply that Minecraft uses TCP. TCP is a stream-based protocol. There are no "packets" in TCP. The Minecraft protocol might have a "packet" unit, but it's not likely that 1-byte packets are used (because it's practically impossible unless ALL packets are 1-byte, or the protocol is heavily synchronous). Again, you need to post some code if you want help. I'm fairly sure you're simply confused about how stream-based sockets must be used.
[QUOTE=esalaka;26182052]Except in C and C++ and the likes where it is [B]the[/B] ternary operator.[/QUOTE] Sure, if you don't want to use the proper term, but the standard makes no mention of that name anywhere. This is just semantics, I wouldn't have posted if arienh4 didn't claim it was 'proper', but it really doesn't matter that much.
[QUOTE=jA_cOp;26182233]Some quick googling seems to imply that Minecraft uses TCP. TCP is a stream-based protocol. There are no "packets" in TCP. The Minecraft protocol might have a "packet" unit, but it's not likely that 1-byte packets are used (because it's practically impossible unless ALL packets are 1-byte, or the protocol is heavily synchronous). Again, you need to post some code if you want help. I'm fairly sure you're simply confused about how stream-based sockets must be used.[/QUOTE] I tried this myself, and it seems like the client first sends only "0x02". Haven't tried further but I think I should just do another recv :P
[QUOTE=esalaka;26183159]I tried this myself, and it seems like the client first sends only "0x02". Haven't tried further but I think I should just do another recv :P[/QUOTE] I'm not sure what it is you're doing, but recv() doesn't guarantee that you receive everything. The return value is the number of bytes received, and if you were expecting more data you need to continuously call recv() until you get the number of bytes you were expecting.
I am writing a java applet for learning experiences. I am extending Applet, but it seems that setSize only sets the window's size, not the actual applet's size. The applet's size seems to be maxed out at the default, which, as far as i can tell is 300*350 or 250*300. Anyone else have this problem? Ill upload an animated gif in a minute, if I can figure out how to get VLC to record one on ubuntu.
[QUOTE=PvtCupcakes;26183245]I'm not sure what it is you're doing, but recv() doesn't guarantee that you receive everything. The return value is the number of bytes received, and if you were expecting more data you need to continuously call recv() until you get the number of bytes you were expecting.[/QUOTE] I know, but my code was just checking if anything is received at all. Eh, actually, just for the lulz, here, have my code: [cpp] #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netdb.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> int main() { struct addrinfo hints, * res; memset( &hints, 0, sizeof( hints ) ); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; getaddrinfo( NULL, "20200", &hints, &res ); int listener = socket( res->ai_family, res->ai_socktype, res->ai_protocol ); bind( listener, res->ai_addr, res->ai_addrlen ); listen( listener, 5 ); struct sockaddr_storage client_addr; int comm = 0; socklen_t claddr_size = 0; while ( comm = accept( listener, ( struct sockaddr * ) &client_addr, &claddr_size ) ) { printf( "Grabbin' clients\n" ); char buf[512]; memset( buf, 0, sizeof( buf ) ); char whatever[18]; printf( "Client connected from %s\n", inet_ntop( AF_INET, &( ( (struct sockaddr_in * ) &client_addr )->sin_addr ), whatever, sizeof( whatever ) ) ); size_t len = 0; if ( recv( comm, buf, 512, 0 ) < 1 ) { printf( "Client disconnected or error occurred! (%i)\n", errno ); close( comm ); continue; } printf( "%s", buf ); if ( buf[0] == 2 ) { size_t len = ntohs( *( buf + 1 ) ); char * name = memset( malloc( len + 1), 0, len + 1 ); memcpy( name, ( buf + 3 ), len ); printf( "Handshake received from %s (Name len %lu)\n", name, len ); printf( "Kicking...\n" ); char * kickmsg = "Thanks for testing."; uint8_t code = 0x02; uint16_t templen = htons( strlen( kickmsg ) ); send( comm, &code, 1, 0 ); send( comm, &templen, 2, 0 ); send( comm, kickmsg, sizeof( kickmsg ), 0 ); } printf( "Client dropped through\n" ); close( comm ); } close( listener ); freeaddrinfo( res ); return 0; } [/cpp] Also I just realized that I'm never sending a kick packet to the client, even though I'm supposed to :v: (Although it's not like it matters 'cause I should send a handshake answer first)
[QUOTE=esalaka;26184279]I know, but my code was just checking if anything is received at all. Eh, actually, just for the lulz, here, have my code: -code snip- Also I just realized that I'm never sending a kick packet to the client, even though I'm supposed to :v: (Although it's not like it matters 'cause I should send a handshake answer first)[/QUOTE] Your program only works because it only ever uses one byte from the stream. recv could've filled that buffer with anything from 1 to 512 bytes. Since you're not holding onto the return value of recv, you won't be able to use this extra data, all you know is that you have [I]at least[/I] one byte. Everything else is effectively lost. If you had changed the buffer length parameter to 1, your program wouldn't have this potential problem of discarding future data. In practice, that first call to recv might always return 1. This could happen if the client writes only one byte to the stream then [I]waits[/I] for a reply before sending more. This is not a healthy assumption to make about clients. The problem here is that his program tries to do more than just the handshake. We have to see the code to be able to help.
[QUOTE=jA_cOp;26184897]Your program only works because it only ever uses one byte from the stream. &#8211;&#8211; This is not a healthy assumption to make about clients. [/QUOTE] I said myself that the recv only checks if anything was received at all. This was meant to prove that the client waits for... Something before sending more data. Nagle's algorithm? (But shouldn't it just send everything in one batch if it was so?)
[QUOTE=esalaka;26185121]I said myself that the recv only checks if anything was received at all. This was meant to prove that the client waits for... Something before sending more data.[/QUOTE] You can't make assumptions like that about the client. What if you get a customised client? A future version of the client without that terrible abuse of TCP frames? A malicious client taking advantage of your assumption? (by the way, it is waiting for the handshake reply) [QUOTE=esalaka;26185121]Nagle's algorithm? (But shouldn't it just send everything in one batch if it was so?)[/QUOTE] Nagle's algorithm is not really relevant on this issue because it's the first frame sent.
[QUOTE=jA_cOp;26185577]You can't make assumptions like that about the client. What if you get a customised client? A future version of the client without that terrible abuse of TCP frames? A malicious client taking advantage of your assumption? (by the way, it is waiting for the handshake reply)[/QUOTE] That code [B]is not supposed to work[/B]. It only assumes that the client sends the auth packet so that it can check their name. I used it to test if I understood the protocol correctly. I wasn't making any assumptions at all and would've simply used telnet to test it if it wasn't for the fact that it's sorta hard to type the NUL character on a keyboard. (Why don't I get the username that's supposed to be in the auth package, then?)
[QUOTE=esalaka;26186481]That code [B]is not supposed to work[/B]. It only assumes that the client sends the auth packet so that it can check their name. I used it to test if I understood the protocol correctly. I wasn't making any assumptions at all and would've simply used telnet to test it if it wasn't for the fact that it's sorta hard to type the NUL character on a keyboard. (Why don't I get the username that's supposed to be in the auth package, then?)[/QUOTE] ... then why did you post it? :sigh:
Would anyone be able to explain to me how inheritance works with C++?
[QUOTE=Jimmylaw;26190243]Would anyone be able to explain to me how inheritance works with C++?[/QUOTE] There are countless tutorials out there explaining this. How are we supposed to write a more effective explanation than those when we know nothing about you or what you're struggling with?
[QUOTE=Jimmylaw;26190243]Would anyone be able to explain to me how inheritance works with C++?[/QUOTE] The basics is you have a class character, which has stats like level, health, attack power... Then you have classes like electric_Man which inherits from character, so it has its own variables like electric power, electric charge... but also has the stuff that character has like level, life... Thats the bare basics of it but you should look up a tutorial to get more into it
[QUOTE=Richy19;26190651]The basics is you have a class character, which has stats like level, health, attack power... Then you have classes like electric_Man which inherits from character, so it has its own variables like electric power, electric charge... but also has the stuff that character has like level, life... Thats the bare basics of it but you should look up a tutorial to get more into it[/QUOTE] You can easily do that with just composition. The real difference with inheritance is that you have virtual functions.
[QUOTE=jA_cOp;26190873]You can easily do that with just composition. The real difference with inheritance is that you have virtual functions.[/QUOTE] Or, in other words, the derived class inherits the [i]interface[/i] of the base class, and can change how the interface is implemented and add new functions to the interface. (Virtual functions are the implementation of the concept of being able to change the implementation of an interface function.)
[QUOTE=Richy19;26190651]The basics is you have a class character, which has stats like level, health, attack power... Then you have classes like electric_Man which inherits from character, so it has its own variables like electric power, electric charge... but also has the stuff that character has like level, life... Thats the bare basics of it but you should look up a tutorial to get more into it[/QUOTE] I understand the basic concept of it but im struggling to code it and yes I have looked online but all the tutorials I have found put all the classes in one code file without an independent header and class file for each one.
Oh sorry i believe the syntax is: class myClass : public inheritanceClass and then you declare the destructor as virtual so: virtual ~myClass;
[QUOTE=Richy19;26205391]Oh sorry i believe the syntax is: class myClass : public inheritanceClass and then you declare the destructor as virtual so: virtual ~myClass;[/QUOTE] Are you sure that's it? the tutorials i looked at seemed to include alot more stuff
Because you can't sum it up in two sentences.
[QUOTE=Overv;26207983]Because you can't sum it up in two sentences.[/QUOTE] I will let you use more then 2 then :)
What specifically do you have problems with?
[QUOTE=ZeekyHBomb;26208230]What specifically do you have problems with?[/QUOTE] I haven't a clue how to implement it. I'm working with directx and I have a class setup for handling loading in models but I will be using alot of differnet models in the game and I don't want to have the main model handing class filled up with set/get methods. So instead I want my model classes to inherit everything from the generic model handling class.
Then I'd either have a function to evaluate what kind of model a file contains, which is used in a switch like [cpp]Model model; switch(getModelFileType(modelfile)) { case MFT_OBJ: model = ObjModelLoader::loadModel(modelfile); break; case MFT_MD3: model = MD3ModelLoader::loadModel(modelfile); break; case MFT_INVALID: throw SomeError("Invalid model-type in file " + modelfile.getPath()); default: throw std::runtime_error("We should never get here..! (" __FILE__ ", line " TO_STRING(__LINE__) ")"); } return model;[/cpp] (that MFT_stuff would be of an enum) Or: [cpp]struct ModelLoader { public: typedef bool (*ModelLoader)(File, Model::Pointer&); //Model::Pointer could be a smart-pointer or something struct Adder //if your compiler is good, sizeof(Adder) will be 0 { public: Adder(const ModelLoader &loader){ ModelLoader::addModelLoader(loader); } }; private: typedef std::vector<ModelLoader> ModelLoaderVector; public: static void addModelLoader(const ModelLoader &loader){ getModelLoaderVector().push_back(loader); } static Model::Pointer loadModel(File &file); private: static ModelLoaderVector& getModelLoaderVector(){ static ModelLoaderVector vector; return vector; } }; Model::Pointer ModelLoader::loadModel(File &file) { Model::Pointer model; //NRVO for(ModelLoaderVector::const_iterator iter = getModelLoaderVector().begin(), endIter = getModelLoaderVector().end(); true; ++iter) { if(iter == endIter) { model = Model::getErrorModel(); //TODO: warn about not being able to load the model break; } if((*iter)(file, model)) break; } return model; }[/cpp] Example of usage: [cpp]class MD3Model : public Model { //... struct Header { public: //... bool parse(File &file); //... } //... MD3Model(File &file, Header &header); //could be protected or private //... static bool load(File file, Model::Pointer &model); //... }; //... bool MD3Model::load(File file, Model::Pointer &model) { Header header; if(!header.parse(file)) return false; model = new MD3Model(header, file); return true; } ModelLoader::Adder MD3ModelLoaderAdder(&MD3Model::load);[/cpp] Took me quite some time to write that up and I should go sleeping now, so there might be some errors.
Here is the code I have for the model handling class. [code] #include "Object.h" Object::Object(LPDIRECT3DDEVICE9 device, const std::string &modelname, D3DXVECTOR3 newposition) { d3ddev = device; LPD3DXBUFFER bufMaterial; position = newposition; D3DXLoadMeshFromX(modelname.c_str(), // file to load D3DXMESH_SYSTEMMEM, // load mesh into system memory d3ddev, // D3D device NULL, // adjacency setting &bufMaterial, // put materials here NULL, // effects &numMaterials, // number of materials in the model &mesh); // the mesh // pointer to buffer containing material info D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterial->GetBufferPointer(); // create a material buffer for each material in the mesh Material = new D3DMATERIAL9[numMaterials]; Texture = new LPDIRECT3DTEXTURE9[numMaterials]; for(DWORD i = 0; i < numMaterials; i++) { Material[i] = tempMaterials[i].MatD3D; // material info Material[i].Ambient = Material[i].Diffuse; // set the ambient if(FAILED(D3DXCreateTextureFromFileA(d3ddev, tempMaterials[i].pTextureFilename, &Texture[i]))) Texture[i] = NULL; } } void Object::Update(void) { // static float index = 0.0f; index+=0.03f; // an ever-increasing float value D3DXMatrixTranslation(&meshTranslate, 0, 0, 0); D3DXMatrixRotationY(&meshRotateY, 0); D3DXMatrixScaling(&meshScale, scale, scale, scale); D3DXMatrixTranslation(&meshPosition,position.x,position.y,position.z); meshMatrix = meshPosition * meshRotateY; } void Object::Render() { // Meshes0 are divided into subsets, one for each material. Render them in // a loop for( DWORD i = 0; i < numMaterials; i++ ) { // Set the material and texture for this subset d3ddev->SetMaterial( &Material[i] ); d3ddev->SetTexture( 0, Texture[i] ); // Draw the mesh subset mesh->DrawSubset( i ); } } LPD3DXMESH Object::GetMesh(void) { return mesh; } D3DMATERIAL9 *Object::GetMaterial(void) { return Material; } LPDIRECT3DTEXTURE9 *Object::GetTexture(void) { return Texture; } DWORD Object::GetMaterialCount(void) { return numMaterials; } D3DXMATRIX Object::GetTranslation(void) { return meshTranslate; } D3DXMATRIX Object::GetYRotation(void) { return meshRotateY; } D3DXMATRIX Object::GetScale(void) { return meshScale; } D3DXMATRIX Object::GetMatrix(void) { return meshMatrix; } void Object::setPosition(D3DXVECTOR3 newPosition) { position = newPosition; } Object::~Object(void) { } [/code] Now for example, if I created a class called vehicle. Would I be able to call methods to the class its inheriting by just doing; Vehicle tank; tank.Render(); Would that be possible? Or am I completely wrong.
Hi guys, I'm pretty new to the whole programming deal but I need help with something in C#. What I have now is a very basic maze game, and when you touch one of the borders, the game will reset you to the beginning and will play a sound. Now what I need help with is playing other sounds when I touch the walls, I've looked on google but it was useless. Is there anyway to trigger other sounds to play while I touch the walls? Code: [code]using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Maze { public partial class Form1 : Form { // This SoundPlayer plays a sound whenever the player hits a wall. System.Media.SoundPlayer startSoundPlayer = new System.Media.SoundPlayer(@"C:\Users\Owner\Desktop\Oops.wav"); // This SoundPlayer plays a sound when the player finishes the game. System.Media.SoundPlayer finishSoundPlayer = new System.Media.SoundPlayer(@"C:\Windows\Media\tada.wav"); public Form1() { InitializeComponent(); MoveToStart(); } private void label1_Click(object sender, EventArgs e) { } private void finishLabel_MouseEnter(object sender, EventArgs e) { } private void finishLabel_MouseMove(object sender, MouseEventArgs e) { { // Show a congratulatory MessageBox, then close the form. finishSoundPlayer.Play(); MessageBox.Show("Congratulations!"); Close(); } } /// <summary> /// Play a sound, then move the mouse pointer to a point 10 pixels down and to /// the right of the starting point in the upper-left corner of the maze. /// </summary> private void MoveToStart() { Point startingPoint = panel1.Location; startingPoint.Offset(10, 10); Cursor.Position = PointToScreen(startingPoint); } private void wall_MouseEnter(object sender, EventArgs e) { // When the mouse pointer hits a wall or enters the panel, // call the MoveToStart() method. MoveToStart(); startSoundPlayer.Play(); } private void panel1_MouseEnter(object sender, EventArgs e) { MoveToStart(); } } } [/code]
Sorry, you need to Log In to post a reply to this thread.