• What are you working on? V7
    2,001 replies, posted
[QUOTE=DrTaxi;20318962]Doesn't UTF-8 do that as well?[/QUOTE] UTF-8 is variable length encoding. Most characters in the ASCII range preserve their single bytes, but the rest can be two or more bytes.
Finally got SOMETHING to work on my model viewer for my engine. Atleast i got the ground to render without crashing my graphics card and giving me a bluescreen
[QUOTE=xAustechx;20319492]I'm learning the SDL library. And this is what I have so far. [img]http://i49.tinypic.com/28a0nqd.png[/img] If you can guess the two sexy people in this image I'll give you the source.[/QUOTE] James Allen and Garry Newman [editline]09:37AM[/editline] Source please.
-snip-
[QUOTE=MakeR;20319771]James Allen and Garry Newman [editline]09:37AM[/editline] Source please.[/QUOTE] That's not Garry, it's High6. Better luck next time though. :)
[QUOTE=xAustechx;20319492]I'm learning the SDL library. And this is what I have so far. [img_thumb]http://i49.tinypic.com/28a0nqd.png[/img_thumb] If you can guess the two sexy people in this image I'll give you the source.[/QUOTE] Ahahaha
The stuff you guys make in this thread is awesome. Wish I was able to make something half as cool. :frown:
I have a problem. For some reason i lose vertex data without any reason that i could see. take a look at this pic: [IMG]http://img534.imageshack.us/img534/5312/problemr.png[/IMG] That green vertex is supposed to be white and in the middle. And i clearly told that vertex to be white. Any ideas?
[QUOTE=i300;20318099]Sweet! Wanna help a network-noob and post the source?[/QUOTE] I'm as much of a network-noob as you are, I just started yesterday :v: But here: [code] #include <iostream> #include <string> #include <stdexcept> #include <map> #include <boost/shared_ptr.hpp> #include <boost/foreach.hpp> #include <SDL.h> #include <RakPeerInterface.h> #include <RakNetworkFactory.h> #include <RakNetTypes.h> #include <BitStream.h> #include <MessageIdentifiers.h> #include "net_var.hpp" #include "hash.hpp" struct vec2 { float x, y; vec2(float x, float y): x(x), y(y) {} vec2(): x(0.0f), y(0.0f) {} }; class networkable { protected: typedef std::map<hash_t, netVarBase*> netVarMap; netVarMap _netVars; void _addNetVar(const std::string &name, netVarBase *what) { _netVars[hash(name)] = what; } public: bool hasNetVar(const std::string &name) const { netVarMap::const_iterator i = _netVars.find(hash(name)); return i != _netVars.end(); } template<typename T> netVar<T> &getNetVar(const std::string &name) { netVarMap::iterator i = _netVars.find(hash(name)); if (i == _netVars.end()) throw std::runtime_error("networkable does not have net var " + name); netVarBase &base = *i->second; if (base.type() != &typeid(T)) throw std::runtime_error("net var " + name + " type mismatch"); return static_cast<netVar<T>&>(base); } template<typename T> const netVar<T> &getNetVar(const std::string &name) const { // hack: use const_cast to avoid code duplication which might cause // issues in case the two implementations get out of sync return const_cast<networkable&>(*this).getNetVar(name); } networkable() {} virtual ~networkable() {} void validate() { netVarMap::iterator i; for (i = _netVars.begin(); i != _netVars.end(); ++i) i->second->validate(); } bool valid() const { netVarMap::const_iterator i; for (i = _netVars.begin(); i != _netVars.end(); ++i) if (!i->second->valid()) return false; return true; } void write(RakNet::BitStream &bs) const { netVarMap::const_iterator i; for (i = _netVars.begin(); i != _netVars.end(); ++i) { if (i->second->valid()) continue; // don't write valid values // serialize net var ID (the hash) bs.Write(i->first); // write the actual data i->second->write(bs); } bs.Write((hash_t)0); // end of net vars } void read(RakNet::BitStream &bs) { while (true) { hash_t id; bs.Read(id); if (id == 0) // id of 0 is end of net vars break; netVarMap::iterator i = _netVars.find(id); if (i == _netVars.end()) throw std::runtime_error("networkable tried to read invalid net var"); i->second->read(bs); } } }; class entity: public networkable { protected: public: entity() {} virtual ~entity() {} }; typedef boost::shared_ptr<entity> entityPtr; class player: public entity { protected: netVar<vec2> _pos; void _addNetVars() { _addNetVar("pos", &_pos); } public: player() { _addNetVars(); _pos.set(vec2(50.0f, 50.0f)); } ~player() {} void move(const vec2 &m) { vec2 &p = _pos.get(); p.x += m.x; p.y += m.y; _pos.invalidate(); } }; typedef std::map<hash_t, entityPtr> entityMap; typedef unsigned char packetId_t; enum { ID_NETWORKABLE_UPDATES = ID_USER_PACKET_ENUM + 1, ID_CREATE_PLAYER }; struct createPlayerMessage { hash_t id; }; int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_EVERYTHING); SDL_Surface *screen = SDL_SetVideoMode(320, 240, 32, SDL_SWSURFACE); RakPeerInterface *peer = RakNetworkFactory::GetRakPeerInterface(); #if defined(BUILD_CLIENT) SocketDescriptor sd(0, NULL); peer->Startup(1, 0, &sd, 1); peer->SetMaximumIncomingConnections(1); #elif defined(BUILD_SERVER) SocketDescriptor sd(1337, NULL); peer->Startup(8, 0, &sd, 1); peer->SetMaximumIncomingConnections(8); #endif #if defined(BUILD_CLIENT) std::string hostAddress = "192.168.1.2"; std::cout << "connecting to " << hostAddress << "\n"; peer->Connect(hostAddress.c_str(), 1337, NULL, 0); #elif defined(BUILD_SERVER) std::cout << "waiting for connections\n"; #endif SDL_Surface *img = SDL_LoadBMP("img.bmp"); entityMap entities; bool running = true; while (running) { SDL_Event evt; while (SDL_PollEvent(&evt)) { switch (evt.type) { case SDL_QUIT: running = false; break; } } Packet *packet = NULL; while (packet = peer->Receive()) { switch (packet->data[0]) { #if defined(BUILD_CLIENT) case ID_CONNECTION_REQUEST_ACCEPTED: std::cout << "connected successfully to " << packet->systemAddress.ToString() << "\n"; // tell the server we want to create a player { RakNet::BitStream bs; createPlayerMessage msg; msg.id = hash("player1"); bs.Write((packetId_t)ID_CREATE_PLAYER); bs.Write(msg); peer->Send(&bs, IMMEDIATE_PRIORITY, RELIABLE, 0, packet->systemAddress, false); } break; case ID_CONNECTION_ATTEMPT_FAILED: std::cout << "connection failed\n"; running = false; break; case ID_CONNECTION_LOST: std::cout << "connection lost to " << packet->systemAddress.ToString() << "\n"; running = false; break; case ID_CREATE_PLAYER: // server wants to create a player { RakNet::BitStream bs(packet->data, packet->length, false); bs.IgnoreBytes(1); // ignore the ID of the packet createPlayerMessage msg; bs.Read(msg); entityPtr ent(new player()); entities[msg.id] = ent; } break; case ID_NETWORKABLE_UPDATES: // we got entity updates { RakNet::BitStream bs(packet->data, packet->length, false); bs.IgnoreBytes(1); // ignore the ID of the packet while (true) { hash_t id; bs.Read(id); if (id == 0) // id of 0 is end of networkables break; entityMap::iterator i = entities.find(id); if (i == entities.end()) continue; // bad entity? networkable &net = *i->second; net.read(bs); } } break; #elif defined(BUILD_SERVER) case ID_NEW_INCOMING_CONNECTION: std::cout << "incoming connection from " << packet->systemAddress.ToString() << "\n"; break; case ID_CONNECTION_LOST: std::cout << "connection lost to " << packet->systemAddress.ToString() << "\n"; break; case ID_CREATE_PLAYER: // someone wants to create a player, accept the request { RakNet::BitStream bs(packet->data, packet->length, true); // interestingly enough we can reuse the same packet // and broadcast it to everyone peer->Send(&bs, IMMEDIATE_PRIORITY, UNRELIABLE_SEQUENCED, 0, UNASSIGNED_SYSTEM_ADDRESS, true); // then we can create our own player bs.IgnoreBytes(1); createPlayerMessage msg; bs.Read(msg); entityPtr ent(new player()); entities[msg.id] = ent; } break; #endif } } #if defined(BUILD_CLIENT) #elif defined(BUILD_SERVER) { RakNet::BitStream bs; bs.Write((packetId_t)ID_NETWORKABLE_UPDATES); // loop over the entities and see what needs to be updated for (entityMap::iterator i = entities.begin(); i != entities.end(); ++i) { networkable &net = *i->second; if (!net.valid()) { // write the networkable's hash (id) first bs.Write(i->first); // then write the networkable data itself net.write(bs); net.validate(); } } bs.Write((hash_t)0); // end of networkables peer->Send(&bs, IMMEDIATE_PRIORITY, UNRELIABLE_SEQUENCED, 0, UNASSIGNED_SYSTEM_ADDRESS, true); } #endif for (entityMap::iterator i = entities.begin(); i != entities.end(); ++i) { entityPtr &ent = i->second; if (ent->hasNetVar("pos")) { netVar<vec2> p = ent->getNetVar<vec2>("pos"); SDL_Rect dest; dest.x = int(p.get().x + 0.5f); dest.y = int(p.get().y + 0.5f); dest.w = img->w; dest.h = img->h; SDL_BlitSurface(img, NULL, screen, &dest); } } SDL_UpdateRect(screen, 0, 0, 0, 0); } SDL_FreeSurface(img); RakNetworkFactory::DestroyRakPeerInterface(peer); SDL_Quit(); return 0; } [/code] I'll leave the details (hashing and netvars) up to you - it serves as a pretty good exercise to implement, and you might possibly come up with a better variant than what I have.
Put it in code tags so you don't stretch the page so much
In openGL ( GLUT ), i'm trying to go through a multidimensional array [code] #define MAP_SIZEX 10 #define MAP_SIZEY 10 char map[MAP_SIZEX][MAP_SIZEY] = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, };[/code] How could I place a cube at each of the points? I can't seem to figure it out.. GLUT code for cubes: glutSolidCube( 1 ); 1 is the preferred size.
[QUOTE=ZomBuster;20321901]Put it in code tags so you don't stretch the page so much[/QUOTE] Woops, sorry, fixed.
[QUOTE=Blynx6;20322266]In openGL ( GLUT ), i'm trying to go through a multidimensional array [code] #define MAP_SIZEX 10 #define MAP_SIZEY 10 char map[MAP_SIZEX][MAP_SIZEY] = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, };[/code] How could I place a cube at each of the points? I can't seem to figure it out.. GLUT code for cubes: glutSolidCube( 1 ); 1 is the preferred size.[/QUOTE] Seems for the fixed-function pipeline, as such you'd simply push, translate and pop the current matrix: [cpp]for(int x = 0; x < MAP_SIZEX; ++x) for(int y = 0; y < MAP_SIZEY; ++y) if(map[x][y] != 0){ glPushMatrix(); glTranslatef(x*offset, y*offset, 0); glutSolidCube(map[x][y]); glPopMatrix(); }[/cpp] At least that's how I think it would work.
Working on a program to turn obj files into my model files. Does anyone have any idea whats the best way of turning this: [code]v -10.0000 10.0000 -10.0000[/code]into something like this: [code]ÿÿ€[/code] (binary) In C++
just realised you can add form controls to XNA forms, could be handy when I can't be bothered going through my own UI stuff or when debugging it: [IMG]http://i163.photobucket.com/albums/t315/novemberdobby/handy.png[/IMG]
[QUOTE=Tobba;20322728]Working on a program to turn obj files into my model files. Does anyone have any idea whats the best way of turning this: [code]v -10.0000 10.0000 -10.0000[/code]into something like this: [code]ÿÿ€[/code] (binary) In C++[/QUOTE] #1, you can't. That's 3 bytes, meaning you'd have to encode 3 floating point values into 2 bytes, which is impossible. #2, assuming that was just an example, you'd read the data and write it back out in some specific structure in binary mode #3, why? The .obj is very simple, why do you need to convert it to your own binary format, which you then have to also parse and therefore make a complete circle?
In C++ does an enum belong in a .cpp, or a .h file?
[QUOTE=TheBoff;20323021]In C++ does an enum belong in a .cpp, or a .h file?[/QUOTE] Wherever you need it.
[QUOTE=nullsquared;20322911]#1, you can't. That's 3 bytes, meaning you'd have to encode 3 floating point values into 2 bytes, which is impossible. #2, assuming that was just an example, you'd read the data and write it back out in some specific structure in binary mode #3, why? The .obj is very simple, why do you need to convert it to your own binary format, which you then have to also parse and therefore make a complete circle?[/QUOTE] #1 yeah that was kinda just a example. thats what im currenty using. But i gonna add more so it will work with floats and bigger numbers. #3 I will use much special stuff in the model files. And im trying to get the files small
[QUOTE=nullsquared;20323491]Wherever you need it.[/QUOTE] So, if I'm using it all over the place, a .h?
[QUOTE=TheBoff;20323817]So, if I'm using it all over the place, a .h?[/QUOTE] Yup. Just make sure you have proper include guards on the header.
[QUOTE=Tobba;20323602]#1 yeah that was kinda just a example. thats what im currenty using. But i gonna add more so it will work with floats and bigger numbers. #3 I will use much special stuff in the model files. And im trying to get the files small[/QUOTE] Google Protocol Buffers?
[QUOTE=TheBoff;20323848]Google Protocol Buffers?[/QUOTE] Yeah I was about to say that, it really takes the complexity out of the equation.
[QUOTE=nullsquared;20323842]Yup. Just make sure you have proper include guards on the header.[/QUOTE] Tah very much. I'm being lazy, so #pragma once is everywhere.
[QUOTE=TheBoff;20323859]Tah very much. I'm being lazy, so #pragma once is everywhere.[/QUOTE] Um sure that works too, I just like to avoid compiler-specific code.
A little noob question: I have some bytes in the beginning of my file. But i have to loop througth loads of stuff in the obj file first and write to it. Is it possible to write to a specified position with ofstream?
Yeah, seekp(): [url]http://www.cplusplus.com/reference/iostream/ostream/seekp/[/url] The problem is that if your file isn't big enough yet, you need to fill it with some data with write().
-snip- didnt read the whole article [editline]06:14PM[/editline] Now i wanna see if my comp can handle the like 900000 vertex scorpion model i found on the internet.... lol
[QUOTE=nullsquared;20323856]Yeah I was about to say that, it really takes the complexity out of the equation.[/QUOTE] so x &#8712; [B]R[/B]? I'm sorry; I couldn't resist!
Bah, fucking hangup's i should probbably reduce the writing to the console [editline]07:20PM[/editline] Took out all the unneeded console prints. Works like a charm now. You might understand why i want my own becuse of this: .obj file - 41 mb ( only the points as thats only what mine contains right now ) mine - 2 mb
Sorry, you need to Log In to post a reply to this thread.