Advertisement Jump to content
  • Advertisement

Sepiantum

Member
  • Content Count

    120
  • Joined

  • Last visited

Community Reputation

102 Neutral

About Sepiantum

  • Rank
    Member
  1. That is a problem. You are testing if playerClass is equal to the character 'W', or if the integer value of 'w' is not 0. The integer value of 'w' is never zero and never will be zero, so each if statement will run. Change it to: if(playerClass == 'W' || playerClass == 'w')
  2. tldr, but here's what I did: //find_distance - calculates perpendicular distance from player to wall in his direction + relative angle float QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayCast::find_distance(QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayPlayer* pPlayer, QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayMap* pMap, float ray_angle, float max_dist){ float angle = fmod(pPlayer->GetDirection() + ray_angle, static_cast<float>(2.0f * D3DX_PI)); //Calculate ray absolute angle based off of player direction and ray angle offset if(angle == 0.0f || angle == D3DX_PI){ //Angles of 0 and pi are perfectly horizontal, so we can only check vertical return this->vertical_distance(pPlayer, pMap, ray_angle, max_dist) * cos(ray_angle); } else if(angle == 0.5f * D3DX_PI || angle == 1.5f * D3DX_PI){ //Angles of pi/4 and 7pi/4 are perfectly vertical, so we can only check horizontal return this->horizontal_distance(pPlayer, pMap, ray_angle, max_dist) * cos(ray_angle); } else { //Not in the 4 cardinal directions, so we take the minimum distance float d1 = this->horizontal_distance(pPlayer, pMap, ray_angle, max_dist); float d2 = this->vertical_distance(pPlayer, pMap, ray_angle, max_dist); if(d1 < 0.0f){ return d2 * cos(ray_angle); } else if(d2 < 0.0f){ return d1 * cos(ray_angle); } else { return min(d1, d2) * cos(ray_angle); } } } //horizontal_distance - calculates perpendicular distance from player to wall in his direction + relative angle using horizontal lattice lines float QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayCast::horizontal_distance(QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayPlayer* pPlayer, QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayMap* pMap, float ray_angle, float max_dist){ float angle = fmod(pPlayer->GetDirection() + ray_angle, static_cast<float>(2.0f * D3DX_PI)); //Calculate ray absolute angle based off of player direction and ray angle offset //Block size variable float block = static_cast<float>(BLOCK_SIZE); //Variables for lattice line points float x = 0.0f; float y = 0.0f; const float px = pPlayer->GetX(); const float py = pPlayer->GetY(); float dx = block / tan(angle); float dy = block; float dist = 0.0f; if(angle > 0.0f && angle < D3DX_PI){ //Upwards facing ray dy = -dy; //Negate dy //Calculate first intersection y = static_cast<float>((static_cast<int>(px) / BLOCK_SIZE) * BLOCK_SIZE) - 1.0f; x = px + (py - y) / tan(angle); dist = sqrt((x - px) * (x - px) + (y - py) * (y - py)); if(this->wall_exists(pMap, static_cast<int>(x / block), static_cast<int>(y / block))){ //Return distance if there is a wall here return dist; } //Otherwise continue do { x += dx; //Increment x y += dy; //Increment y dist = sqrt((x - px) * (x - px) + (y - py) * (y - py)); //Calculate distance if(dist > max_dist){ //Exceed maximum ray distance return -1.0f / cos(ray_angle); //-1 for failure } } while(!this->wall_exists(pMap, static_cast<int>(x / block), static_cast<int>(y / block))); //Found wall return dist; } else { //Downwards facing ray //Calculate first intersection y = static_cast<float>((static_cast<int>(py) / BLOCK_SIZE) * BLOCK_SIZE) + block; x = px + (py - y) / tan(angle); dist = sqrt((x - px) * (x - px) + (y - py) * (y - py)); if(this->wall_exists(pMap, static_cast<int>(x / block), static_cast<int>(y / block))){ //Return distance if there is a wall here return dist; } //Otherwise continue do { x += dx; //Increment x y += dy; //Increment y dist = sqrt((x - px) * (x - px) + (y - py) * (y - py)); //Calculate distance if(dist > max_dist){ //Exceed maximum ray distance return -1.0f / cos(ray_angle); //-1 for failure } } while(!this->wall_exists(pMap, static_cast<int>(x / block), static_cast<int>(y / block))); //Found wall return dist; } return -1.0f / cos(ray_angle); //Could not find wall - return -1 to signify failure } //vertical_distance - calculates perpendicular distance from player to wall in his direction + relative angle using vertical lattice lines float QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayCast::vertical_distance(QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayPlayer* pPlayer, QuantumGameEngine::QuantumGraphics::QuantumRaycast::CRayMap* pMap, float ray_angle, float max_dist){ float angle = fmod(pPlayer->GetDirection() + ray_angle, static_cast<float>(2.0f * D3DX_PI)); //Calculate ray absolute angle based off of player direction and ray angle offset //Block size variable float block = static_cast<float>(BLOCK_SIZE); //Variables for lattice line points float x = 0.0f; float y = 0.0f; const float px = pPlayer->GetX(); const float py = pPlayer->GetY(); float dy = block * tan(angle); float dx = block; float dist = 0.0f; if(angle > 0.5f * D3DX_PI && angle < 1.5f * D3DX_PI){ //Left facing ray dx = -dx; //Negate dx //Calculate first intersection x = static_cast<float>((static_cast<int>(px) / BLOCK_SIZE) * BLOCK_SIZE) - 1.0f; y = py + (px - x) * tan(angle); dist = sqrt((x - px) * (x - px) + (y - py) * (y - py)); if(this->wall_exists(pMap, static_cast<int>(x / block), static_cast<int>(y / block))){ //Return distance if there is a wall here return dist; } //Otherwise continue do { x += dx; //Increment x y += dy; //Increment y dist = sqrt((x - px) * (x - px) + (y - py) * (y - py)); //Calculate distance if(dist > max_dist){ //Exceed maximum ray distance return -1.0f / cos(ray_angle); //-1 for failure } } while(!this->wall_exists(pMap, static_cast<int>(x / block), static_cast<int>(y / block))); //Found wall return dist; } else { //Right facing ray //Calculate first intersection x = static_cast<float>((static_cast<int>(px) / BLOCK_SIZE) * BLOCK_SIZE) + block; y = py + (px - x) * tan(angle); dist = sqrt((x - px) * (x - px) + (y - py) * (y - py)); if(this->wall_exists(pMap, static_cast<int>(x / block), static_cast<int>(y / block))){ //Return distance if there is a wall here return dist; } //Otherwise continue do { x += dx; //Increment x y += dy; //Increment y dist = sqrt((x - px) * (x - px) + (y - py) * (y - py)); //Calculate distance if(dist > max_dist){ //Exceed maximum ray distance return -1.0f / cos(ray_angle); //-1 for failure } } while(!this->wall_exists(pMap, static_cast<int>(x / block), static_cast<int>(y / block))); //Found wall return dist; } return -1.0f / cos(ray_angle); //Could not find wall - return -1 to signify failure } Basically what you did. Calculate the first vertical grid intersection and the first horizontal intersection, and take the smaller of the two. I broke it up into 3 cases so I wouldn't get divide by 0 errors: 0 and 180 so I only need to check vertical, 90 and 270 so I only need to check horizontal, and the others where I check both. You can find the complete source here. Download the latest prealpha release and look into quantumgameengine/quantumgraphics/quantumraycast/craycast.cpp
  3. To make new return nullptr on fail, you could just do #define new new (std::nothrow) and use it like void* p = new char[1024];
  4. I've uploaded what I've managed to put together so far. This version of the test still uses the exported unordered_map. I will change that code once somebody confirms my above post. Everything should be explained to you when you run the executable. EDIT: help <command> is how you get help on a certain command. I forgot to include that in help.
  5. According to this page, std::string is automatically exported by the C Runtime. So let me get this straight. CConsole should be declared like: class __declspec(dllexport) CConsole { public: CConsole(); virtual ~CConsole(); virtual std::string Add(CCFunc* pFunc) = 0; virtual std::string Remove(std::string name) = 0; void delete_self(){ delete this; } //Implementation in another file of course }; And then somewhere else, CConsole is implemented but not exported. Then, I define something like this: CConsole* __declspec(dllexport) CreateConsole(){ return new CConsoleImplementation(); } Or should I make everything char* instead? I'm pretty sure Microsoft is saying that using std::string as a return type is fine.
  6. Would declaring CConsole as a pure virtual interface and providing a method CreateConsole() that instantiates a console class derived from CConsole work?
  7. Yeah I realized I was callling delete on CCFunc objects multiple times. Adding a needs_delete = false right before pConsole->Remove() fixes the problem. So how would you suggest registering console variables and console functions with the console object?
  8. Warning used to look like this (I just suppressed it): 1>c:\important stuff\quantum game engine\quantum game engine\cvar\CConsole.h(28): warning C4251: 'CConsole::CFuncList' : class 'std::tr1::unordered_map<_Kty,_Ty>' needs to have dll-interface to be used by clients of class 'CConsole' 1> with 1> [ 1> _Kty=std::string, 1> _Ty=CCFunc * 1> ] Instead, I'm getting massive access violation errors when I run my code. CConsole destructor: //Destructor - clear the map CConsole::~CConsole(){ //Loop through and delete what needs to be deleted for(std::tr1::unordered_map<std::string, CCFunc*>::iterator it = this->CFuncList.begin(); it != this->CFuncList.end(); it++){ if(it->second->needs_delete){ delete it->second; } } } Remove code: std::string CConsole::Remove(std::string _name){ if(this->CFuncList.count(_name)){ this->CFuncList[_name]->pConsole = nullptr; //Use delete if needed if(this->CFuncList[_name]->needs_delete){ delete this->CFuncList[_name]; } this->CFuncList.erase(_name); return _name + " was successfully removed from the function list"; } else { return "Error: " + _name + " does not exist"; } } CCFunc destructor: CCFunc::~CCFunc(){ //If not yet removed if(this->pConsole){ this->pConsole->Remove(this->name); } this->name.clear(); this->desc.clear(); this->pConsole = nullptr; } When I run my app, it breaks with the error: Unhandled exception at 0x000007fef1e4b918 (cvar.dll) in cvar_test.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff inside iosfwd (line 527) from this->desc.clear() inside the CCFunc destructor. Any ideas on what's going on? EDIT: commenting out this->desc.clear() gives the same access violation in iosfwd (line 527) from this->pConsole = nullptr in the CCFunc destructor. I don't think a simple assignment should have this problem lol...
  9. I've been trying to write a cvar system to export in a dll lately, and Microsoft's compiler is getting mad at me for not providing explicit instantiations for std::tr1::unordered_map<std::string, CCFunc*>. I've been trying to provide all sorts of explicit instantiantions, but I just end up with even more warnings.
  10. Sepiantum

    C++ cvar system

    laziness ftw. anyways, i've decided to use a giant union of all supported types in vc++ to store cvar stuff because you really don't cvars for your directx renderer class.
  11. Sepiantum

    error code on objects in c++

    Heal would have to take in a warrior object. Try healingitems::Heal(Warrior warrior).
  12. Alright I got lua, luac, lua52.dll, and the static library compiled and working. I don't know why, but for some reason, my compiled lua is at least half the size of the binaries downloaded from luabinaries. Is it because I'm building as C++ and luabinaries builds as standard C?
  13. I've downloaded the Lua source from lua.org and I wish to compile it myself for my own uses. What files do I need to include for the lua dll + library, the lua interpreter, and lua compiler?
  14. Sepiantum

    Linking libraries into libraries

    You would need to to include all the engine header files, unless you load your library with LoadLibrary().
  15. Valve's Source engine and the Quake engine both provide the user with a cool looking console system. In a little project of mine, I've decided that it would be helpful to implement a cvar system so that I could do some realtime debugging. So how does one go about designing such a system and not kill his FPS? I'm thinking an std::unordered_map<std::string, DWORD> would be cool and all, but then console functions would not really exists.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!