bool CopyFileTo(const tstring& sFrom, const tstring& sTo, bool bOverride) { TUnimplemented(); int read_fd; int write_fd; struct stat stat_buf; off_t offset = 0; read_fd = open(sFrom.c_str(), O_RDONLY); if (!read_fd) return false; fstat(read_fd, &stat_buf); write_fd = open(sTo.c_str(), O_WRONLY | O_CREAT, stat_buf.st_mode); if (!write_fd) { close(read_fd); return false; } sendfile(write_fd, read_fd, &offset, stat_buf.st_size); close(read_fd); close(write_fd); return true; }
time_t GetFileModificationTime(const char* pszFile) { TUnimplemented(); struct stat s; if (stat(pszFile, &s) != 0) return 0; return s.st_mtime; }
tstring FindAbsolutePath(const tstring& sPath) { TUnimplemented(); char* pszFullPath = realpath(sPath.c_str(), nullptr); tstring sFullPath = pszFullPath; free(pszFullPath); return sFullPath; }
void CRenderingContext::SetDepthFunction(depth_function_t eDepthFunction) { if (eDepthFunction == DF_LEQUAL) glDepthFunc(GL_LEQUAL); else if (eDepthFunction == DF_LESS) glDepthFunc(GL_LESS); else TUnimplemented(); GetContext().m_eDepthFunction = eDepthFunction; }
void CAOGenerator::RenderSetupScene() { TUnimplemented(); tvector<tvector<float>> aaflVerts; RenderSetupSceneNode(m_pScene->GetScene(0), aaflVerts); for (size_t i = 0; i < aaflVerts.size(); i++) { m_aiSceneMaterials.push_back(CRenderer::LoadVertexDataIntoGL(aaflVerts[i].size()*sizeof(float), aaflVerts[i].data())); m_aiSceneMaterialVerts.push_back(aaflVerts[i].size()/8); } m_oRenderFB = SMAKRenderer()->CreateFrameBuffer(m_iWidth, m_iHeight, (fb_options_e)(FB_TEXTURE|FB_LINEAR|FB_DEPTH)); }
void CRenderingContext::BeginRenderQuads() { m_avecTexCoord.clear(); m_aavecTexCoords.clear(); m_avecNormals.clear(); m_aclrColors.clear(); m_avecVertices.clear(); m_bTexCoord = false; m_bNormal = false; m_bColor = false; TUnimplemented(); //m_iDrawMode = GL_QUADS; }
void CRenderingContext::SetBlend(blendtype_t eBlend) { if (eBlend) { glEnablei(GL_BLEND, 0); if (eBlend == BLEND_ALPHA) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); else if (eBlend == BLEND_ADDITIVE) glBlendFunc(GL_SRC_ALPHA, GL_ONE); else if (eBlend == BLEND_BOTH) glBlendFunc(GL_ONE, GL_ONE); else TUnimplemented(); } else glDisablei(GL_BLEND, 0); GetContext().m_eBlend = eBlend; }
void CNormalGenerator::SaveToFile(const tchar *pszFilename) { if (!pszFilename) return; tstring sFilename = pszFilename; tvector<Color> aclrTexels; aclrTexels.resize(m_iNormal2Width*m_iNormal2Height); for (size_t i = 0; i < aclrTexels.size(); i++) aclrTexels[i] = m_avecNormal2Texels[i]; if (sFilename.endswith(".png")) stbi_write_png(sFilename.c_str(), m_iNormal2Width, m_iNormal2Height, 3, aclrTexels.data(), 0); else if (sFilename.endswith(".tga")) stbi_write_tga(sFilename.c_str(), m_iNormal2Width, m_iNormal2Height, 3, aclrTexels.data()); else if (sFilename.endswith(".bmp")) stbi_write_bmp(sFilename.c_str(), m_iNormal2Width, m_iNormal2Height, 3, aclrTexels.data()); else TUnimplemented(); }
bool CDigitanksEntity::IsTouching(CBaseEntity* pOther, Vector& vecPoint) const { if (IsImprisoned()) { CDigitank* pOtherTank = dynamic_cast<CDigitank*>(pOther); if (!pOtherTank) return false; if (!pOtherTank->GetPlayerOwner()) return false; if (Distance(pOtherTank->GetRealOrigin()) > 20) return false; return true; } TUnimplemented(); return false; }
bool CShader::Compile() { tstring sShaderHeader = CShaderLibrary::GetShaderHeader(); if (CShaderLibrary::Get()->m_iSamples) sShaderHeader += "#define USE_MULTISAMPLE_TEXTURES 1\n"; sShaderHeader += CShaderLibrary::GetShaderFunctions(); FILE* f = tfopen("shaders/" + m_sVertexFile + ".vs", "r"); TAssert(f); if (!f) return false; tstring sVertexShader = sShaderHeader; sVertexShader += "uniform mat4x4 mProjection;\n"; sVertexShader += "uniform mat4x4 mView;\n"; sVertexShader += "uniform mat4x4 mGlobal;\n"; tstring sLine; while (fgetts(sLine, f)) sVertexShader += sLine; fclose(f); f = tfopen("shaders/" + m_sFragmentFile + ".fs", "r"); TAssert(f); if (!f) return false; tstring sFragmentShader = sShaderHeader; sFragmentShader += "out vec4 vecOutputColor;\n"; while (fgetts(sLine, f)) sFragmentShader += sLine; fclose(f); size_t iVShader = glCreateShader(GL_VERTEX_SHADER); const char* pszStr = sVertexShader.c_str(); glShaderSource((GLuint)iVShader, 1, &pszStr, NULL); glCompileShader((GLuint)iVShader); int iVertexCompiled; glGetShaderiv((GLuint)iVShader, GL_COMPILE_STATUS, &iVertexCompiled); if (iVertexCompiled != GL_TRUE || Application()->HasCommandLineSwitch("--debug-gl")) { int iLogLength = 0; char szLog[1024]; glGetShaderInfoLog((GLuint)iVShader, 1024, &iLogLength, szLog); CShaderLibrary::Get()->WriteLog(m_sVertexFile + ".vs", szLog, pszStr); } size_t iFShader = glCreateShader(GL_FRAGMENT_SHADER); pszStr = sFragmentShader.c_str(); glShaderSource((GLuint)iFShader, 1, &pszStr, NULL); glCompileShader((GLuint)iFShader); int iFragmentCompiled; glGetShaderiv((GLuint)iFShader, GL_COMPILE_STATUS, &iFragmentCompiled); if (iFragmentCompiled != GL_TRUE || Application()->HasCommandLineSwitch("--debug-gl")) { int iLogLength = 0; char szLog[1024]; glGetShaderInfoLog((GLuint)iFShader, 1024, &iLogLength, szLog); CShaderLibrary::Get()->WriteLog(m_sFragmentFile + ".fs", szLog, pszStr); } size_t iProgram = glCreateProgram(); glBindAttribLocation(iProgram, 0, "vecPosition"); // Force position at location 0. ATI cards won't work without this. glAttachShader((GLuint)iProgram, (GLuint)iVShader); glAttachShader((GLuint)iProgram, (GLuint)iFShader); glLinkProgram((GLuint)iProgram); int iProgramLinked; glGetProgramiv((GLuint)iProgram, GL_LINK_STATUS, &iProgramLinked); if (iProgramLinked != GL_TRUE || Application()->HasCommandLineSwitch("--debug-gl")) { int iLogLength = 0; char szLog[1024]; glGetProgramInfoLog((GLuint)iProgram, 1024, &iLogLength, szLog); CShaderLibrary::Get()->WriteLog("link", szLog, "link"); } if (iVertexCompiled != GL_TRUE || iFragmentCompiled != GL_TRUE || iProgramLinked != GL_TRUE) { TError("Shader compilation failed for shader " + m_sName + ". Check shaders.txt\n"); Destroy(); return false; } m_iProgram = iProgram; m_iVShader = iVShader; m_iFShader = iFShader; m_iPositionAttribute = glGetAttribLocation(m_iProgram, "vecPosition"); m_iNormalAttribute = glGetAttribLocation(m_iProgram, "vecNormal"); m_iTangentAttribute = glGetAttribLocation(m_iProgram, "vecTangent"); m_iBitangentAttribute = glGetAttribLocation(m_iProgram, "vecBitangent"); for (size_t i = 0; i < MAX_TEXTURE_CHANNELS; i++) m_aiTexCoordAttributes[i] = glGetAttribLocation(m_iProgram, sprintf("vecTexCoord%d", i).c_str()); m_iColorAttribute = glGetAttribLocation(m_iProgram, "vecVertexColor"); glBindFragDataLocation(m_iProgram, 0, "vecOutputColor"); TAssert(m_iPositionAttribute != ~0); int iNumUniforms; glGetProgramiv(m_iProgram, GL_ACTIVE_UNIFORMS, &iNumUniforms); char szUniformName[256]; GLsizei iLength; GLint iSize; GLenum iType; for (int i = 0; i < iNumUniforms; i++) { glGetActiveUniform(m_iProgram, i, sizeof(szUniformName), &iLength, &iSize, &iType, szUniformName); tstring sUniformName = szUniformName; if (sUniformName == "mProjection") continue; if (sUniformName == "mView") continue; if (sUniformName == "mGlobal") continue; CShader::CUniform& oUniform = m_asUniforms[sUniformName]; oUniform.m_pDefault = nullptr; switch (iType) { case GL_FLOAT: oUniform.m_sUniformType = "float"; break; case GL_FLOAT_VEC2: oUniform.m_sUniformType = "vec2"; break; case GL_FLOAT_VEC3: oUniform.m_sUniformType = "vec3"; break; case GL_FLOAT_VEC4: oUniform.m_sUniformType = "vec4"; break; case GL_INT: oUniform.m_sUniformType = "int"; break; case GL_BOOL: oUniform.m_sUniformType = "bool"; break; case GL_FLOAT_MAT4: oUniform.m_sUniformType = "mat4"; break; case GL_SAMPLER_2D: oUniform.m_sUniformType = "sampler2D"; break; default: TUnimplemented(); } } for (auto it = m_aParameters.begin(); it != m_aParameters.end(); it++) { for (size_t j = 0; j < it->second.m_aActions.size(); j++) { auto it2 = m_asUniforms.find(it->second.m_aActions[j].m_sName); TAssert(it2 != m_asUniforms.end()); if (it2 == m_asUniforms.end()) { TError("Shader '" + m_sName + "' specifies a uniform '" + it->second.m_aActions[j].m_sName + "' that is not in the linked program.\n"); continue; } CShader::CUniform& oUniform = it2->second; // This is almost cheating CData d; d.SetValue(it->second.m_aActions[j].m_sValue); if (oUniform.m_sUniformType == "float") it->second.m_aActions[j].m_flValue = d.GetValueFloat(); else if (oUniform.m_sUniformType == "vec2") it->second.m_aActions[j].m_vec2Value = d.GetValueVector2D(); else if (oUniform.m_sUniformType == "vec3") it->second.m_aActions[j].m_vecValue = d.GetValueVector(); else if (oUniform.m_sUniformType == "vec4") it->second.m_aActions[j].m_vec4Value = d.GetValueVector4D(); else if (oUniform.m_sUniformType == "int") it->second.m_aActions[j].m_iValue = d.GetValueInt(); else if (oUniform.m_sUniformType == "bool") it->second.m_aActions[j].m_bValue = d.GetValueBool(); else if (oUniform.m_sUniformType == "mat4") { TUnimplemented(); } else if (oUniform.m_sUniformType == "sampler2D") { // No op. } else TUnimplemented(); } } for (auto it = m_aDefaults.begin(); it != m_aDefaults.end(); it++) { auto it2 = m_asUniforms.find(it->first); TAssert(it2 != m_asUniforms.end()); if (it2 == m_asUniforms.end()) { TError("Shader '" + m_sName + "' specifies a default for uniform '" + it->second.m_sName + "' that is not in the linked program.\n"); continue; } CShader::CUniform& oUniform = it2->second; oUniform.m_pDefault = &it->second; // Again with the cheating. CData d; d.SetValue(it->second.m_sValue); if (oUniform.m_sUniformType == "float") it->second.m_flValue = d.GetValueFloat(); else if (oUniform.m_sUniformType == "vec2") it->second.m_vec2Value = d.GetValueVector2D(); else if (oUniform.m_sUniformType == "vec3") it->second.m_vecValue = d.GetValueVector(); else if (oUniform.m_sUniformType == "vec4") it->second.m_vec4Value = d.GetValueVector4D(); else if (oUniform.m_sUniformType == "int") it->second.m_iValue = d.GetValueInt(); else if (oUniform.m_sUniformType == "bool") it->second.m_bValue = d.GetValueBool(); else if (oUniform.m_sUniformType == "mat4") { TUnimplemented(); } else if (oUniform.m_sUniformType == "sampler2D") { TUnimplemented(); // Can't set a default texture... yet. } else TUnimplemented(); } return true; }
bool CGeppetto::BuildFromInputScript(const tstring& sScript) { FILE* fp = tfopen_asset(GetPath(sScript), "r"); if (!fp) { TError("Could not read input script '" + sScript + "'\n"); return false; } std::shared_ptr<CData> pData(new CData()); CDataSerializer::Read(fp, pData.get()); CData* pOutput = pData->FindChild("Output"); if (!pOutput) { TError("Could not find Output section in input script '" + sScript + "'\n"); return false; } CData* pGame = pData->FindChild("Game"); if (!pGame) { TError("Could not find Game section in input script '" + sScript + "'\n"); return false; } t.SetGameDirectory(FindAbsolutePath(GetPath(pGame->GetValueString()))); tstring sOutputDir = ToForwardSlashes(pOutput->GetValueString()); t.SetOutputDirectory(GetDirectory(sOutputDir)); t.SetOutputFile(GetFilename(sOutputDir)); t.SetScriptDirectory(GetDirectory((GetPath(sScript)))); m_sOutput = FindAbsolutePath(t.GetGameDirectory() + T_DIR_SEP + pOutput->GetValueString()); CData* pSceneAreas = pData->FindChild("SceneAreas"); CData* pMesh = pData->FindChild("Mesh"); CData* pPhysics = pData->FindChild("Physics"); CData* pPhysicsShapes = pData->FindChild("PhysicsShapes"); // Find all file modification times. time_t iScriptModificationTime = GetFileModificationTime(sScript.c_str()); time_t iOutputModificationTime = GetFileModificationTime(m_sOutput.c_str()); tmap<tstring, time_t> aiSceneModificationTimes; if (pSceneAreas) { for (size_t i = 0; i < pSceneAreas->GetNumChildren(); i++) { CData* pArea = pSceneAreas->GetChild(i); if (pArea->GetKey() != "Area") continue; tstring sFile = pArea->FindChildValueString("File"); TAssert(sFile.length()); if (!sFile.length()) continue; auto it = aiSceneModificationTimes.find(sFile); if (it == aiSceneModificationTimes.end()) aiSceneModificationTimes[sFile] = GetFileModificationTime(sFile.c_str()); } } time_t iInputModificationTime = 0; if (pMesh) iInputModificationTime = GetFileModificationTime(pMesh->GetValueString().c_str()); time_t iPhysicsModificationTime = 0; if (pPhysics) iPhysicsModificationTime = GetFileModificationTime(pPhysics->GetValueString().c_str()); bool bRecompile = false; if (iScriptModificationTime > iOutputModificationTime) bRecompile = true; else if (iInputModificationTime > iOutputModificationTime) bRecompile = true; else if (iPhysicsModificationTime > iOutputModificationTime) bRecompile = true; else if (m_iBinaryModificationTime > iOutputModificationTime) bRecompile = true; else { for (auto it = aiSceneModificationTimes.begin(); it != aiSceneModificationTimes.end(); it++) { if (it->second > iOutputModificationTime) { bRecompile = true; break; } } } if (!bRecompile) { if (m_bForceCompile) { TMsg("Forcing rebuild even though no changes detected.\n"); } else { TMsg("No changes detected. Skipping '" + m_sOutput + "'.\n\n"); return true; } } CData* pGlobalTransforms = pData->FindChild("UseGlobalTransforms"); if (pGlobalTransforms) t.UseGlobalTransformations(); else t.UseLocalTransformations(); t.UseUV(); t.UseNormals(); if (pMesh) { tstring sExtension = pMesh->GetValueString().substr(pMesh->GetValueString().length()-4); if (sExtension == ".png") { TUnimplemented(); // Not updated since the switch to materials. int x, y, n; unsigned char* pData = stbi_load((GetPath(pMesh->GetValueString())).c_str(), &x, &y, &n, 0); if (!pData) { TError("Couldn't load '" + pMesh->GetValueString() + "', reason: " + stbi_failure_reason() + "\n"); return false; } stbi_image_free(pData); // Don't need it, just need the dimensions. Vector vecUp = Vector(0, 0, 0.5f) * ((float)y/100); Vector vecLeft = Vector(0, 0.5f, 0) * ((float)x/100); t.UseNormals(false); if (IsAbsolutePath(pMesh->GetValueString())) t.AddMaterial(GetPath(pMesh->GetValueString())); else t.AddMaterial(t.GetOutputDirectory() + "/" + pMesh->GetValueString(), GetPath(pMesh->GetValueString())); t.AddVertex(0, -vecLeft + vecUp, Vector2D(0.0f, 1.0f)); t.AddVertex(0, -vecLeft - vecUp, Vector2D(0.0f, 0.0f)); t.AddVertex(0, vecLeft - vecUp, Vector2D(1.0f, 0.0f)); t.AddVertex(0, -vecLeft + vecUp, Vector2D(0.0f, 1.0f)); t.AddVertex(0, vecLeft - vecUp, Vector2D(1.0f, 0.0f)); t.AddVertex(0, vecLeft + vecUp, Vector2D(1.0f, 1.0f)); } else if (sExtension == ".mat") { CMaterialHandle hMaterial(pMesh->GetValueString()); if (!hMaterial.IsValid()) { TError("Input material '" + pMesh->GetValueString() + "' does not exist or is invalid.\n"); return false; } if (!hMaterial->m_ahTextures.size()) { TError("Input material '" + pMesh->GetValueString() + "' has no textures.\n"); return false; } float w = (float)hMaterial->m_ahTextures[0]->m_iWidth; float h = (float)hMaterial->m_ahTextures[0]->m_iHeight; Vector vecUp = Vector(0, 0.5f, 0) * (h/hMaterial->m_iTexelsPerMeter); Vector vecRight = Vector(0, 0, 0.5f) * (w/hMaterial->m_iTexelsPerMeter); t.UseNormals(false); t.AddMaterial(pMesh->GetValueString()); t.AddVertex(0, -vecRight + vecUp, Vector2D(0.0f, 1.0f)); t.AddVertex(0, -vecRight - vecUp, Vector2D(0.0f, 0.0f)); t.AddVertex(0, vecRight - vecUp, Vector2D(1.0f, 0.0f)); t.AddVertex(0, -vecRight + vecUp, Vector2D(0.0f, 1.0f)); t.AddVertex(0, vecRight - vecUp, Vector2D(1.0f, 0.0f)); t.AddVertex(0, vecRight + vecUp, Vector2D(1.0f, 1.0f)); } else { TMsg("Reading model '" + GetPath(pMesh->GetValueString()) + "' ..."); std::shared_ptr<CConversionScene> pScene(new CConversionScene()); CModelConverter c(pScene.get()); if (!c.ReadModel(GetPath(pMesh->GetValueString()))) { TError("Couldn't read '" + GetPath(pMesh->GetValueString()) + "'.\n"); return false; } TMsg(" Done.\n"); TMsg("Building toy mesh ..."); LoadSceneIntoToy(pScene.get(), &t); TMsg(" Done.\n"); } } if (pPhysics) { TMsg("Reading physics model '" + GetPath(pPhysics->GetValueString()) + "' ..."); std::shared_ptr<CConversionScene> pScene(new CConversionScene()); CModelConverter c(pScene.get()); if (!c.ReadModel(GetPath(pPhysics->GetValueString()))) { TError("Couldn't read '" + GetPath(pPhysics->GetValueString()) + "'.\n"); return false; } TMsg(" Done.\n"); TMsg("Building toy physics model ..."); LoadSceneIntoToyPhysics(pScene.get(), &t); TMsg(" Done.\n"); } if (pPhysicsShapes) { for (size_t i = 0; i < pPhysicsShapes->GetNumChildren(); i++) { CData* pShape = pPhysicsShapes->GetChild(i); TAssert(pShape->GetKey() == "Box"); if (pShape->GetKey() != "Box") continue; TRS trs = pShape->GetValueTRS(); t.AddPhysBox(trs); } } if (pSceneAreas) LoadSceneAreas(pSceneAreas); return Compile(); }
void NetClient::Service() { m_shared.Service(); uint16 packet_size; // In bytes uint8 packet_contents[MAX_PACKET_LENGTH]; packet_size = 2; packet_contents[0] = 'V'; packet_contents[1] = 0; // How many values are in this packet? for (int n = 0; n < m_shared.m_replicated_fields_size; n++) { replicated_field_t table_entry_index = m_shared.m_replicated_fields[n].m_table_entry; TAssert(table_entry_index < m_shared.m_replicated_fields_table_size); replicated_entity_instance_t entity_instance_index = m_shared.m_replicated_fields[n].m_instance_entry; ReplicatedField* table_entry = &m_shared.m_replicated_fields_table[table_entry_index]; ReplicatedInstanceEntity* entity_instance = &m_shared.m_replicated_entities[entity_instance_index]; if (memcmp(ENTITY_FIELD_OFFSET(entity_instance->m_entity, table_entry->m_offset), ENTITY_FIELD_OFFSET(entity_instance->m_entity_copy, table_entry->m_offset), table_entry->m_size) == 0) continue; m_shared.Packet_WriteValueChange(packet_contents, &packet_size, table_entry_index, entity_instance_index); memcpy(ENTITY_FIELD_OFFSET(entity_instance->m_entity_copy, table_entry->m_offset), ENTITY_FIELD_OFFSET(entity_instance->m_entity, table_entry->m_offset), table_entry->m_size); } if (packet_contents[1]) m_shared.Packet_Send(packet_contents, packet_size, 0); ENetEvent event; while (enet_host_service(m_enetclient, &event, 0) > 0) { switch (event.type) { case ENET_EVENT_TYPE_CONNECT: break; case ENET_EVENT_TYPE_RECEIVE: TCheck(event.packet->dataLength); if (!event.packet->dataLength) break; switch (event.packet->data[0]) { case 'C': { TAssert(event.packet->dataLength == 5); replicated_entity_instance_t entity_instance_index = event.packet->data[1]; replicated_entity_t entity_table_index = event.packet->data[2]; uint16 entity_index = tntohs(*(uint16*)&event.packet->data[3]); AddEntityFromServer(entity_instance_index, entity_table_index, entity_index); break; } case 'V': TAssert(((uint16)event.packet->dataLength) == event.packet->dataLength); m_shared.Packet_ReadValueChanges(event.packet->data, (uint16)event.packet->dataLength); break; case 'W': TAssert(event.packet->dataLength == 2); m_peer_index = event.packet->data[1]; break; default: TUnimplemented(); break; } enet_packet_destroy(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: TUnimplemented(); break; default: TUnimplemented(); break; } } }
// Add any neighbors of iVisible which are visible to iArea's visible set. void CToyUtil::AddVisibleNeighbors(size_t iArea, size_t iVisible) { if (iArea == iVisible) return; tvector<Vector> avecPoints; for (size_t i = 0; i < m_asSceneAreas[iVisible].m_aiNeighboringAreas.size(); i++) { size_t iOther = m_asSceneAreas[iVisible].m_aiNeighboringAreas[i]; // If this area is already visible, we can skip it to prevent extra work and recursion. if (IsVisibleFrom(iArea, iOther)) continue; // Form a convex hull from the bounding boxes of iArea and i avecPoints.clear(); Vector vecMins = m_asSceneAreas[iArea].m_aabbArea.m_vecMins; Vector vecMaxs = m_asSceneAreas[iArea].m_aabbArea.m_vecMaxs; avecPoints.push_back(vecMins); avecPoints.push_back(Vector(vecMins.x, vecMins.y, vecMaxs.z)); avecPoints.push_back(Vector(vecMaxs.x, vecMins.y, vecMaxs.z)); avecPoints.push_back(Vector(vecMaxs.x, vecMins.y, vecMins.z)); avecPoints.push_back(Vector(vecMins.x, vecMaxs.y, vecMins.z)); avecPoints.push_back(Vector(vecMins.x, vecMaxs.y, vecMaxs.z)); avecPoints.push_back(Vector(vecMaxs.x, vecMaxs.y, vecMins.z)); avecPoints.push_back(vecMaxs); vecMins = m_asSceneAreas[iOther].m_aabbArea.m_vecMins; vecMaxs = m_asSceneAreas[iOther].m_aabbArea.m_vecMaxs; avecPoints.push_back(vecMins); avecPoints.push_back(Vector(vecMins.x, vecMins.y, vecMaxs.z)); avecPoints.push_back(Vector(vecMaxs.x, vecMins.y, vecMaxs.z)); avecPoints.push_back(Vector(vecMaxs.x, vecMins.y, vecMins.z)); avecPoints.push_back(Vector(vecMins.x, vecMaxs.y, vecMins.z)); avecPoints.push_back(Vector(vecMins.x, vecMaxs.y, vecMaxs.z)); avecPoints.push_back(Vector(vecMaxs.x, vecMaxs.y, vecMins.z)); avecPoints.push_back(vecMaxs); #ifdef __linux__ // Odd linker errors, linker can't find CConvexHullGenerator for some reason TUnimplemented(); #else CConvexHullGenerator c(avecPoints); const tvector<size_t>& avecConvexTriangles = c.GetConvexTriangles(); // Test to see if iVisible intersects that hull AABB aabbShrunkBounds = m_asSceneAreas[iVisible].m_aabbArea + AABB(Vector(0.1f, 0.1f, 0.1f), Vector(-0.1f, -0.1f, -0.1f)); // Shrink the bounds a tad so touching bounds on the far side don't count. bool bIntersect = ConvexHullIntersectsAABB(aabbShrunkBounds, avecPoints, avecConvexTriangles); if (bIntersect) { AddSceneAreaVisible(iArea, iOther); AddSceneAreaVisible(iOther, iArea); // Calling it recursively this way may allow visibility that doesn't exist, eg, in a chain a -> b -> c -> d, a can see d through c but not through b. // I'm willing to accept that for now if it doesn't become a problem. AddVisibleNeighbors(iArea, iOther); } #endif } }
Vector CAOGenerator::RenderSceneFromPosition(Vector vecPosition, Vector vecDirection, CConversionFace* pRenderFace) { TUnimplemented(); CRenderingContext c(SMAKRenderer()); c.UseFrameBuffer(&m_oRenderFB); // Bring it away from its poly so that the camera never clips around behind it. // Adds .001 because of a bug where GL for some reason won't show the faces unless I do that. Vector vecEye = vecPosition + (vecDirection + Vector(.001f, .001f, .001f)) * 0.1f; c.SetViewport(Rect(m_iRPVX, m_iRPVY, m_iRPVW, m_iRPVH)); c.SetProjection(Matrix4x4::ProjectPerspective(120.0f, 1, 0.01f, 100.0f)); c.SetView(Matrix4x4::ConstructCameraView(vecEye, vecDirection, Vector(0, 1, 0))); c.ClearColor(); c.ClearDepth(); for (size_t i = 0; i < m_aiSceneMaterials.size(); i++) { TAssert(i < SMAKWindow()->GetMaterials().size()); if (i >= SMAKWindow()->GetMaterials().size()) break; if (!m_aiSceneMaterialVerts[i]) continue; c.UseMaterial(SMAKWindow()->GetMaterials()[i]); c.BeginRenderVertexArray(m_aiSceneMaterials[i]); c.SetPositionBuffer((size_t)0, 5*sizeof(float)); c.SetTexCoordBuffer((size_t)3*sizeof(float), 5*sizeof(float)); c.EndRenderVertexArray(m_aiSceneMaterialVerts[i]); } c.Finish(); #ifdef AO_DEBUG DebugRenderSceneLookAtPosition(vecPosition, vecDirection, pRenderFace); glFinish(); #endif c.ReadPixels(m_iRPVX, m_iRPVY, m_iRPVW, m_iRPVH, m_pvecPixels); Vector vecShadowColor; float flTotal = 0; for (size_t p = 0; p < m_iRPVW*m_iRPVH*m_iPixelDepth; p++) { float flColumn = fmod((float)p / (float)m_iPixelDepth, (float)m_iRPVW); Vector vecUV(flColumn / m_iRPVW, (float)(p / m_iPixelDepth / m_iRPVW) / m_iRPVH, 0); Vector vecUVCenter(0.5f, 0.5f, 0); // Weight the pixel based on its distance to the center. // With the huge FOV that we work with, polygons to the // outside are huge on the screen. float flWeight = (0.5f-(vecUV - vecUVCenter).Length())*2.0f; if (flWeight <= 0.1) continue; // Pixels in the center of the screen are much, much more important. flWeight = SLerp(flWeight, 0.2f); Vector vecPixel(m_pvecPixels[p].x, m_pvecPixels[p].y, m_pvecPixels[p].z); vecShadowColor += vecPixel * flWeight; flTotal += flWeight; } vecShadowColor /= flTotal; return vecShadowColor; }
void CGameServer::LoadLevel(const CHandle<CLevel>& pLevel) { // Create and name the entities first and add them to this array. This way we avoid a problem where // one entity needs to connect to another entity which has not yet been created. tmap<size_t, CBaseEntity*> apEntities; // Do a quick precache now to load default models and such. Another precache will come later. const auto& aEntities = pLevel->GetEntityData(); for (size_t i = 0; i < aEntities.size(); i++) AddToPrecacheList("C" + aEntities[i].GetClass()); PrecacheList(); m_bAllowPrecaches = true; for (size_t i = 0; i < aEntities.size(); i++) { const CLevelEntity* pLevelEntity = &aEntities[i]; tstring sClass = "C" + pLevelEntity->GetClass(); auto it = CBaseEntity::GetEntityRegistration().find(sClass); TAssert(it != CBaseEntity::GetEntityRegistration().end()); if (it == CBaseEntity::GetEntityRegistration().end()) { TError("Unregistered entity '" + sClass + "'\n"); continue; } AddToPrecacheList("C" + aEntities[i].GetClass()); CBaseEntity* pEntity = Create<CBaseEntity>(sClass.c_str()); apEntities[i] = pEntity; pEntity->SetName(pLevelEntity->GetName()); // Process outputs here so that they exist when handle callbacks run. for (size_t k = 0; k < pLevelEntity->GetOutputs().size(); k++) { auto pOutput = &pLevelEntity->GetOutputs()[k]; tstring sValue = pOutput->m_sOutput; CSaveData* pSaveData = CBaseEntity::FindOutput(pEntity->GetClassName(), sValue); TAssert(pSaveData); if (!pSaveData) { TError("Unknown output '" + sValue + "'\n"); continue; } tstring sTarget = pOutput->m_sTargetName; tstring sInput = pOutput->m_sInput; tstring sArgs = pOutput->m_sArgs; bool bKill = pOutput->m_bKill; if (!sTarget.length()) { TUnimplemented(); TError("Output '" + sValue + "' of entity '" + pEntity->GetName() + "' (" + pEntity->GetClassName() + ") is missing a target.\n"); continue; } if (!sInput.length()) { TUnimplemented(); TError("Output '" + sValue + "' of entity '" + pEntity->GetName() + "' (" + pEntity->GetClassName() + ") is missing an input.\n"); continue; } pEntity->AddOutputTarget(sValue, sTarget, sInput, sArgs, bKill); } } for (auto it = apEntities.begin(); it != apEntities.end(); it++) { auto pLevelEntity = &aEntities[it->first]; CBaseEntity* pEntity = it->second; // Force physics related stuff first so it's available if there's a physics model. auto itScale = pLevelEntity->GetParameters().find("Scale"); if (itScale != pLevelEntity->GetParameters().end()) UnserializeParameter("Scale", itScale->second, pEntity); auto itOrigin = pLevelEntity->GetParameters().find("Origin"); if (itOrigin != pLevelEntity->GetParameters().end()) UnserializeParameter("Origin", itOrigin->second, pEntity); for (auto it = pLevelEntity->GetParameters().begin(); it != pLevelEntity->GetParameters().end(); it++) { tstring sHandle = it->first; tstring sValue = it->second; if (sHandle == "MoveParent") continue; if (sHandle == "Scale") continue; if (sHandle == "Origin") continue; UnserializeParameter(sHandle, sValue, pEntity); } } for (auto it = apEntities.begin(); it != apEntities.end(); it++) { auto pLevelEntity = &aEntities[it->first]; CBaseEntity* pEntity = it->second; // Force MoveParent last so that global -> local conversion is performed. auto itMoveParent = pLevelEntity->GetParameters().find("MoveParent"); if (itMoveParent != pLevelEntity->GetParameters().end()) UnserializeParameter("MoveParent", itMoveParent->second, pEntity); } for (size_t i = 0; i < apEntities.size(); i++) apEntities[i]->PostLoad(); if (CWorkbench::IsActive()) CWorkbench::LoadLevel(pLevel); }
bool CopyFileTo(const tstring& sFrom, const tstring& sTo, bool bOverride) { TUnimplemented(); return 0; }
void CreateDirectoryNonRecursive(const tstring& sPath) { TUnimplemented(); mkdir(sPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); }
void SetClipboard(const tstring& sBuf) { TUnimplemented(); }
tstring GetClipboard() { TUnimplemented(); return tstring(); }
void CRenderingContext::SetupMaterial() { if (!GetContext().m_hMaterial.IsValid()) return; if (!m_pShader) return; const tstring& sMaterialBlend = GetContext().m_hMaterial->m_sBlend; if (sMaterialBlend == "alpha") SetBlend(BLEND_ALPHA); else if (sMaterialBlend == "additive") SetBlend(BLEND_ADDITIVE); else { TAssert(!sMaterialBlend.length()); SetBlend(BLEND_NONE); } for (auto it = m_pShader->m_asUniforms.begin(); it != m_pShader->m_asUniforms.end(); it++) { CShader::CUniform& pUniformName = it->second; CShader::CParameter::CUniform* pUniform = it->second.m_pDefault; if (pUniform) { if (pUniformName.m_sUniformType == "float") SetUniform(it->first.c_str(), pUniform->m_flValue); else if (pUniformName.m_sUniformType == "vec2") SetUniform(it->first.c_str(), pUniform->m_vec2Value); else if (pUniformName.m_sUniformType == "vec3") SetUniform(it->first.c_str(), pUniform->m_vecValue); else if (pUniformName.m_sUniformType == "vec4") SetUniform(it->first.c_str(), pUniform->m_vec4Value); else if (pUniformName.m_sUniformType == "int") SetUniform(it->first.c_str(), pUniform->m_iValue); else if (pUniformName.m_sUniformType == "bool") SetUniform(it->first.c_str(), pUniform->m_bValue); else if (pUniformName.m_sUniformType == "mat4") { TUnimplemented(); } else if (pUniformName.m_sUniformType == "sampler2D") { TUnimplemented(); } else TUnimplemented(); } else { if (pUniformName.m_sUniformType == "float") SetUniform(it->first.c_str(), 0.0f); else if (pUniformName.m_sUniformType == "vec2") SetUniform(it->first.c_str(), Vector2D()); else if (pUniformName.m_sUniformType == "vec3") SetUniform(it->first.c_str(), Vector()); else if (pUniformName.m_sUniformType == "vec4") SetUniform(it->first.c_str(), Vector4D()); else if (pUniformName.m_sUniformType == "int") SetUniform(it->first.c_str(), 0); else if (pUniformName.m_sUniformType == "bool") SetUniform(it->first.c_str(), false); else if (pUniformName.m_sUniformType == "mat4") SetUniform(it->first.c_str(), Matrix4x4()); else if (pUniformName.m_sUniformType == "sampler2D") SetUniform(it->first.c_str(), 0); else TUnimplemented(); } } for (size_t i = 0; i < GetContext().m_hMaterial->m_aParameters.size(); i++) { auto& oParameter = GetContext().m_hMaterial->m_aParameters[i]; CShader::CParameter* pShaderParameter = oParameter.m_pShaderParameter; TAssert(pShaderParameter); if (!pShaderParameter) continue; for (size_t j = 0; j < pShaderParameter->m_aActions.size(); j++) { auto& oAction = pShaderParameter->m_aActions[j]; tstring& sName = oAction.m_sName; tstring& sValue = oAction.m_sValue; tstring& sType = m_pShader->m_asUniforms[sName].m_sUniformType; if (sValue == "[value]") { if (sType == "float") SetUniform(sName.c_str(), oParameter.m_flValue); else if (sType == "vec2") SetUniform(sName.c_str(), oParameter.m_vec2Value); else if (sType == "vec3") SetUniform(sName.c_str(), oParameter.m_vecValue); else if (sType == "vec4") SetUniform(sName.c_str(), oParameter.m_vec4Value); else if (sType == "int") SetUniform(sName.c_str(), oParameter.m_iValue); else if (sType == "bool") SetUniform(sName.c_str(), oParameter.m_bValue); else if (sType == "mat4") { TUnimplemented(); } else if (sType == "sampler2D") { // No op, handled below. } else TUnimplemented(); } else { if (sType == "float") SetUniform(sName.c_str(), oAction.m_flValue); else if (sType == "vec2") SetUniform(sName.c_str(), oAction.m_vec2Value); else if (sType == "vec3") SetUniform(sName.c_str(), oAction.m_vecValue); else if (sType == "vec4") SetUniform(sName.c_str(), oAction.m_vec4Value); else if (sType == "int") SetUniform(sName.c_str(), oAction.m_iValue); else if (sType == "bool") SetUniform(sName.c_str(), oAction.m_bValue); else if (sType == "mat4") { TUnimplemented(); } else if (sType == "sampler2D") { TUnimplemented(); SetUniform(sName.c_str(), 0); } else TUnimplemented(); } } } for (size_t i = 0; i < m_pShader->m_asTextures.size(); i++) { if (!GetContext().m_hMaterial->m_ahTextures[i].IsValid()) continue; glActiveTexture(GL_TEXTURE0+i); glBindTexture(GL_TEXTURE_2D, (GLuint)GetContext().m_hMaterial->m_ahTextures[i]->m_iGLID); SetUniform(m_pShader->m_asTextures[i].c_str(), (int)i); } }
void CLevelEntity::SetParameterValue(const tstring& sKey, const tstring& sValue) { auto it = m_asParameters.find(sKey); if (it == m_asParameters.end()) { if (!sValue.length()) return; m_asParameters[sKey] = sValue; } else { if (!sValue.length()) { m_asParameters.erase(sKey); Dirtify(); return; } tstring& sCurrentValue = it->second; if (sCurrentValue == sValue) return; sCurrentValue = sValue; } Dirtify(); CSaveData oSaveData; CSaveData* pSaveData = CBaseEntity::FindSaveDataValuesByHandle(("C" + GetClass()).c_str(), sKey.c_str(), &oSaveData); if (!pSaveData) TMsg("Level entity " + GetClass() + ":" + GetName() + " has unregistered savedata value: " + sKey + "\n"); if (pSaveData && pSaveData->m_pszHandle && pSaveData->m_bDefault) { // Special case. if (strcmp(pSaveData->m_pszHandle, "Model") == 0) { m_hMaterialModel = CMaterialLibrary::AddMaterial(sValue); // Don't continue to erasing the default parameters if it's a model, since models have special processing. return; } if (strcmp(pSaveData->m_pszType, "bool") == 0) { bool bValue = UnserializeString_bool(sValue); bool b = *((bool*)&pSaveData->m_oDefault[0]); if (bValue == b) m_asParameters.erase(sKey); } else { if (strcmp(pSaveData->m_pszType, "size_t") == 0) { size_t i = *((size_t*)&pSaveData->m_oDefault[0]); if (stoi(sValue) == i) m_asParameters.erase(sKey); } else if (strcmp(pSaveData->m_pszType, "float") == 0) { float f = *((float*)&pSaveData->m_oDefault[0]); if (stof(sValue) == f) m_asParameters.erase(sKey); } else if (strcmp(pSaveData->m_pszType, "Vector") == 0) { if (CanUnserializeString_TVector(sValue)) { Vector v = *((Vector*)&pSaveData->m_oDefault[0]); if (UnserializeString_TVector(sValue) == v) m_asParameters.erase(sKey); } } else if (strcmp(pSaveData->m_pszType, "Vector2D") == 0) { if (CanUnserializeString_Vector2D(sValue)) { Vector2D v = *((Vector2D*)&pSaveData->m_oDefault[0]); if (UnserializeString_Vector2D(sValue) == v) m_asParameters.erase(sKey); } } else if (strcmp(pSaveData->m_pszType, "EAngle") == 0) { if (CanUnserializeString_EAngle(sValue)) { EAngle v = *((EAngle*)&pSaveData->m_oDefault[0]); if (UnserializeString_EAngle(sValue) == v) m_asParameters.erase(sKey); } } else if (strcmp(pSaveData->m_pszType, "Matrix4x4") == 0) { if (CanUnserializeString_Matrix4x4(sValue)) { Matrix4x4 m = *((Matrix4x4*)&pSaveData->m_oDefault[0]); if (UnserializeString_Matrix4x4(sValue) == m) m_asParameters.erase(sKey); } } else if (strcmp(pSaveData->m_pszType, "AABB") == 0) { if (CanUnserializeString_AABB(sValue)) { AABB b = *((AABB*)&pSaveData->m_oDefault[0]); if (UnserializeString_AABB(sValue) == b) m_asParameters.erase(sKey); } } else { TUnimplemented(); } } } }
void CGameServerNetwork::UpdateNetworkVariables(int iClient, bool bForceAll) { if (!GameNetwork()->IsConnected()) return; double flTime = GameServer()->GetGameTime(); size_t iMaxEnts = GameServer()->GetMaxEntities(); for (size_t i = 0; i < iMaxEnts; i++) { CBaseEntity* pEntity = CBaseEntity::GetEntity(i); if (!pEntity) continue; const tchar* pszClassName = pEntity->GetClassName(); CEntityRegistration* pRegistration = NULL; do { pRegistration = pEntity->GetRegisteredEntity(pszClassName); TAssert(pRegistration); if (!pRegistration) break; size_t iNetVarsSize = pRegistration->m_aNetworkVariables.size(); for (size_t j = 0; j < iNetVarsSize; j++) { CNetworkedVariableData* pVarData = &pRegistration->m_aNetworkVariables[j]; CNetworkedVariableBase* pVariable = pVarData->GetNetworkedVariableBase(pEntity); if (!bForceAll) { if (!pVariable->IsDirty()) continue; if (flTime - pVariable->m_flLastUpdate < pVarData->m_flUpdateInterval) continue; } // For one, m_flLastUpdate needs to be a double pVariable->m_flLastUpdate = (float)flTime; // For two, it's shit. TUnimplemented(); // Try some testing or something. CNetworkParameters p; p.ui1 = pEntity->GetHandle(); size_t iDataSize; void* pValue = pVariable->Serialize(iDataSize); if (net_replication_debug.GetBool()) { if (iDataSize >= 4) TMsg(tstring("Updating ") + pVarData->GetName() + sprintf(tstring(" (%x) (%f) (%d)\n"), *(unsigned int*)pValue, *(float*)pValue, *(int*)pValue)); else TMsg(tstring("Updating ") + pVarData->GetName() + "\n"); } p.CreateExtraData(iDataSize + strlen(pVarData->GetName())+1); strcpy((char*)p.m_pExtraData, pVarData->GetName()); memcpy((unsigned char*)(p.m_pExtraData) + strlen(pVarData->GetName())+1, pValue, iDataSize); // UV stands for UpdateValue GameNetwork()->CallFunctionParameters(iClient, "UV", &p); // Only reset the dirty flag if all clients got the message. if (iClient == NETWORK_TOCLIENTS) pVariable->SetDirty(false); } pszClassName = pRegistration->m_pszParentClass; } while (pszClassName); } }
void GetMACAddresses(unsigned char*& paiAddresses, size_t& iAddresses) { TUnimplemented(); }