diff --git a/.gitignore b/.gitignore index cc6231fe..3c09da37 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,14 @@ MechoSoma/Debug /MechoSoma/gameDbg.exe /MechoSoma/game.exe /MechoSoma/mechosoma.map + +# IDE +.idea + +# Cmake +cmake-build-debug + +# Third party +MechoSoma/ThirdParty/3dsftk3 +MechoSoma/ThirdParty/libjpeg-turbo + diff --git a/MechoSoma/CMakeLists.txt b/MechoSoma/CMakeLists.txt new file mode 100644 index 00000000..dedab40e --- /dev/null +++ b/MechoSoma/CMakeLists.txt @@ -0,0 +1,551 @@ +cmake_minimum_required(VERSION 3.12) + +project(MOONSHINE_RUNNERS VERSION 1.0.0 LANGUAGES CXX) + +set(GAME_SOURCES + # FX + FX/Hermit.h + FX/XTList.h + FX/fxlabApplication.h + FX/fxlabBodyInterface.cpp + FX/fxlabBodyInterface.h + FX/fxlabClientEffect.cpp + FX/fxlabClientEffect.h + FX/fxlabClientGeneral.cpp + FX/fxlabClientGeneral.h + FX/fxlabClientLauncher.cpp + FX/fxlabClientLauncher.h + FX/fxlabClientLightning.cpp + FX/fxlabClientLightning.h + FX/fxlabClientModel.cpp + FX/fxlabClientModel.h + FX/fxlabClientSound.cpp + FX/fxlabClientSound.h + FX/fxlabClientStuff.cpp + FX/fxlabClientStuff.h + FX/fxlabGeneral.cpp + FX/fxlabGeneral.h + FX/fxlabID.h + FX/fxlabInterface.cpp + FX/fxlabInterface.h + FX/fxlabKey.cpp + FX/fxlabKey.h + FX/fxlabResource.cpp + FX/fxlabResource.h + FX/fxlabServerArcane.cpp + FX/fxlabServerArcane.h + FX/fxlabServerGeneral.cpp + FX/fxlabServerGeneral.h + FX/fxlabServerStuff.cpp + FX/fxlabServerStuff.h + FX/fxlabSprite.cpp + FX/fxlabSprite.h + # RUNTIME + RUNTIME/ArcaneDefine.h + RUNTIME/Chtree.cpp + RUNTIME/Chtree.h + RUNTIME/KEYS.CPP + RUNTIME/KEYS.H + RUNTIME/LocalVersion.cpp + RUNTIME/LocalVersion.h + RUNTIME/Scripts + RUNTIME/SpriteDispatcher.cpp + RUNTIME/SpriteDispatcher.h + RUNTIME/TGA.H + RUNTIME/TrackDispatcher.cpp + RUNTIME/TrackDispatcher.h + RUNTIME/TrackRecorder.cpp + RUNTIME/TrackRecorder.h + RUNTIME/ai_arcane.h + RUNTIME/ai_arcane_prm.h + RUNTIME/arcane.cpp + RUNTIME/arcane.h + RUNTIME/arcane_menu.cpp + RUNTIME/arcane_menu.h + RUNTIME/arcane_menu_d3d.cpp + RUNTIME/arcane_menu_d3d.h + RUNTIME/cdcheck.h + RUNTIME/ctl_point.cpp + RUNTIME/ctl_point.h + RUNTIME/demo_dispatcher.cpp + RUNTIME/demo_dispatcher.h + RUNTIME/fcontainer.cpp + RUNTIME/fcontainer.h + RUNTIME/intro.cpp + RUNTIME/intro.h + RUNTIME/intro_movie.cpp + RUNTIME/intro_movie.h + RUNTIME/intro_movie_id.h + RUNTIME/mch_common.h + RUNTIME/mch_list.h + RUNTIME/mch_rto.H + RUNTIME/mechosoma.cpp + RUNTIME/mechosoma.h + RUNTIME/og_buffer.cpp + RUNTIME/online_game.cpp + RUNTIME/online_game.h + RUNTIME/parts_pool.cpp + RUNTIME/parts_pool.h + RUNTIME/psi_model.h + RUNTIME/race.cpp + RUNTIME/race.h + RUNTIME/resource.cpp + RUNTIME/setup.cpp + RUNTIME/tga.cpp + RUNTIME/timer.cpp + RUNTIME/track.cpp + RUNTIME/track.h + RUNTIME/wininet_api_port.cpp + RUNTIME/wininet_api.h + RUNTIME/xINI.cpp + RUNTIME/xINI_File.cpp + RUNTIME/xINI_File.h + # IVisGeneric + IVisGeneric/IVisGeneric.h + IVisGeneric/M3d_id.h + IVisGeneric/UMATH.H + IVisGeneric/Unknown.h + IVisGeneric/VisGenericDefine.h + IVisGeneric/World_id.h + # Sound + Sound/MpegSound_port.cpp + Sound/sound.cpp + Sound/sound_api.cpp + # Terra + Terra/JPEG_FM.cpp + Terra/LAND.CPP + Terra/RENDER.H + Terra/VMAP.CPP + Terra/VMAP.H + Terra/ch_points.cpp + Terra/ch_points.h + Terra/land.h + Terra/non_rotate_scan_min_full.cpp + Terra/sur_scr.cpp + Terra/sur_scr.h + # VisGeneric + VisGeneric/AnimChannelNode.cpp + VisGeneric/AnimChannelNode.h + VisGeneric/Base.h + VisGeneric/BaseClass.h + VisGeneric/BaseDefine.h + VisGeneric/BaseLight.h + VisGeneric/BaseObject.cpp + VisGeneric/BaseObject.h + VisGeneric/BasePolyGrid.cpp + VisGeneric/BasePolyGrid.h + VisGeneric/BaseReflection.cpp + VisGeneric/BaseReflection.h + VisGeneric/BaseTrail.h + VisGeneric/BoundingBox.h + VisGeneric/Camera.cpp + VisGeneric/Camera.h + VisGeneric/DefineWSC.h + VisGeneric/Dispatcher.cpp + VisGeneric/Dispatcher.h + VisGeneric/DrawPolygonShade.h + VisGeneric/Dummy.cpp + VisGeneric/Dummy.h + VisGeneric/File3ds.cpp + VisGeneric/File3ds.h + VisGeneric/Frame.cpp + VisGeneric/Frame.h + VisGeneric/GameClient.cpp + VisGeneric/GameClient.h + VisGeneric/HashStringGroup.h + VisGeneric/IncTerra.h + VisGeneric/Levin.cpp + VisGeneric/Levin.h + VisGeneric/M3d_effects.h + VisGeneric/Material.cpp + VisGeneric/Material.h + VisGeneric/Math3d.cpp + VisGeneric/Math3d.h + VisGeneric/Maths.cpp + VisGeneric/Maths.h + VisGeneric/Mesh3ds.cpp + VisGeneric/Mesh3ds.h + VisGeneric/Object.cpp + VisGeneric/Object.h + VisGeneric/Object3d.cpp + VisGeneric/Object3d.h + VisGeneric/PlayWSC.cpp + VisGeneric/PlayWSC.h + VisGeneric/PolyGrid.cpp + VisGeneric/PolyGrid.h + VisGeneric/PolyMgr.cpp + VisGeneric/PolyMgr.h + VisGeneric/PolyMgrD3D.cpp + VisGeneric/PolyMgrDraw.cpp + VisGeneric/PolyMgrTex.cpp + VisGeneric/RenderDevice.cpp + VisGeneric/RenderDevice.h + VisGeneric/Scene.cpp + VisGeneric/Scene.h + VisGeneric/SurmapClient.cpp + VisGeneric/SurmapClient.h + VisGeneric/TERRA.H + VisGeneric/TexMgr.cpp + VisGeneric/TexMgr.h + VisGeneric/TgaServ.cpp + VisGeneric/TgaServ.h + VisGeneric/TileMap.cpp + VisGeneric/TileMap.h + VisGeneric/TileWater.cpp + VisGeneric/TileWater.h + VisGeneric/UnkLibrary.h + VisGeneric/Unknown.cpp + VisGeneric/VisGeneric.cpp + VisGeneric/VisGeneric.dsp + VisGeneric/VisGeneric.h + VisGeneric/VisGeneric.vcproj + VisGeneric/WinVideo_port.cpp + VisGeneric/WinVideo.h + VisGeneric/XGR.h + VisGeneric/drawPolygonShade.cpp + VisGeneric/vgBaseObject.cpp + VisGeneric/vgCamera.cpp + VisGeneric/vgGraph.cpp + VisGeneric/vgObject.cpp + VisGeneric/vgOmni.cpp + VisGeneric/vgUnknown.cpp + VisGeneric/vgWorld.cpp + VisGeneric/xgr.cpp + # Graph3d + VisGeneric/Graph3d/Graph3d_Direct3d.cpp + VisGeneric/Graph3d/Graph3d_Direct3d.h + VisGeneric/Graph3d/IGraph3d.cpp + VisGeneric/Graph3d/IGraph3d.h + # Md3d + VisGeneric/md3d/d3dSprites.cpp + # PluginMAX + VisGeneric/PluginMAX/src/AnimationMaterial.cpp + VisGeneric/PluginMAX/src/AnimationMesh.cpp + VisGeneric/PluginMAX/src/ChannelAnimation.cpp + VisGeneric/PluginMAX/src/ChannelMapping.cpp + VisGeneric/PluginMAX/src/DefMeshFile.cpp + VisGeneric/PluginMAX/src/HelperObject.cpp + VisGeneric/PluginMAX/src/LodObject.cpp + VisGeneric/PluginMAX/src/MaterialObject.cpp + VisGeneric/PluginMAX/src/MeshFile.cpp + VisGeneric/PluginMAX/src/NodeObject.cpp + VisGeneric/PluginMAX/src/ObjectMesh.cpp + VisGeneric/PluginMAX/src/SceneMesh.cpp + VisGeneric/PluginMAX/src/StreamBuffer.cpp + VisGeneric/PluginMAX/src/StreamBuffer.h + # XMath + XMath/XMath.cpp + XMath/xmath.h + # XTool + XTool/filesystem.cpp + XTool/filesystem.h + XTool/port.cpp + XTool/port.h + XTool/xtool.h + XTool/inzip.cpp + XTool/outzip.cpp + XTool/treezip.cpp + XTool/zip_headers.h + XTool/zip_resource.cpp + XTool/xstream.cpp + XTool/xbcnvin.cpp + XTool/xbcnvout.cpp + XTool/xbcore.cpp + XTool/xbsearch.cpp + XTool/xconsole.cpp + XTool/xkey.cpp + XTool/xgraph.cpp + XTool/xgraph.h + XTool/xerrhand.cpp + XTool/xrecorder.cpp + XTool/xutil.cpp + XTool/xsound.cpp + # Xreal + Xreal/AnimalArcansPrm.h + Xreal/AnimalsPrm.h + Xreal/AnimatedBody.h + Xreal/ArcaneStatistics.h + Xreal/ArcansOfMechos.cpp + Xreal/ArcansPrm.h + Xreal/Archimed.cpp + Xreal/Ball.cpp + Xreal/Ball.h + Xreal/BaseObject.h + Xreal/Body.cpp + Xreal/Body.h + Xreal/BodyDispatcher.cpp + Xreal/BodyDispatcher.h + Xreal/BodyFactory.cpp + Xreal/BodyFactory.h + Xreal/BodyFeatureHT.h + Xreal/BonusMan.cpp + Xreal/BonusMan.h + Xreal/Brevno.cpp + Xreal/Brevno.h + Xreal/Bubble.cpp + Xreal/Bubble.h + Xreal/Butterfly.cpp + Xreal/Butterfly.h + Xreal/CameraClipping.cpp + Xreal/CameraDispatcher.cpp + Xreal/CameraDispatcher.h + Xreal/CameraPrm.h + Xreal/Cannon.cpp + Xreal/Cannon.h + Xreal/Clown.cpp + Xreal/Clown.h + Xreal/CollisionHandler.cpp + Xreal/CollisionHandler.hpp + Xreal/Contact.cpp + Xreal/Contact.h + Xreal/ControlledObject.cpp + Xreal/ControlledObject.h + Xreal/CrawlingObject.cpp + Xreal/CrawlingObject.h + Xreal/Crystal.cpp + Xreal/Crystal.h + Xreal/CustomFieldSources.cpp + Xreal/CustomFieldSources.h + Xreal/CycledMath.h + Xreal/Debris.cpp + Xreal/Debris.h + Xreal/DebugPrm.h + Xreal/Dog.h + Xreal/Dragon.cpp + Xreal/Dragon.h + Xreal/Dynamics.cpp + Xreal/EvilEye.cpp + Xreal/EvilEye.h + Xreal/FieldGrid.cpp + Xreal/FieldGrid.h + Xreal/FieldSource.cpp + Xreal/FieldSource.h + Xreal/FirePoint.cpp + Xreal/FirePoint.h + Xreal/FixedPathBody.cpp + Xreal/FixedPathBody.h + Xreal/FlyingObject.cpp + Xreal/FlyingObject.h + Xreal/Forest_world.cpp + Xreal/Frog.cpp + Xreal/Frog.h + Xreal/Grid2D.h + Xreal/GrowingBody.cpp + Xreal/GrowingBody.h + Xreal/Handle.h + Xreal/HydrophobicObject.cpp + Xreal/HydrophobicObject.h + Xreal/Joystick + Xreal/LCP_ContactSolver.cpp + Xreal/LCP_ContactSolver.h + Xreal/LCP_Solver.cpp + Xreal/LCP_Solver.h + Xreal/LCP_frictional.cpp + Xreal/Line2D.h + Xreal/LittleSpider.cpp + Xreal/LittleSpider.h + Xreal/Mechos.cpp + Xreal/Mechos.h + Xreal/MechosEffects.cpp + Xreal/MechosForSale.cpp + Xreal/MechosForSale.h + Xreal/MechosPrm.h + Xreal/MemoryHeap.cpp + Xreal/MemoryHeap.h + Xreal/Meteorite.cpp + Xreal/Meteorite.h + Xreal/Moutain_world.cpp + Xreal/MultiBodyCollision.cpp + Xreal/MultibodyContact.h + Xreal/OwnerProtection.h + Xreal/Params.cpp + Xreal/Params.h + Xreal/Part.cpp + Xreal/Part.h + Xreal/Penguin.h + Xreal/PersonageDifferetiationPrm.h + Xreal/Pig.cpp + Xreal/Pig.h + Xreal/PointControlledObject.cpp + Xreal/PointControlledObject.h + Xreal/Polyhedron.cpp + Xreal/Polyhedron.h + Xreal/PolyhedronClip.cpp + Xreal/PolyhedronLibrary.cpp + Xreal/PolyhedronLibrary.h + Xreal/QHull + Xreal/QuatMath.h + Xreal/ResourceDispatcher.cpp + Xreal/ResourceDispatcher.h + Xreal/RungeKutta4.h + Xreal/SST_Reader.h + Xreal/Shark.h + Xreal/Ship.cpp + Xreal/Ship.h + Xreal/SimpleClip.cpp + Xreal/SimpleClip.h + Xreal/SimpleTrack.h + Xreal/SmartMissile.cpp + Xreal/SmartMissile.h + Xreal/SmartStone.cpp + Xreal/SmartStone.h + Xreal/Spider.cpp + Xreal/Spider.h + Xreal/StaticBonus.cpp + Xreal/StaticBonus.h + Xreal/StatisticalAnalizator.h + Xreal/StdAfx.cpp + Xreal/StdAfx.h + Xreal/Stone.cpp + Xreal/Stone.h + Xreal/Suicide.cpp + Xreal/Suicide.h + Xreal/SynchroTimer.h + Xreal/Timers.h + Xreal/TitaniumBall.cpp + Xreal/TitaniumBall.h + Xreal/TnT + Xreal/Tomato.cpp + Xreal/Tomato.h + Xreal/TrackIterator.cpp + Xreal/TrackIterator.h + Xreal/TrackSpline.cpp + Xreal/TrackSpline.h + Xreal/VectorOperations.inl + Xreal/VectorOperationsAligned.inl + Xreal/Vitamina.cpp + Xreal/Vitamina.hpp + Xreal/Water_world.cpp + Xreal/Whale.cpp + Xreal/Whale.h + Xreal/WorldDispatcher.cpp + Xreal/Worm.cpp + Xreal/Worm.h + Xreal/Xreal.cpp + Xreal/Xreal.h + Xreal/XrealWorlds.h + Xreal/Xreal_utl.cpp + Xreal/Xreal_utl.h + Xreal/fcm.inl + Xreal/gen_animalarcans.cpp + Xreal/gen_animals.cpp + Xreal/gen_arcans.cpp + Xreal/gen_camera.cpp + Xreal/gen_debug.cpp + Xreal/gen_game.cpp + Xreal/gen_game.h + Xreal/gen_mechos.cpp + Xreal/gen_personagedifferntiation.cpp + Xreal/gen_xreal.cpp + Xreal/gen_xreal.h + Xreal/pt.cpp + # Xreal/Joystick + Xreal/Joystick/XJoystick_port.cpp + # iScreen + iScreen/SCRIPTS/SCR_DEFS.H + iScreen/ACS_CORE.CPP + iScreen/ACS_EXT.CPP + iScreen/HFONT.CPP + iScreen/HFONT.H + iScreen/I-World.cpp + iScreen/acs_quant.cpp + iScreen/hbm.cpp + iScreen/hbm.h + iScreen/iScript.cpp + iScreen/iText.cpp + iScreen/savegame.cpp + # ThirdParty + ThirdParty/aci_Parser/aci_parser.cpp +) +set(LIBRARY_NAME game) + +include_directories(FX) +include_directories(IVisGeneric) +include_directories(Sound) +include_directories(Terra) +include_directories(RUNTIME) +include_directories(RUNTIME/SCRIPTS) +include_directories(VisGeneric) +include_directories(VisGeneric/md3d) +include_directories(VisGeneric/Graph3d) +include_directories(VisGeneric/Scripts) +include_directories(VisGeneric/UTIL) +include_directories(VisGeneric/PluginMAX/inc) +include_directories(VisGeneric/PluginMAX/src) +include_directories(ThirdParty/aci_Parser) +include_directories(XMath) +include_directories(XTool) +include_directories(Xreal) +include_directories(Xreal/Joystick) +include_directories(Xreal/TnT) +include_directories(iScreen) +include_directories(iScreen/SCRIPTS) + +add_subdirectory(ThirdParty/3dsftk3) +add_subdirectory(ThirdParty/iniparser) + +include_directories(ThirdParty/libjpeg-turbo/include) +link_directories(ThirdParty/libjpeg-turbo/lib) + +add_definitions(-D_MECHOSOMA_ -D_USE_TILEMAP_ -D_USE_TERRA_ -DNASSERT -D_FINAL_VERSION_ -D_MPPLUS_SOUNDTRACK_) + +add_library(${LIBRARY_NAME} ${GAME_SOURCES}) +target_link_libraries(${LIBRARY_NAME} PUBLIC 3dsftk3 iniparser jpeg) + +set_target_properties( + ${LIBRARY_NAME} + PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + +if(APPLE) +set(APPLICATION_SOURCES + macOS/GameViewController.mm + macOS/GameViewController.h + macOS/KeyboardCodeConversion.mm + macOS/KeyboardCodeConversion.h + macOS/Matrix.cpp + macOS/Matrix.h + macOS/Md3d.cpp + macOS/Ref.h + macOS/Renderer.mm + macOS/Renderer.h + macOS/RendererInterface.h + macOS/RenderState.h + macOS/ShaderCommon.h + macOS/TextureManager.mm + macOS/TextureManager.h + macOS/TextureManagerInterface.h + macOS/VertexType.h + macOS/main.mm +) +set(APPLICATION_NAME moonshine-runners) + +set(METAL_LIBRARY_AIR ${CMAKE_BINARY_DIR}/default.air) +set(METAL_LIBRARY ${CMAKE_BINARY_DIR}/default.metallib) + +add_custom_command(OUTPUT ${METAL_LIBRARY_AIR} + COMMAND xcrun -sdk macosx metal -c ${CMAKE_SOURCE_DIR}/macOS/Library.metal -o ${METAL_LIBRARY_AIR} +) + +add_custom_command(OUTPUT ${METAL_LIBRARY} + COMMAND xcrun -sdk macosx metallib ${METAL_LIBRARY_AIR} -o ${METAL_LIBRARY} + DEPENDS ${METAL_LIBRARY_AIR} +) + +add_executable(${APPLICATION_NAME} MACOSX_BUNDLE ${METAL_LIBRARY} ${APPLICATION_SOURCES}) +target_link_libraries(${APPLICATION_NAME} PRIVATE stdc++ "-framework CoreFoundation" "-framework Cocoa" "-framework Metal" "-framework MetalKit" "-framework Accelerate" objc ${LIBRARY_NAME}) + +# target_sources(${APPLICATION_NAME} PRIVATE ${METAL_LIBRARY}) +set_source_files_properties(${METAL_LIBRARY} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) + +set_target_properties( + ${APPLICATION_NAME} + PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) +endif(APPLE) diff --git a/MechoSoma/FX/Hermit.h b/MechoSoma/FX/Hermit.h index 45255c10..d828b83c 100644 --- a/MechoSoma/FX/Hermit.h +++ b/MechoSoma/FX/Hermit.h @@ -4,11 +4,11 @@ // (C) 1999 K-D Lab // Author: Alexandre Kotliar //////////////////////////////////////////////////////////////////////////////// -#include +#include template class HermitIterator { - typedef stlp_std::_List_iterator> iterator; + typedef typename list::iterator iterator; float t; Vector P[4]; list* points; diff --git a/MechoSoma/FX/fxlabBodyInterface.cpp b/MechoSoma/FX/fxlabBodyInterface.cpp index fce57fae..2247799d 100644 --- a/MechoSoma/FX/fxlabBodyInterface.cpp +++ b/MechoSoma/FX/fxlabBodyInterface.cpp @@ -1,9 +1,11 @@ #include "StdAfx.h" #include "aci_parser.h" +#ifdef _WIN32 #include "win32f.h" +#endif -#include "handle.h" +#include "Handle.h" #include "BodyDispatcher.h" #include "Mechos.h" #include "OwnerProtection.h" @@ -13,14 +15,14 @@ #include "TileMap.h" #include "TileWater.h" #include "IVisGeneric.h" -#include "terra.h" +#include "TERRA.H" #include "race.h" #include "sound.h" #include "sur_scr.h" #include "SST_Reader.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "fxlabID.h" #include "fxlabGeneral.h" @@ -137,7 +139,8 @@ void fxlabSleepyMortar::quant() BonusMeteorite::quant(); float t = sin(M_PI*(float)(color_time()) / 1000.0f); - xrealIVG -> SetObjectColor(geometry,NULL,&sColor4f(fabs(t),0,0,1.0f)); + sColor4f c1(fabs(t),0,0,1.0f); + xrealIVG -> SetObjectColor(geometry,NULL,&c1); }; //---------------------------- diff --git a/MechoSoma/FX/fxlabBodyInterface.h b/MechoSoma/FX/fxlabBodyInterface.h index 423c3a9c..0bab9c2a 100644 --- a/MechoSoma/FX/fxlabBodyInterface.h +++ b/MechoSoma/FX/fxlabBodyInterface.h @@ -1,7 +1,7 @@ #include "Meteorite.h" template -void fxlabCreateBolide(int model,int noise,Vect3f& pos,Vect3f& vel,float damage,int client_key_type,ArcaneStatisticsInfo* stat,fxlabProtectionType* protect,ObjectType* stuff) +void fxlabCreateBolide(int model,int noise,const Vect3f& pos,const Vect3f& vel,float damage,int client_key_type,ArcaneStatisticsInfo* stat,fxlabProtectionType* protect,ObjectType* stuff) { Body* p; OwnerProtection* op; diff --git a/MechoSoma/FX/fxlabClientEffect.cpp b/MechoSoma/FX/fxlabClientEffect.cpp index 48d2a02b..18e7128f 100644 --- a/MechoSoma/FX/fxlabClientEffect.cpp +++ b/MechoSoma/FX/fxlabClientEffect.cpp @@ -1,9 +1,9 @@ #include "StdAfx.h" #include "aci_parser.h" #include "IVisGeneric.h" -#include "m3d_effects.h" -#include "polymgr.h" -#include "terra.h" +#include "M3d_effects.h" +#include "PolyMgr.h" +#include "TERRA.H" #include "sound.h" #include "race.h" @@ -28,7 +28,7 @@ void fxlabSwarmDomain::Load(fxlabResourceObject* key,float time) key->GetKey(buffer,time); - switch(round(buffer[FXLAB_SWARM_DOMAIN_TYPE])){ + switch(int(round(buffer[FXLAB_SWARM_DOMAIN_TYPE]))){ case FXLAB_SWARM_DOMAIN_POINT: Point(buffer[FXLAB_SWARM_DOMAIN_DATA_X],buffer[FXLAB_SWARM_DOMAIN_DATA_Y],buffer[FXLAB_SWARM_DOMAIN_DATA_Z]); break; @@ -283,9 +283,9 @@ void fxlabParticleFear::KeyUpdate(void) ImageNoise = round(KeyData[FXLAB_FEAR_DATA_IMAGE_NOISE]); }; -#include "Visgeneric.h" -#include "camera.h" -#include "scene.h" +#include "VisGeneric.h" +#include "Camera.h" +#include "Scene.h" void fxlabParticleFear::Show(void) { @@ -535,8 +535,8 @@ void fxlabCrazyTwister::ConvertPosition(void) else VsS = Vect3f(ProcessMinX,ProcessMinX,ProcessMaxZ - ProcessMinZ); - VsL.x = XCYCL(round(Position.x - VsS.x)); - VsL.y = YCYCL(round(Position.y - VsS.y)); + VsL.x = XCYCL(int(round(Position.x - VsS.x))); + VsL.y = YCYCL(int(round(Position.y - VsS.y))); VsL.z = Position.z - VsS.z; VsS *= 2.0f; @@ -1034,7 +1034,7 @@ void fxlabFearStream::CoreProcess(void) DeleteParticle(p); }else{ v = p->Velocity; - if((round(p->Position.z) + z) <= ZV(XCYCL(round(p->Position.x) + x),YCYCL(round(p->Position.y) + y))){ + if((round(p->Position.z) + z) <= ZV(XCYCL(int(round(p->Position.x)) + x),YCYCL(int(round(p->Position.y)) + y))){ if(v.z > 0) v.z *= ReflectionImpulse; else diff --git a/MechoSoma/FX/fxlabClientGeneral.cpp b/MechoSoma/FX/fxlabClientGeneral.cpp index 9736cf33..dece17dc 100644 --- a/MechoSoma/FX/fxlabClientGeneral.cpp +++ b/MechoSoma/FX/fxlabClientGeneral.cpp @@ -1,7 +1,7 @@ #include "StdAfx.h" #include "aci_parser.h" -#include "terra.h" +#include "TERRA.H" #include "fxlabID.h" #include "fxlabGeneral.h" @@ -10,7 +10,7 @@ #include "fxlabApplication.h" #include "XTList.h" #include "fxlabClientGeneral.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" void fxlabClientEvolutionType::Start(void) { @@ -240,8 +240,8 @@ int fxlabParticleCore::GetAlive(void) void fxlabParticleCore::ConvertPosition(void) { VsS = Vect3f(ProcessMaxX - ProcessMinX,ProcessMaxY - ProcessMinY,ProcessMaxZ - ProcessMinZ); - VsL.x = XCYCL(round(Position.x + ProcessMinX)); - VsL.y = YCYCL(round(Position.y + ProcessMinY)); + VsL.x = XCYCL(int(round(Position.x + ProcessMinX))); + VsL.y = YCYCL(int(round(Position.y + ProcessMinY))); VsL.z = Position.z + ProcessMinZ; }; @@ -257,9 +257,9 @@ void fxlabParticleCore::KeyCheck(void) ErrH.Abort("Bad Key of fxlabParticleCore"); }; -#include "Visgeneric.h" -#include "camera.h" -#include "scene.h" +#include "VisGeneric.h" +#include "Camera.h" +#include "Scene.h" void fxlabParticleCore::CheckVisibility(void) { diff --git a/MechoSoma/FX/fxlabClientLauncher.cpp b/MechoSoma/FX/fxlabClientLauncher.cpp index 4c3f657a..d5dae326 100644 --- a/MechoSoma/FX/fxlabClientLauncher.cpp +++ b/MechoSoma/FX/fxlabClientLauncher.cpp @@ -1,7 +1,7 @@ #include "StdAfx.h" #include "aci_parser.h" -#include "terra.h" +#include "TERRA.H" #include "BodyDispatcher.h" #include "Mechos.h" @@ -670,8 +670,8 @@ void fxlabClientSuicideLink::CalcVelocity(void) Velocity = Core->Yglobal(); Velocity = -Velocity; d = 30.0f; - Position.x = XCYCL(round(Position.x + Velocity.x * d)); - Position.y = YCYCL(round(Position.y + Velocity.y * d)); + Position.x = XCYCL(int(round(Position.x + Velocity.x * d))); + Position.y = YCYCL(int(round(Position.y + Velocity.y * d))); Position.z = Position.z + Velocity.z * d; Velocity *= FXLAB_CLIENT_SUICIDE_SPEED; }; @@ -1159,7 +1159,7 @@ void fxlabClientVoodooMasterLink::Update(void) a = -MechosOwner->yaw() + M_PI * 1.5f; cycle(a,M_PI * 2.0f); - PsiVelocity += getDist(a,LastPosition.z,M_PI * 2.0f) * FXLAB_CLIENT_VOODOO_MASTER_PSI_MASS; + PsiVelocity += getDist_f(a,LastPosition.z,M_PI * 2.0f) * FXLAB_CLIENT_VOODOO_MASTER_PSI_MASS; LastPosition.z += PsiVelocity * DeltaTime; cycle(LastPosition.z,M_PI * 2.0f); PsiVelocity *= FXLAB_CLIENT_VOODOO_MASTER_PSI_DAMP; diff --git a/MechoSoma/FX/fxlabClientLightning.cpp b/MechoSoma/FX/fxlabClientLightning.cpp index a76e211b..abb1ffa9 100644 --- a/MechoSoma/FX/fxlabClientLightning.cpp +++ b/MechoSoma/FX/fxlabClientLightning.cpp @@ -1,7 +1,7 @@ #include "StdAfx.h" #include "aci_parser.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "Levin.h" #include "fxlabID.h" diff --git a/MechoSoma/FX/fxlabClientModel.cpp b/MechoSoma/FX/fxlabClientModel.cpp index abb82d7b..9e8ff5d8 100644 --- a/MechoSoma/FX/fxlabClientModel.cpp +++ b/MechoSoma/FX/fxlabClientModel.cpp @@ -6,7 +6,7 @@ #include "IVisGeneric.h" #include "sound.h" -#include "terra.h" +#include "TERRA.H" #include "fxlabID.h" #include "fxlabGeneral.h" @@ -169,7 +169,13 @@ void fxlabControlOmni::Start(void) { fxlabClientKeyObjectType::Start(); cInterfaceVisGeneric *IVisGeneric=CreateIVisGeneric(); - OmniPoint=(cOmni*)IVisGeneric->CreateOmni(&Vect3f(Position.x,Position.y,Position.z),KeyData[FXLAB_CONTROL_OMNI_DATA_RADIUS],&sColor4f(KeyData[FXLAB_CONTROL_OMNI_DATA_RED],KeyData[FXLAB_CONTROL_OMNI_DATA_GREEN],KeyData[FXLAB_CONTROL_OMNI_DATA_BLUE])); + Vect3f v1(Position.x,Position.y,Position.z); + sColor4f c1( + KeyData[FXLAB_CONTROL_OMNI_DATA_RED], + KeyData[FXLAB_CONTROL_OMNI_DATA_GREEN], + KeyData[FXLAB_CONTROL_OMNI_DATA_BLUE] + ); + OmniPoint=(cOmni*)IVisGeneric->CreateOmni(&v1,KeyData[FXLAB_CONTROL_OMNI_DATA_RADIUS],&c1); IVisGeneric->Release(); }; @@ -185,9 +191,15 @@ void fxlabControlOmni::Quant(void) { fxlabClientKeyObjectType::Quant(); cInterfaceVisGeneric *IVisGeneric=CreateIVisGeneric(); - IVisGeneric->SetOmniPosition((cUnknownClass*)OmniPoint,&Vect3f(Position.x,Position.y,Position.z)); + Vect3f v1(Position.x,Position.y,Position.z); + IVisGeneric->SetOmniPosition((cUnknownClass*)OmniPoint,&v1); IVisGeneric->SetOmniSize((cUnknownClass*)OmniPoint,KeyData[FXLAB_CONTROL_OMNI_DATA_RADIUS]); - IVisGeneric->SetOmniColor((cUnknownClass*)OmniPoint,&sColor4f(KeyData[FXLAB_CONTROL_OMNI_DATA_RED],KeyData[FXLAB_CONTROL_OMNI_DATA_GREEN],KeyData[FXLAB_CONTROL_OMNI_DATA_BLUE])); + sColor4f c1( + KeyData[FXLAB_CONTROL_OMNI_DATA_RED], + KeyData[FXLAB_CONTROL_OMNI_DATA_GREEN], + KeyData[FXLAB_CONTROL_OMNI_DATA_BLUE] + ); + IVisGeneric->SetOmniColor((cUnknownClass*)OmniPoint,&c1); IVisGeneric->Release(); }; @@ -307,7 +319,7 @@ void fxlabLashModel::Quant(void) { fxlabAnimationModel::Quant(); - if((!fxlabGetWorldReflectionEnable()) && Position.z < vMap->LevelH2O && (GetAt(XCYCL(round(Position.x)),YCYCL(round(Position.y))) & At_WATER)){ + if((!fxlabGetWorldReflectionEnable()) && Position.z < vMap->LevelH2O && (GetAt(XCYCL(int(round(Position.x))),YCYCL(int(round(Position.y)))) & At_WATER)){ DeltaPhase = 0.95f; SetAlive(0); }; @@ -597,8 +609,13 @@ void fxlabPetardModel::Start(void) t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_TAIL); t->SetStartTime(fxlabClientD->GetTime()); - t->SetPosition(CYCLE(Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS])); - t->SetVelocity(-NormVelocity); + + Vect3f v1 = Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS]; + t->SetPosition(CYCLE(v1)); + + Vect3f v2 = -NormVelocity; + t->SetVelocity(v2); + t->SetKeyID(FXLAB_ID_KEY_PETARD_TAIL); t->SetProcessInterface(&TailPoint); t->Start(); @@ -615,7 +632,10 @@ void fxlabPetardModel::Quant(void) { fxlabBulletModel::Quant(); if(TailPoint.Process) - TailPoint.Process->SetPosition(CYCLE(Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS])); + { + Vect3f v1 = Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS]; + TailPoint.Process->SetPosition(CYCLE(v1)); + } }; //-------------------------------- @@ -628,8 +648,13 @@ void fxlabSnowBulletModel::Start(void) t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_TAIL); t->SetStartTime(fxlabClientD->GetTime()); - t->SetPosition(CYCLE(Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS])); - t->SetVelocity(-NormVelocity); + + Vect3f v1 = Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS]; + t->SetPosition(CYCLE(v1)); + + Vect3f v2 = -NormVelocity; + t->SetVelocity(v2); + t->SetKeyID(FXLAB_ID_KEY_SNOW_BULLET); t->SetProcessInterface(&TailPoint); t->Start(); @@ -646,7 +671,10 @@ void fxlabSnowBulletModel::Quant(void) { fxlabBulletModel::Quant(); if(TailPoint.Process) - TailPoint.Process->SetPosition(CYCLE(Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS])); + { + Vect3f v1 = Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS]; + TailPoint.Process->SetPosition(CYCLE(v1)); + } }; //-------------------------------- @@ -659,8 +687,13 @@ void fxlabFireBulletModel::Start(void) t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_TAIL); t->SetStartTime(fxlabClientD->GetTime()); - t->SetPosition(CYCLE(Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS])); - t->SetVelocity(-NormVelocity); + + Vect3f v1 = Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS]; + t->SetPosition(CYCLE(v1)); + + Vect3f v2 = -NormVelocity; + t->SetVelocity(v2); + t->SetKeyID(FXLAB_ID_KEY_FIRE_BULLET); t->SetProcessInterface(&TailPoint); t->Start(); @@ -677,7 +710,10 @@ void fxlabFireBulletModel::Quant(void) { fxlabBulletModel::Quant(); if(TailPoint.Process) - TailPoint.Process->SetPosition(CYCLE(Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS])); + { + Vect3f v1 = Position - NormVelocity * KeyData[FXLAB_CONTROL_MODEL_DATA_RADIUS]; + TailPoint.Process->SetPosition(CYCLE(v1)); + } }; //------------------------------------------------------- diff --git a/MechoSoma/FX/fxlabClientSound.cpp b/MechoSoma/FX/fxlabClientSound.cpp index 1a47d0ff..1d0e32c5 100644 --- a/MechoSoma/FX/fxlabClientSound.cpp +++ b/MechoSoma/FX/fxlabClientSound.cpp @@ -1,6 +1,6 @@ #include "StdAfx.h" #include "aci_parser.h" -#include "terra.h" +#include "TERRA.H" #include "sound.h" #include "fxlabID.h" diff --git a/MechoSoma/FX/fxlabClientStuff.cpp b/MechoSoma/FX/fxlabClientStuff.cpp index 74b2eff7..0de9de82 100644 --- a/MechoSoma/FX/fxlabClientStuff.cpp +++ b/MechoSoma/FX/fxlabClientStuff.cpp @@ -1,9 +1,9 @@ #include "StdAfx.h" #include "aci_parser.h" -#include "win32f.h" +// #include "win32f.h" -#include "handle.h" +#include "Handle.h" #include "BodyDispatcher.h" #include "Mechos.h" #include "OwnerProtection.h" @@ -15,10 +15,10 @@ #include "PolyGrid.h" #include "TileWater.h" #include "IVisGeneric.h" -#include "terra.h" +#include "TERRA.H" #include "race.h" #include "sound.h" -#include "polymgr.h" +#include "PolyMgr.h" #include "CameraDispatcher.h" @@ -26,7 +26,7 @@ #include "sur_scr.h" #include "SST_Reader.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "fxlabID.h" #include "fxlabGeneral.h" @@ -236,11 +236,17 @@ void fxlabCheckPoint::ModelUpdate(void) phase = KeyData[FXLAB_CHECK_POINT_DATA_MOVE_PHASE] + KeyData[FXLAB_CHECK_POINT_DATA_PHASE_DELTA] * sinf(AddPhase); cInterfaceVisGeneric *IVisGeneric=CreateIVisGeneric(); - IVisGeneric->SetObjectPosition((cUnknownClass*)ModelPoint[ModelIndex], - &Vect3f(Position.x + Velocity.x * phase,Position.y + Velocity.y * phase,Position.z + Velocity.z * phase),&AnglePosition); + + Vect3f v1(Position.x + Velocity.x * phase,Position.y + Velocity.y * phase,Position.z + Velocity.z * phase); + IVisGeneric->SetObjectPosition((cUnknownClass*)ModelPoint[ModelIndex],&v1,&AnglePosition); + scale = KeyData[FXLAB_CHECK_POINT_DATA_RADIUS] * Scale / ModelRadius; - IVisGeneric->SetObjectScale((cUnknownClass*)ModelPoint[ModelIndex],&Vect3f(scale,scale,scale)); - IVisGeneric->SetObjectColor((cUnknownClass*)ModelPoint[ModelIndex],&sColor4f(KeyData[FXLAB_CHECK_POINT_DATA_RED],KeyData[FXLAB_CHECK_POINT_DATA_GREEN],KeyData[FXLAB_CHECK_POINT_DATA_BLUE],KeyData[FXLAB_CHECK_POINT_DATA_ALPHA])); + Vect3f v2(scale,scale,scale); + IVisGeneric->SetObjectScale((cUnknownClass*)ModelPoint[ModelIndex],&v2); + + sColor4f c1(KeyData[FXLAB_CHECK_POINT_DATA_RED],KeyData[FXLAB_CHECK_POINT_DATA_GREEN],KeyData[FXLAB_CHECK_POINT_DATA_BLUE],KeyData[FXLAB_CHECK_POINT_DATA_ALPHA]); + IVisGeneric->SetObjectColor((cUnknownClass*)ModelPoint[ModelIndex],&c1); + IVisGeneric->Release(); }; @@ -255,7 +261,7 @@ void fxlabCheckPoint::SetMode(int mode) Mode = mode; }; -void fxlabCheckPoint::SetVelocity(Vect3f& velocity) +void fxlabCheckPoint::SetVelocity(const Vect3f& velocity) { Velocity = velocity; }; @@ -323,9 +329,14 @@ void fxlabCheckPoint::SetCheckPointRacer(int mode,struct mchRacer* p,int init_fl t->SetKeyID(FXLAB_ID_KEY_POLAR_STAR); scale = KeyData[FXLAB_CHECK_POINT_DATA_RADIUS] * Scale / ModelRadius; - t->SetScaleVector(Vect3f(scale,scale,scale)); + Vect3f v1(scale,scale,scale); + t->SetScaleVector(v1); + t->SetAngleVector(AnglePosition); - t->SetColorVector(Vect3f(KeyData[FXLAB_CHECK_POINT_DATA_RED],KeyData[FXLAB_CHECK_POINT_DATA_GREEN],KeyData[FXLAB_CHECK_POINT_DATA_BLUE])); + + Vect3f v2(KeyData[FXLAB_CHECK_POINT_DATA_RED],KeyData[FXLAB_CHECK_POINT_DATA_GREEN],KeyData[FXLAB_CHECK_POINT_DATA_BLUE]); + t->SetColorVector(v2); + t->SetTransparency(KeyData[FXLAB_CHECK_POINT_DATA_ALPHA]); t->SetModel(ModelID[0]); t->SetRacerPoint(p); @@ -371,8 +382,13 @@ void fxlabPolarModel::Start(void) ModelPoint=(cMesh*)IVisGeneric->CreateObject(M3D_KIND(ModelID),M3D_TYPE(ModelID)); IVisGeneric->SetObjectPosition((cUnknownClass*)ModelPoint,&Position,&ModelAngle); IVisGeneric->SetObjectAttribute((cUnknownClass*)ModelPoint,CalcAttribute()); - IVisGeneric->SetObjectScale((cUnknownClass*)ModelPoint,&(ModelScale * KeyData[FXLAB_POLAR_MODEL_DATA_SCALE])); - IVisGeneric->SetObjectColor((cUnknownClass*)ModelPoint,&sColor4f(Color.x,Color.y,Color.z,Alpha*KeyData[FXLAB_POLAR_MODEL_DATA_ALPHA])); + + Vect3f v1(ModelScale * KeyData[FXLAB_POLAR_MODEL_DATA_SCALE]); + IVisGeneric->SetObjectScale((cUnknownClass*)ModelPoint,&v1); + + sColor4f c1(Color.x,Color.y,Color.z,Alpha*KeyData[FXLAB_POLAR_MODEL_DATA_ALPHA]); + IVisGeneric->SetObjectColor((cUnknownClass*)ModelPoint,&c1); + IVisGeneric->Release(); }; @@ -385,21 +401,26 @@ void fxlabPolarModel::Quant(void) v.setSpherical(KeyData[FXLAB_POLAR_MODEL_DATA_PSI] + OffsetAngle,KeyData[FXLAB_POLAR_MODEL_DATA_THETTA],KeyData[FXLAB_POLAR_MODEL_DATA_RADIUS]); v += Center->R(); v.z += Center->radius() * 2.0f; - v.x = XCYCL(round(v.x)); - v.y = YCYCL(round(v.y)); + v.x = XCYCL(int(round(v.x))); + v.y = YCYCL(int(round(v.y))); d.x = getDistX(v.x,StartPosition.x); d.y = getDistY(v.y,StartPosition.y); d.z = v.z - StartPosition.z; Position = StartPosition + d * KeyData[FXLAB_POLAR_MODEL_DATA_PHASE]; - Position.x = XCYCL(round(Position.x)); - Position.y = YCYCL(round(Position.y)); + Position.x = XCYCL(int(round(Position.x))); + Position.y = YCYCL(int(round(Position.y))); }; cInterfaceVisGeneric *IVisGeneric=CreateIVisGeneric(); IVisGeneric->SetObjectPosition((cUnknownClass*)ModelPoint,&Position,&ModelAngle); - IVisGeneric->SetObjectColor((cUnknownClass*)ModelPoint,&sColor4f(Color.x,Color.y,Color.z,Alpha*KeyData[FXLAB_POLAR_MODEL_DATA_ALPHA])); - IVisGeneric->SetObjectScale((cUnknownClass*)ModelPoint,&(ModelScale * KeyData[FXLAB_POLAR_MODEL_DATA_SCALE])); + + sColor4f c1(Color.x,Color.y,Color.z,Alpha*KeyData[FXLAB_POLAR_MODEL_DATA_ALPHA]); + IVisGeneric->SetObjectColor((cUnknownClass*)ModelPoint,&c1); + + Vect3f v1(ModelScale * KeyData[FXLAB_POLAR_MODEL_DATA_SCALE]); + IVisGeneric->SetObjectScale((cUnknownClass*)ModelPoint,&v1); + IVisGeneric->Release(); }; @@ -409,17 +430,17 @@ void fxlabPolarModel::KeyCheck(void) ErrH.Abort("Bad Key of fxPolarModel"); }; -void fxlabPolarModel::SetScaleVector(Vect3f& v) +void fxlabPolarModel::SetScaleVector(const Vect3f& v) { ModelScale = v; }; -void fxlabPolarModel::SetAngleVector(Vect3f& v) +void fxlabPolarModel::SetAngleVector(const Vect3f& v) { ModelAngle = v; }; -void fxlabPolarModel::SetColorVector(Vect3f& v) +void fxlabPolarModel::SetColorVector(const Vect3f& v) { Color = v; }; @@ -877,15 +898,27 @@ void fxlabClientWildClaw::CalcCenter(void) Point[2] *= ScaleFactor; Point[3] *= ScaleFactor; - z = (float)(fxlabGetLevel(XCYCL(round(Position.x + Point[1].x)),YCYCL(round(Position.y + Point[1].y)),Position.z)); + z = (float)(fxlabGetLevel( + XCYCL(int(round(Position.x + Point[1].x))), + YCYCL(int(round(Position.y + Point[1].y))), + Position.z + )); if(z > (Point[1].z + Position.z)) Point[1].z = z - Position.z; - z = (float)(fxlabGetLevel(XCYCL(round(Position.x + Point[2].x)),YCYCL(round(Position.y + Point[2].y)),Position.z)); + z = (float)(fxlabGetLevel( + XCYCL(int(round(Position.x + Point[2].x))), + YCYCL(int(round(Position.y + Point[2].y))), + Position.z + )); if(z > (Point[2].z + Position.z)) Point[2].z = z - Position.z; - z = (float)(fxlabGetLevel(XCYCL(round(Position.x + Point[3].x)),YCYCL(round(Position.y + Point[3].y)),Position.z)); + z = (float)(fxlabGetLevel( + XCYCL(int(round(Position.x + Point[3].x))), + YCYCL(int(round(Position.y + Point[3].y))), + Position.z + )); if(z > (Point[3].z + Position.z)) Point[3].z = z - Position.z; @@ -1499,13 +1532,18 @@ void fxlabClientRevoltSpaceLink::Quant(void) if(!TailPoint.Process){ t = fxlabClientD->CreateObject(TailType); t->SetStartTime(fxlabClientD->GetTime()); - t->SetMatrix(MatXf(Core->Alg(),Core->R())); + + MatXf m1(Core->Alg(),Core->R()); + t->SetMatrix(m1); + t->SetVelocity(Velocity); t->SetKeyID(TailID); t->SetProcessInterface(&TailPoint); t->Start(); }else{ - TailPoint.Process->SetMatrix(MatXf(Core->Alg(),Core->R())); + MatXf m1(Core->Alg(),Core->R()); + TailPoint.Process->SetMatrix(m1); + TailPoint.Process->SetVelocity(Velocity); }; }; @@ -1561,7 +1599,7 @@ void fxlabClientMassShifter::KeyCheck(void) ErrH.Abort("Bad Key in fxlabClientMassShifter"); }; -void fxlabClientMassShifter::Generate(Mat3f& m,Vect3f& v) +void fxlabClientMassShifter::Generate(const Mat3f& m,const Vect3f& v) { fxlabGeneralObjectType* t; @@ -1569,11 +1607,14 @@ void fxlabClientMassShifter::Generate(Mat3f& m,Vect3f& v) t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_MASS_SHIFTER_MODEL); t->SetPosition(v); - t->SetMatrix(MatXf(m,v)); + + MatXf m1(m,v); + t->SetMatrix(m1); + t->Start(); }; -void fxlabClientMassShifterNitro::Generate(Mat3f& m,Vect3f& v) +void fxlabClientMassShifterNitro::Generate(const Mat3f& m,const Vect3f& v) { fxlabGeneralObjectType* t; @@ -1581,11 +1622,14 @@ void fxlabClientMassShifterNitro::Generate(Mat3f& m,Vect3f& v) t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_MASS_SHIFTER_MODEL_NITRO); t->SetPosition(v); - t->SetMatrix(MatXf(m,v)); + + MatXf m1(m,v); + t->SetMatrix(m1); + t->Start(); }; -void fxlabClientMassShifterCharacter::Generate(Mat3f& m,Vect3f& v) +void fxlabClientMassShifterCharacter::Generate(const Mat3f& m,const Vect3f& v) { fxlabGeneralObjectType* t; @@ -1593,11 +1637,14 @@ void fxlabClientMassShifterCharacter::Generate(Mat3f& m,Vect3f& v) t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_MASS_SHIFTER_MODEL_CHARACTER); t->SetPosition(v); - t->SetMatrix(MatXf(m,v)); + + MatXf m1(m,v); + t->SetMatrix(m1); + t->Start(); }; -void fxlabClientMassShifterMovie::Generate(Mat3f& m,Vect3f& v) +void fxlabClientMassShifterMovie::Generate(const Mat3f& m,const Vect3f& v) { fxlabGeneralObjectType* t; @@ -1605,7 +1652,10 @@ void fxlabClientMassShifterMovie::Generate(Mat3f& m,Vect3f& v) t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_MASS_SHIFTER_MODEL_MOVIE); t->SetPosition(v); - t->SetMatrix(MatXf(m,v)); + + MatXf m1(m,v); + t->SetMatrix(m1); + t->Start(); }; @@ -1843,7 +1893,10 @@ void fxlabClientMechosController::Quant(void) t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_SPARK_GENERATOR); t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_MECHOS_BUBBLE); - t->SetPosition(Vect3f(Owner->R())); + + Vect3f v1(Owner->R()); + t->SetPosition(v1); + t->Start(); }; @@ -1852,14 +1905,19 @@ void fxlabClientMechosController::Quant(void) v -= Owner->Yglobal() * Owner->radius(); CYCLE(v); - tx = XCYCL(round(v.x)); - ty = YCYCL(round(v.y)); + tx = XCYCL(int(round(v.x))); + ty = YCYCL(int(round(v.y))); if(GetAt(tx,ty) & At_WATER){ t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_WATER_WAVE_MODEL); t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_MECHOS_WAVE_MODEL); - t->SetPosition(Vect3f(v.x,v.y,vMap->LevelH2O + 3.0f)); - t->SetColorVector(Vect3f(fxlabGetTrackWaveRed(),fxlabGetTrackWaveGreen(),fxlabGetTrackWaveBlue())); + + Vect3f v1(v.x,v.y,vMap->LevelH2O + 3.0f); + t->SetPosition(v1); + + Vect3f v2(fxlabGetTrackWaveRed(),fxlabGetTrackWaveGreen(),fxlabGetTrackWaveBlue()); + t->SetColorVector(v2); + t->SetTransparency(fxlabGetTrackWaveAlpha()); t->Start(); }; @@ -1867,15 +1925,19 @@ void fxlabClientMechosController::Quant(void) v = Owner->part_coords(M3D_LB_WHEEL); v -= Owner->Yglobal() * Owner->radius(); CYCLE(v); - tx = XCYCL(round(v.x)); - ty = YCYCL(round(v.y)); + tx = XCYCL(int(round(v.x))); + ty = YCYCL(int(round(v.y))); if(GetAt(tx,ty) & At_WATER){ t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_WATER_WAVE_MODEL); t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_MECHOS_WAVE_MODEL); - t->SetPosition(Vect3f(v.x,v.y,vMap->LevelH2O + 3.0f)); - t->SetColorVector(Vect3f(fxlabGetTrackWaveRed(),fxlabGetTrackWaveGreen(),fxlabGetTrackWaveBlue())); + + Vect3f v1(v.x,v.y,vMap->LevelH2O + 3.0f); + t->SetPosition(v1); + + Vect3f v2(fxlabGetTrackWaveRed(),fxlabGetTrackWaveGreen(),fxlabGetTrackWaveBlue()); + t->SetColorVector(v2); t->SetTransparency(fxlabGetTrackWaveAlpha()); t->Start(); }; @@ -1894,7 +1956,10 @@ void fxlabClientMechosController::Quant(void) t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_MECHOS_LINK); t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_DAMAGE_WARNING_LINK); - t->SetPosition(Vect3f(Owner->R())); + + Vect3f v1(Owner->R()); + t->SetPosition(v1); + t->SetBody(Owner); t->SetProcessInterface(&DamageWarningPoint); t->Start(); @@ -1917,7 +1982,10 @@ void fxlabClientMechosController::Quant(void) t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_SOUND_SPACE_IMPULSE); t->SetStartTime(fxlabClientD->GetTime()); t->SetSoundID(EFF_BONUS_ENERGY); - t->SetPosition(Vect3f(Owner->R())); + + Vect3f v1(Owner->R()); + t->SetPosition(v1); + t->Start(); }; }; @@ -1939,7 +2007,10 @@ void fxlabClientMechosController::Quant(void) t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_SOUND_SPACE_IMPULSE); t->SetStartTime(fxlabClientD->GetTime()); t->SetSoundID(EFF_BONUS_SPELL); - t->SetPosition(Vect3f(Owner->R())); + + Vect3f v1(Owner->R()); + t->SetPosition(v1); + t->Start(); }; }; @@ -1973,7 +2044,9 @@ void fxlabClientMechosController::Quant(void) }; IVisGeneric->SetObjectColor((cUnknownClass*)(mp),&sColor4f(cp->Color0.r,cp->Color0.g,cp->Color0.b,a),&sColor4f(r,g,b,cp->Color1.a),mesh_id[i]); Owner->setColor(i,&sColor4f(cp->Color0.r,cp->Color0.g,cp->Color0.b,a),&sColor4f(r,g,b,cp->Color1.a));*/ - Owner->setColor(i,&sColor4f(1.0f,1.0f,1.0f,a),&sColor4f(r,g,b,1.0f)); + sColor4f c1(1.0f,1.0f,1.0f,a); + sColor4f c2(r,g,b,1.0f); + Owner->setColor(i,&c1,&c2); cp->ColorEnable = 1; cp->Red = 0; @@ -1991,7 +2064,9 @@ void fxlabClientMechosController::Quant(void) cp->Alpha = 0; // IVisGeneric->SetObjectColor((cUnknownClass*)(mp),&(cp->Color0),&(cp->Color1),mesh_id[i]); // Owner->setColor(i,&(cp->Color0),&(cp->Color1)); - Owner->setColor(i,&sColor4f(1.0f,1.0f,1.0f,1.0f),&sColor4f(0,0,0,1.0f)); + sColor4f c1(1.0f,1.0f,1.0f,1.0f); + sColor4f c2(0,0,0,1.0f); + Owner->setColor(i,&c1,&c2); }; }; }; @@ -2249,9 +2324,9 @@ void fxlabClientDragonHeadFireSwitcher::CreateObject(void) //-------------------------------------------- -#include "Visgeneric.h" -#include "camera.h" -#include "scene.h" +#include "VisGeneric.h" +#include "Camera.h" +#include "Scene.h" void fxlabClientWorldIrradiate::Open(void) { @@ -2347,7 +2422,14 @@ void fxlabClientWorldIrradiate::Show(void) assert(scene); for(i = 0;i < scene->GetNumberCamera();i++){ camera = scene->GetCamera(i); - P3D->SetViewColor(camera,sColor4f(KeyData[FXLAB_CLIENT_WORLD_IRRADIATE_DATA_RED],KeyData[FXLAB_CLIENT_WORLD_IRRADIATE_DATA_GREEN],KeyData[FXLAB_CLIENT_WORLD_IRRADIATE_DATA_BLUE],KeyData[FXLAB_CLIENT_WORLD_IRRADIATE_DATA_ALPHA]),sColor4f(0,0,0,0),1); + sColor4f c1( + KeyData[FXLAB_CLIENT_WORLD_IRRADIATE_DATA_RED], + KeyData[FXLAB_CLIENT_WORLD_IRRADIATE_DATA_GREEN], + KeyData[FXLAB_CLIENT_WORLD_IRRADIATE_DATA_BLUE], + KeyData[FXLAB_CLIENT_WORLD_IRRADIATE_DATA_ALPHA] + ); + sColor4f c2(0,0,0,0); + P3D->SetViewColor(camera,c1,c2,1); }; IVisGeneric->Release(); }; @@ -2412,13 +2494,15 @@ void fxlabClientSetFaceFire::KeyCheck(void) ErrH.Abort("Bad Key of fxlabClientSetFaceFire"); }; -void fxlabClientSetFaceFire::SetVelocity(Vect3f& v) +void fxlabClientSetFaceFire::SetVelocity(const Vect3f& v) { if(KeyPoint){ Velocity = v; Velocity.normalize(KeyData[FXLAB_CLIENT_SET_FACE_FIRE_SPEED]); - }else - Velocity = v.normalize(); + }else { + Velocity = v; + Velocity.normalize(); + } }; //-------------------------------------------------------- @@ -2451,7 +2535,7 @@ void fxlabClientMovieBowRepeater::KeyCheck(void) ErrH.Abort("Bad Key of fxlabClientMovieBowRepeater"); }; -void fxlabClientMovieBowRepeater::SetVelocity(Vect3f& v) +void fxlabClientMovieBowRepeater::SetVelocity(const Vect3f& v) { Velocity = v; }; @@ -2478,7 +2562,10 @@ void fxlabClientMovieBowRepeater::CreateBow(void) t->SetKeyID(FXLAB_ID_KEY_MOVIE_SPARK); t->SetStartTime(fxlabClientD->GetTime()); t->SetPosition(Position); - t->SetVelocity(Vect3f(0,0,0)); + + Vect3f v1(0,0,0); + t->SetVelocity(v1); + t->Start(); t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_SOUND_SPACE_IMPULSE); @@ -2500,7 +2587,10 @@ void fxlabClientMovieWaveRepeater::Start(void) t->SetKeyID(FXLAB_ID_KEY_MOVIE_SPRAY_STREAM); t->SetStartTime(fxlabClientD->GetTime()); t->SetPosition(Position); - t->SetVelocity(Vect3f(0,0,15.0f)); + + Vect3f v1(0,0,15.0f); + t->SetVelocity(v1); + t->Start(); Cnt = 0; @@ -2529,7 +2619,10 @@ void fxlabClientMovieWaveRepeater::CreateBow(void) t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_MECHOS_WAVE_MODEL); t->SetPosition(Position); - t->SetColorVector(Vect3f(fxlabGetTrackWaveRed(),fxlabGetTrackWaveGreen(),fxlabGetTrackWaveBlue())); + + Vect3f v1(fxlabGetTrackWaveRed(),fxlabGetTrackWaveGreen(),fxlabGetTrackWaveBlue()); + t->SetColorVector(v1); + t->SetTransparency(fxlabGetTrackWaveAlpha()); t->Start(); @@ -2558,7 +2651,10 @@ void fxlabClientMovieQuandLight::Start(void) t->SetKeyID(FXLAB_ID_KEY_QUAD_SPARK); t->SetStartTime(fxlabClientD->GetTime()); t->SetPosition(Position); - t->SetVelocity(Vect3f(0,0,0)); + + Vect3f v1(0,0,0); + t->SetVelocity(v1); + t->SetProcessInterface(&SparkPoint); t->Start(); @@ -2573,7 +2669,10 @@ void fxlabClientMovieQuandLight::Start(void) t->SetKeyID(FXLAB_ID_KEY_QUAD_BOW); t->SetStartTime(fxlabClientD->GetTime()); t->SetPosition(Position); - t->SetVelocity(Vect3f(0,0,0)); + + Vect3f v2(0,0,0); + t->SetVelocity(v2); + t->SetProcessInterface(&BowPoint); t->Start(); }; @@ -2715,10 +2814,10 @@ void fxlabClientMovieTeleport::Start(void) fxlabClientSpaceType::Start(); v = Position; - if(fxlabGetWorldReflectionEnable() && GetW(XCYCL(round(v.x)),YCYCL(round(v.y)))) + if(fxlabGetWorldReflectionEnable() && GetW(XCYCL(int(round(v.x))),YCYCL(int(round(v.y))))) v.z = vMap->LevelH2O + 2.5f; else - v.z = ZV(XCYCL(round(v.x)),YCYCL(round(v.y))) + 2.5f; + v.z = ZV(XCYCL(int(round(v.x))),YCYCL(int(round(v.y)))) + 2.5f; t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_SPARK_GENERATOR); t->SetStartTime(fxlabClientD->GetTime()); @@ -2747,15 +2846,18 @@ void fxlabClientMovieSpot::Start(void) fxlabClientSpaceType::Start(); v = Position; - if(fxlabGetWorldReflectionEnable() && GetW(XCYCL(round(v.x)),YCYCL(round(v.y)))) + if(fxlabGetWorldReflectionEnable() && GetW(XCYCL(int(round(v.x))),YCYCL(int(round(v.y))))) v.z = vMap->LevelH2O + 2.5f; else - v.z = ZV(XCYCL(round(v.x)),YCYCL(round(v.y))) + 2.5f; + v.z = ZV(XCYCL(int(round(v.x))),YCYCL(int(round(v.y)))) + 2.5f; t = fxlabClientD->CreateObject(FXLAB_CLIENT_PROCESS_CONTROL_MODEL); t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_TELEPORT_MOVIE_MODEL); - t->SetMatrix(getPlacementGroundPose(Vect3f(Position.x,Position.y,0))); + + auto m1 = getPlacementGroundPose(Vect3f(Position.x,Position.y,0)); + t->SetMatrix(m1); + t->SetPosition(v); t->SetProcessInterface(&SpotPoint); t->Start(); @@ -2781,7 +2883,10 @@ void fxlabClientFireTreeMovie::Start(void) t->SetKeyID(FXLAB_ID_KEY_MOVIE_TREE_FIRE); t->SetStartTime(fxlabClientD->GetTime()); t->SetPosition(Position); - t->SetVelocity(Vect3f(0,0,0)); + + Vect3f v1(0,0,0); + t->SetVelocity(v1); + t->SetProcessInterface(&FirePoint); t->Start(); }; @@ -2948,7 +3053,10 @@ void fxlabClientCharacterWaveGenerator::CoreGenerate(void) t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_CHARACTER_WAVE_MODEL); t->SetPosition(v); - t->SetColorVector(Vect3f(fxlabGetTrackWaveRed(),fxlabGetTrackWaveGreen(),fxlabGetTrackWaveBlue())); + + Vect3f v1(fxlabGetTrackWaveRed(),fxlabGetTrackWaveGreen(),fxlabGetTrackWaveBlue()); + t->SetColorVector(v1); + t->SetTransparency(fxlabGetTrackWaveAlpha()); t->Start(); }; @@ -3004,7 +3112,10 @@ void fxlabClientBossWorldBurst::Start(void) t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_CHARACTER_WORLD_BURST); t->SetPosition(Position); - t->SetVelocity(Vect3f(0,0,0)); + + Vect3f v1(0,0,0); + t->SetVelocity(v1); + t->SetProcessInterface(&BurstPoint); t->Start(); }; @@ -3032,7 +3143,10 @@ void fxlabClientBossWorldExplosion::Start(void) t->SetStartTime(fxlabClientD->GetTime()); t->SetKeyID(FXLAB_ID_KEY_CHARACTER_WORLD_EXPLOSION); t->SetPosition(Position); - t->SetVelocity(Vect3f(0,0,0)); + + Vect3f v1(0,0,0); + t->SetVelocity(v1); + t->SetProcessInterface(&ExplosionPoint); t->Start(); }; @@ -3099,7 +3213,7 @@ void fxlabClientMovieDragonFire::Quant(void) SoundPoint.Process->SetPosition(Position); }; -void fxlabClientMovieDragonFire::SetVelocity(Vect3f& v) +void fxlabClientMovieDragonFire::SetVelocity(const Vect3f& v) { Velocity = v; Velocity.normalize(20.0f); @@ -3201,7 +3315,7 @@ void fxlabClientBossRocketFire::Quant(void) SoundPoint.Process->SetPosition(Position); }; -void fxlabClientBossRocketFire::SetVelocity(Vect3f& v) +void fxlabClientBossRocketFire::SetVelocity(const Vect3f& v) { Normal = v; Normal.normalize(); diff --git a/MechoSoma/FX/fxlabClientStuff.h b/MechoSoma/FX/fxlabClientStuff.h index 952dbe06..3546b149 100644 --- a/MechoSoma/FX/fxlabClientStuff.h +++ b/MechoSoma/FX/fxlabClientStuff.h @@ -44,7 +44,7 @@ struct fxlabCheckPoint : fxlabClientSpaceType void SetScale(float scale); void SetMode(int mode); - void SetVelocity(Vect3f& velocity); + void SetVelocity(const Vect3f& velocity); void SetCheckPointModels(int id0,int id1); void SetCheckPointRacer(int mode,struct mchRacer* p,int init_flag); void SetAngle(float angle); @@ -89,9 +89,9 @@ struct fxlabPolarModel : fxlabClientKeyObjectType void KeyCheck(void); - void SetScaleVector(Vect3f& v); - void SetAngleVector(Vect3f& v); - void SetColorVector(Vect3f& v); + void SetScaleVector(const Vect3f& v); + void SetAngleVector(const Vect3f& v); + void SetColorVector(const Vect3f& v); void SetTransparency(float a); void SetModel(int id); void SetRacerPoint(struct mchRacer* p); @@ -212,7 +212,7 @@ struct fxlabClientWildClaw : fxlabClientRemoteAim void CalcCenter(void); - void SetVelocity(Vect3f& v){ Velocity = v; }; + void SetVelocity(const Vect3f& v){ Velocity = v; }; void SetRemoteID(int id); int GetAlive(void); @@ -388,23 +388,23 @@ struct fxlabClientMassShifter : fxlabClientKeyObjectType { void Quant(void); void KeyCheck(void); - virtual void Generate(Mat3f& m,Vect3f& v); + virtual void Generate(const Mat3f& m,const Vect3f& v); }; struct fxlabClientMassShifterNitro : fxlabClientMassShifter { - void Generate(Mat3f& m,Vect3f& v); + void Generate(const Mat3f& m,const Vect3f& v); }; struct fxlabClientMassShifterCharacter : fxlabClientMassShifter { - void Generate(Mat3f& m,Vect3f& v); + void Generate(const Mat3f& m,const Vect3f& v); }; struct fxlabClientMassShifterMovie : fxlabClientMassShifter { - void Generate(Mat3f& m,Vect3f& v); + void Generate(const Mat3f& m,const Vect3f& v); }; //------------------------------------- @@ -625,7 +625,7 @@ struct fxlabClientSetFaceFire : fxlabClientKeyObjectType void Close(void); void Quant(void); void KeyCheck(void); - void SetVelocity(Vect3f& v); + void SetVelocity(const Vect3f& v); }; enum fxlabClientMovieBowRepeaterDataField @@ -643,7 +643,7 @@ struct fxlabClientMovieBowRepeater : fxlabClientKeyObjectType void Start(void); void Quant(void); void KeyCheck(void); - void SetVelocity(Vect3f& v); + void SetVelocity(const Vect3f& v); virtual void CreateBow(void); }; @@ -744,7 +744,7 @@ struct fxlabClientMovieDragonFire : fxlabClientSpaceType void Start(void); void Close(void); void Quant(void); - void SetVelocity(Vect3f& v); + void SetVelocity(const Vect3f& v); }; //----------------------------------- @@ -812,6 +812,6 @@ struct fxlabClientBossRocketFire : fxlabClientSpaceType void Start(void); void Close(void); void Quant(void); - void SetVelocity(Vect3f& v); + void SetVelocity(const Vect3f& v); }; diff --git a/MechoSoma/FX/fxlabGeneral.cpp b/MechoSoma/FX/fxlabGeneral.cpp index 505154f4..cf98e20e 100644 --- a/MechoSoma/FX/fxlabGeneral.cpp +++ b/MechoSoma/FX/fxlabGeneral.cpp @@ -1,24 +1,26 @@ #include "StdAfx.h" #include "aci_parser.h" +#ifdef _WIN32 #include "win32f.h" +#endif -#include "handle.h" +#include "Handle.h" #include "BodyDispatcher.h" #include "Mechos.h" #include "OwnerProtection.h" #include "Meteorite.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "Levin.h" -#include "terra.h" +#include "TERRA.H" #include "race.h" #include "sound.h" #include "sur_scr.h" #include "SST_Reader.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "fxlabID.h" #include "fxlabGeneral.h" diff --git a/MechoSoma/FX/fxlabGeneral.h b/MechoSoma/FX/fxlabGeneral.h index ac644887..3c522e11 100644 --- a/MechoSoma/FX/fxlabGeneral.h +++ b/MechoSoma/FX/fxlabGeneral.h @@ -48,16 +48,16 @@ struct fxlabGeneralObjectType virtual void SetStartTime(float time){ StartTime = time; }; virtual void SetFinishTime(float time){ FinishTime = time; }; - virtual void SetPosition(class Vect3f& v){}; + virtual void SetPosition(const class Vect3f& v){}; virtual void GetPosition(class Vect3f& v){}; virtual void SetConversion(int conv){}; virtual void SetSplineOwner(void* point){}; - virtual void SetVelocity(Vect3f& v){}; + virtual void SetVelocity(const Vect3f& v){}; virtual void SetScale(float scale){}; - virtual void SetMatrix(class MatXf& m){}; + virtual void SetMatrix(const class MatXf& m){}; virtual void SetAngle(float angle){}; virtual void SetMode(int mode){}; @@ -66,9 +66,9 @@ struct fxlabGeneralObjectType virtual void SetCheckPointRacer(int mode,struct mchRacer* p,int init_flag = 0){}; virtual void SetCheckPointCamera(int camera){}; - virtual void SetScaleVector(Vect3f& v){}; - virtual void SetAngleVector(Vect3f& v){}; - virtual void SetColorVector(Vect3f& v){}; + virtual void SetScaleVector(const Vect3f& v){}; + virtual void SetAngleVector(const Vect3f& v){}; + virtual void SetColorVector(const Vect3f& v){}; virtual void SetTransparency(float a){}; virtual void SetModel(int id){}; virtual void SetRacerPoint(struct mchRacer* p){}; @@ -145,7 +145,7 @@ struct fxlabGeneralObjectType virtual void SetScaleAnimation(float start_scale,float end_scale,int time){}; - virtual void SetDirectionMatrix(class Mat3f& m){}; + virtual void SetDirectionMatrix(const class Mat3f& m){}; virtual void SetBigBossWorldStatus(int world){}; }; diff --git a/MechoSoma/FX/fxlabInterface.cpp b/MechoSoma/FX/fxlabInterface.cpp index 6fc5db46..43b38562 100644 --- a/MechoSoma/FX/fxlabInterface.cpp +++ b/MechoSoma/FX/fxlabInterface.cpp @@ -1,9 +1,11 @@ #include "StdAfx.h" #include "aci_parser.h" +#ifdef _WIN32 #include "win32f.h" +#endif -#include "handle.h" +#include "Handle.h" #include "BodyDispatcher.h" #include "Mechos.h" #include "OwnerProtection.h" @@ -13,16 +15,16 @@ #include "TileMap.h" #include "TileWater.h" #include "IVisGeneric.h" -#include "terra.h" +#include "TERRA.H" #include "race.h" #include "sound.h" -#include "Igraph3d.h" +#include "IGraph3d.h" #include "sur_scr.h" #include "SST_Reader.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "fxlabID.h" #include "fxlabGeneral.h" @@ -44,10 +46,14 @@ #include "fxlabServerStuff.h" #include "fxlabServerArcane.h" #include "fxlabBodyInterface.h" -#include "Mechosoma.h" +#include "mechosoma.h" #include "Statistics.h" #include "PersonageDifferetiationPrm.h" -#include "params.h" +#include "Params.h" + +#ifndef _WIN32 +#define DBGCHECK +#endif fxlabClientObjectDispatcher* fxlabClientD = NULL; fxlabServerObjectDispatcher* fxlabServerD = NULL; @@ -375,7 +381,7 @@ void fxlabCreateMasterCheckPoint(fxlabProcessInterface* master,int x,int y,int z }; -int fxlabLine2SphereDist(Vect3f& r1,Vect3f& c,float rad) +int fxlabLine2SphereDist(const Vect3f& r1,const Vect3f& c,float rad) { Vect3f m,m2,p; float t,d; @@ -583,7 +589,7 @@ void fxlabFirePointInterface::Close(void) ServerPoint.Process->SetAlive(0); }; -void fxlabFirePointInterface::Update(Vect3f& pos,Vect3f& vel) +void fxlabFirePointInterface::Update(const Vect3f& pos,const Vect3f& vel) { fxlabGeneralObjectType* t; @@ -675,7 +681,7 @@ void fxlabFirePointInterface::Update(Vect3f& pos,Vect3f& vel) }; }; -void fxlabFirePointInterface::Update(class Vect3f& pos,class Mat3f& vel) +void fxlabFirePointInterface::Update(const class Vect3f& pos,const class Mat3f& vel) { fxlabGeneralObjectType* t; @@ -3072,7 +3078,9 @@ void fxlabMechosGlowDestruction(Mechos* p) p->fxlabMechosInfo.ColorData[i].Alpha = 0; // IVisGeneric->SetObjectColor((cUnknownClass*)(mp),&(p->fxlabMechosInfo.ColorData[i].Color0),&(p->fxlabMechosInfo.ColorData[i].Color1),mesh_id[i]); // p->setColor(i,&(p->fxlabMechosInfo.ColorData[i].Color0),&(p->fxlabMechosInfo.ColorData[i].Color1)); - p->setColor(i,&sColor4f(1.0f,1.0f,1.0f,1.0f),&sColor4f(0,0,0,1.0f)); + sColor4f c1(1.0f,1.0f,1.0f,1.0f); + sColor4f c2(0,0,0,1.0f); + p->setColor(i,&c1,&c2); }; }; IVisGeneric->Release(); @@ -3471,7 +3479,7 @@ void fxlabTeleportInterface::SetStatus(int status) void fxlabTeleportDispatcher::Init(void) { - fxlabTeleportList.resize(100); + fxlabTeleportList.reserve(100); }; void fxlabTeleportDispatcher::Finit(void) @@ -3487,7 +3495,7 @@ void fxlabTeleportDispatcher::Finit(void) void fxlabTeleportDispatcher::Open(void) { fxlabTeleportListType::iterator p; - hash_map::iterator pp; + std::unordered_map::iterator pp; if(mchCurrentWorld == 7){ FOR_EACH(fxlabTeleportList,p){ @@ -3501,7 +3509,7 @@ void fxlabTeleportDispatcher::Open(void) void fxlabTeleportDispatcher::Close(void) { fxlabTeleportListType::iterator p; - hash_map::iterator pp; + std::unordered_map::iterator pp; FOR_EACH(fxlabTeleportList,p){ FOR_EACH(((*p).second),pp){ @@ -4168,7 +4176,7 @@ void fxlabSnowBallAction(class Body* p) //----------------------------------------- -void fxlabMovieUpdateProcess(const char* name,Vect3f& position,Vect3f& velocity,int status) +void fxlabMovieUpdateProcess(const char* name,const Vect3f& position,const Vect3f& velocity,int status) { fxlabMovieD->UpdateProcess(name,position,velocity,status); }; @@ -4180,7 +4188,7 @@ void fxlabMovieDestroy(void) void fxlabMovieDispacther::Open(void) { - MovieList.resize(300); + MovieList.reserve(300); RegisterName("Kron_fire_first",FXLAB_CLIENT_PROCESS_SET_FACE_FIRE,FXLAB_ID_KEY_MOVIE_HEAD_SET); RegisterName("kron_flash",FXLAB_CLIENT_PROCESS_MOVIE_BOW_REPEATER,FXLAB_ID_KEY_MOVIE_STORM_CONTROL); RegisterName("Kron_Water1",FXLAB_CLIENT_PROCESS_MOVIE_WAVE_REPEATER,FXLAB_ID_KEY_MOVIE_WAVE_CONTROL); @@ -4266,7 +4274,7 @@ void fxlabMovieDispacther::Close(void) void fxlabMovieDispacther::Clear(void) { - hash_map,fxlabMovieEqStr>::iterator i_movie; + std::unordered_map::iterator i_movie; FOR_EACH(MovieList,i_movie){ if(i_movie->second.ProcessPoint.Process) @@ -4280,9 +4288,9 @@ void fxlabMovieDispacther::RegisterName(const char* name,int type,int key_id) MovieList[name].ProcessKeyID = key_id; }; -void fxlabMovieDispacther::UpdateProcess(const char* name,Vect3f& position,Vect3f& velocity,int status) +void fxlabMovieDispacther::UpdateProcess(const char* name,const Vect3f& position,const Vect3f& velocity,int status) { - hash_map,fxlabMovieEqStr>::iterator i_movie; + std::unordered_map::iterator i_movie; fxlabGeneralObjectType* t; fxlabProcessInterface* p; diff --git a/MechoSoma/FX/fxlabInterface.h b/MechoSoma/FX/fxlabInterface.h index d8a6fd2b..e723cb27 100644 --- a/MechoSoma/FX/fxlabInterface.h +++ b/MechoSoma/FX/fxlabInterface.h @@ -1,10 +1,11 @@ #ifndef __FXLAB_INTERFACE__ #define __FXLAB_INTERFACE__ -#include "base.h" +#include + +#include "Base.h" #include "ArcaneDefine.h" #include "ArcaneStatistics.h" -#include "hash_map.h" void fxlabOpen(void); void fxlabClose(void); @@ -53,7 +54,7 @@ void fxlabArcaneStop(const class ArcaneStatisticsInfo* p); void fxlabArcaneAction(const class ArcaneStatisticsInfo* p,int id); void fxlabArcaneStatisticInit(void); -int fxlabLine2SphereDist(class Vect3f& r1,class Vect3f& c,float rad); +int fxlabLine2SphereDist(const class Vect3f& r1,const class Vect3f& c,float rad); int fxlabGetWorldReflectionEnable(void); int fxlabGetWaterRed(void); @@ -90,11 +91,11 @@ struct fxlabFirePointInterface void Open(int id); void Close(void); - void Update(class Vect3f& pos,class Vect3f& vel); - void Update(class Vect3f& pos,class Mat3f& vel); + void Update(const class Vect3f& pos,const class Vect3f& vel); + void Update(const class Vect3f& pos,const class Mat3f& vel); }; -#include "umath.h" +#include "UMATH.H" const int FXLAB_MECHOS_IMFORMATION_MANA_DELAY = 500; const int FXLAB_MECHOS_IMFORMATION_ENERGY_DELAY = 500; @@ -282,7 +283,7 @@ struct fxlabTeleportInterface void SetStatus(int status); }; -typedef hash_map > fxlabTeleportListType; +typedef std::unordered_map > fxlabTeleportListType; struct fxlabTeleportDispatcher { @@ -322,18 +323,18 @@ struct fxlabMovieEqStr struct fxlabMovieDispacther { - hash_map,fxlabMovieEqStr> MovieList; + std::unordered_map MovieList; void Open(void); void Close(void); void Clear(void); void RegisterName(const char* name,int type,int key_id); - void UpdateProcess(const char* name,Vect3f& position,Vect3f& velocity,int status); + void UpdateProcess(const char* name,const Vect3f& position,const Vect3f& velocity,int status); }; extern fxlabMovieDispacther* fxlabMovieD; -void fxlabMovieUpdateProcess(const char* name,Vect3f& position,Vect3f& velocity,int status); +void fxlabMovieUpdateProcess(const char* name,const Vect3f& position,const Vect3f& velocity,int status); void fxlabMovieDestroy(void); enum fxlabBigBossWorldType diff --git a/MechoSoma/FX/fxlabServerArcane.cpp b/MechoSoma/FX/fxlabServerArcane.cpp index f51aeb6c..1014ba9f 100644 --- a/MechoSoma/FX/fxlabServerArcane.cpp +++ b/MechoSoma/FX/fxlabServerArcane.cpp @@ -1,12 +1,12 @@ #include "StdAfx.h" #include "aci_parser.h" -#include "terra.h" +#include "TERRA.H" #include "BodyDispatcher.h" #include "Mechos.h" #include "CustomFieldSources.h" -#include "keys.h" +#include "KEYS.H" #include "ctl_point.h" #include "race.h" #include "arcane_menu.h" @@ -21,10 +21,10 @@ #include "fxlabServerGeneral.h" #include "fxlabServerStuff.h" #include "fxlabServerArcane.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" -#include "m3d_id.h" -#include "m3d_effects.h" +#include "M3d_id.h" +#include "M3d_effects.h" #include "fxlabBodyInterface.h" #include "TrackIterator.h" @@ -34,7 +34,7 @@ const float FXLAB_REALOBJECT_OFFSET_Z = 20.0f; MatXf getPlacementPose(const Vect3f& center); -void fxlabGetArcanePosition(Mechos* owner,Vect3f& offset,Vect3f& pos); +void fxlabGetArcanePosition(Mechos* owner,const Vect3f& offset,Vect3f& pos); extern int mchCurrentWorld; @@ -2322,7 +2322,7 @@ void fxlabArcaneRedTrack::Close(void) }; -void fxlabGetArcanePosition(Mechos* owner,Vect3f& offset,Vect3f& pos) +void fxlabGetArcanePosition(Mechos* owner,const Vect3f& offset,Vect3f& pos) { Vect3f AxisX,AxisY,AxisZ; diff --git a/MechoSoma/FX/fxlabServerGeneral.cpp b/MechoSoma/FX/fxlabServerGeneral.cpp index 32df246b..befada71 100644 --- a/MechoSoma/FX/fxlabServerGeneral.cpp +++ b/MechoSoma/FX/fxlabServerGeneral.cpp @@ -1,12 +1,12 @@ #include "StdAfx.h" #include "aci_parser.h" -#include "terra.h" +#include "TERRA.H" #include "BodyDispatcher.h" #include "Mechos.h" #include "CustomFieldSources.h" -#include "keys.h" +#include "KEYS.H" #include "ctl_point.h" #include "race.h" #include "arcane_menu.h" @@ -19,7 +19,7 @@ #include "fxlabApplication.h" #include "XTList.h" #include "fxlabServerGeneral.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" void fxlabServerEvolutionType::Start(void) diff --git a/MechoSoma/FX/fxlabServerStuff.cpp b/MechoSoma/FX/fxlabServerStuff.cpp index 571ef125..261b6704 100644 --- a/MechoSoma/FX/fxlabServerStuff.cpp +++ b/MechoSoma/FX/fxlabServerStuff.cpp @@ -1,12 +1,12 @@ #include "StdAfx.h" #include "aci_parser.h" -#include "terra.h" +#include "TERRA.H" #include "BodyDispatcher.h" #include "Mechos.h" #include "CustomFieldSources.h" -#include "keys.h" +#include "KEYS.H" #include "ctl_point.h" #include "race.h" #include "arcane_menu.h" @@ -23,9 +23,9 @@ #include "fxlabServerGeneral.h" #include "fxlabServerStuff.h" #include "fxlabServerArcane.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" -#include "win32f.h" +// #include "win32f.h" #include "mechosoma.h" #include "fxlabBodyInterface.h" @@ -63,8 +63,8 @@ void fxlabDamageSensorType::Action(void) case FXLAB_DAMAGE_SPHERE_TYPE_CHARGE_ENERGY: while(mp){ if(CheckProtection(mp) && mp->completed() && mp->Type == MCH_RACER_TYPE_MECHOS){ - dx = getDistX(round(mp->R().x),x); - dy = getDistY(round(mp->R().y),y); + dx = getDistX_f(round(mp->R().x),x); + dy = getDistY_f(round(mp->R().y),y); dz = round(mp->R().z) - z; d = dx*dx + dy*dy + dz*dz; r2 = round(Radius + mp->radius()); @@ -81,8 +81,8 @@ void fxlabDamageSensorType::Action(void) case FXLAB_DAMAGE_SPHERE_TYPE_CHARGE_MANA: while(mp){ if(CheckProtection(mp) && mp->completed() && mp->Type == MCH_RACER_TYPE_MECHOS){ - dx = getDistX(round(mp->R().x),x); - dy = getDistY(round(mp->R().y),y); + dx = getDistX_f(round(mp->R().x),x); + dy = getDistY_f(round(mp->R().y),y); dz = round(mp->R().z) - z; d = dx*dx + dy*dy + dz*dz; r2 = round(Radius + mp->radius()); @@ -99,8 +99,8 @@ void fxlabDamageSensorType::Action(void) case FXLAB_DAMAGE_SPHERE_TYPE_KINETIC: while(mp){ if(CheckProtection(mp) && mp->completed() && mp->Type == MCH_RACER_TYPE_MECHOS){ - dx = getDistX(round(mp->R().x),x); - dy = getDistY(round(mp->R().y),y); + dx = getDistX_f(round(mp->R().x),x); + dy = getDistY_f(round(mp->R().y),y); dz = round(mp->R().z) - z; d = dx*dx + dy*dy + dz*dz; r2 = round(Radius + mp->radius()); @@ -115,8 +115,8 @@ void fxlabDamageSensorType::Action(void) default: while(mp){ if(CheckProtection(mp) && mp->completed() && mp->Type == MCH_RACER_TYPE_MECHOS){ - dx = getDistX(round(mp->R().x),x); - dy = getDistY(round(mp->R().y),y); + dx = getDistX_f(round(mp->R().x),x); + dy = getDistY_f(round(mp->R().y),y); dz = round(mp->R().z) - z; d = dx*dx + dy*dy + dz*dz; r2 = round(Radius + mp->radius()); diff --git a/MechoSoma/FX/fxlabSprite.cpp b/MechoSoma/FX/fxlabSprite.cpp index f6281b69..69cc4e3e 100644 --- a/MechoSoma/FX/fxlabSprite.cpp +++ b/MechoSoma/FX/fxlabSprite.cpp @@ -2,7 +2,7 @@ #include "aci_parser.h" -#include "polymgr.h" +#include "PolyMgr.h" #include "fxlabID.h" #include "fxlabResource.h" @@ -43,7 +43,7 @@ void fxlabSpriteType::Close(void) sSpriteFX* fxlabSpriteType::GetSpriteData(float phase) { - return SpriteData + round(phase * Scale); + return SpriteData + int(round(phase * Scale)); }; void fxlabSpriteType::Link(void) diff --git a/MechoSoma/IVisGeneric/IVisGeneric.h b/MechoSoma/IVisGeneric/IVisGeneric.h index f8dcf92f..8fd1dc0e 100644 --- a/MechoSoma/IVisGeneric/IVisGeneric.h +++ b/MechoSoma/IVisGeneric/IVisGeneric.h @@ -1,6 +1,8 @@ #ifndef __IVISGENERIC_H__ #define __IVISGENERIC_H__ +#include + #include "Unknown.h" class Vect2f; @@ -12,21 +14,21 @@ struct XBuffer; class cInterfaceGraph3d; UI_BEGIN(cInterfaceVisGeneric,KIND_UI_VISGENERIC) - // èíèöèàëèçàöèîííàÿ ÷àñòü + // ����������������� ����� UI_IMPORT( int Create(char *CreateBuffer) ); UI_IMPORT( int Release() ); - // ôóíêöèè äëÿ ðàáîòû ñîáñòâåííî ñ áèáëèîòåêîé âûâîäà + // ������� ��� ������ ���������� � ����������� ������ UI_IMPORT( int PreDraw(int mask=0xFFFFFFFF) ); UI_IMPORT( int Draw(int mask=0xFFFFFFFF) ); UI_IMPORT( int PostDraw(int mask=0xFFFFFFFF) ); UI_IMPORT( int SetTime(int Time) ); UI_IMPORT( int dSetTime(int dTime) ); UI_IMPORT( int GetTime(int *Time) ); - // ôóíêöèè äëÿ ðàáîòû ñî ñöåíîé + // ������� ��� ������ �� ������ UI_IMPORT( cUnknownClass* CreateScene() ); UI_IMPORT( int ReleaseScene(cUnknownClass* Scene) ); UI_IMPORT( int SetScene(cUnknownClass* Scene) ); - // îáùèå ôóíêöèè äëÿ ðàáîòû îáúåêòàìè cUnknownClass + // ����� ������� ��� ������ ��������� cUnknownClass UI_IMPORT( int Release(cUnknownClass *UnkClass) ); UI_IMPORT( int SetAttribute(cUnknownClass *UnkClass,int Attribute) ); UI_IMPORT( int GetAttribute(cUnknownClass *UnkClass,int Attribute=0xFFFFFFFF) ); @@ -34,7 +36,7 @@ UI_BEGIN(cInterfaceVisGeneric,KIND_UI_VISGENERIC) UI_IMPORT( int SetPosition(cUnknownClass *UnkClass,const Vect3f *Pos,const Vect3f *AngleGrad=0) ); UI_IMPORT( int dSetPosition(cUnknownClass *UnkClass,const Vect3f *dPos,const Vect3f *dAngleGrad) ); UI_IMPORT( int GetPosition(cUnknownClass *UnkClass,Vect3f *Pos,Vect3f *AngleGrad) ); - // ôóíêöèè äëÿ ðàáîòû ñ îêíîì âûâîäà + // ������� ��� ������ � ����� ������ UI_IMPORT( cUnknownClass* CreateGraph(int xScr,int yScr,int GraphMode=0,int FullScr=0,int ColorBit=16) ); UI_IMPORT( int SetGraphClipping(cUnknownClass *URenderDevice,const sRectangle4f *clip) ); UI_IMPORT( int GetGraphClipping(cUnknownClass *URenderDevice,sRectangle4f *clip) ); @@ -44,8 +46,8 @@ UI_BEGIN(cInterfaceVisGeneric,KIND_UI_VISGENERIC) UI_IMPORT( int ReInitGraph(cUnknownClass *URenderDevice,int xScr,int yScr,int GraphMode=0,int FullScr=0,int ColorBit=16) ); UI_IMPORT( int GetGraphInfo(cUnknownClass *URenderDevice,int *xScr,int *yScr,int *GraphMode=0,int *FullScr=0,int *ColorBit=0) ); UI_IMPORT( cInterfaceGraph3d* GetIGraph3d(cUnknownClass *URenderDevice=0) ); - // ôóíêöèè äëÿ ðàáîòû ñ îáúåêòàìè - UI_IMPORT( int LoadObjectLibrary(char *fname="RESOURCE\\m3d.scb") ); + // ������� ��� ������ � ��������� + UI_IMPORT( int LoadObjectLibrary(const std::filesystem::path &path) ); UI_IMPORT( int FreeObjectLibrary(int kind=0xFFFFFFFF,int type=0xFFFFFFFF) ); UI_IMPORT( int ReleaseObject(int kind,int type) ); UI_IMPORT( cUnknownClass* CreateObject(char *fname,char *TexturePath,int Kind=0,int Type=0) ); @@ -79,7 +81,7 @@ UI_BEGIN(cInterfaceVisGeneric,KIND_UI_VISGENERIC) UI_IMPORT( int ClearRenderObjectSwitch(int attribute=0xFFFFFFFF) ); UI_IMPORT( int LoadObject(cUnknownClass **UObject,XBuffer &buf,cUnknownClass *UParent=0) ); UI_IMPORT( int SaveObject(cUnknownClass *UObject,XBuffer &buf) ); - // ôóíêöèè äëÿ ðàáîòû ñ òî÷å÷íûìè èñòî÷íèêàìè ñâåòà + // ������� ��� ������ � ��������� ����������� ����� UI_IMPORT( cUnknownClass* CreateOmni(const Vect3f *Pos,float radius,const sColor4f *Color) ); UI_IMPORT( int ReleaseOmni(cUnknownClass *UOmni) ); UI_IMPORT( int ReleaseOmni(int type) ); @@ -92,7 +94,7 @@ UI_BEGIN(cInterfaceVisGeneric,KIND_UI_VISGENERIC) UI_IMPORT( int GetOmniSize(cUnknownClass *UOmni,float *radius) ); UI_IMPORT( int SetOmniVisible(cUnknownClass *UOmni,int visible) ); UI_IMPORT( int GetOmniVisible(cUnknownClass *UOmni,int visible=0xFFFFFFFF) ); - // ôóíêöèè äëÿ ðàáîòû ñ êàìåðàìè + // ������� ��� ������ � �������� UI_IMPORT( cUnknownClass* CreateCamera(char *CreateBuffer=0) ); UI_IMPORT( int AttachCamera(cUnknownClass *UCamera) ); UI_IMPORT( int DetachCamera(cUnknownClass *UCamera) ); @@ -113,7 +115,7 @@ UI_BEGIN(cInterfaceVisGeneric,KIND_UI_VISGENERIC) UI_IMPORT( int SetCameraOfs(cUnknownClass *UCamera,const Vect3f *Ofs) ); UI_IMPORT( int GetCameraOfs(cUnknownClass *UCamera,Vect3f *Ofs) ); UI_IMPORT( int ReleaseCamera(cUnknownClass *UCamera=0) ); - // ôóíêöèè äëÿ ðàáîòû ñ èñòî÷íèêàìè ñâåòà, âëèÿþùèìè íà îñâåùåíèå îáúåêòîâ òåêóùåé ñöåíû + // ������� ��� ������ � ����������� �����, ��������� �� ��������� �������� ������� ����� UI_IMPORT( cUnknownClass* CreateLight(int id=-1) ); UI_IMPORT( int SetLightPosition(cUnknownClass *ULight,const Vect3f *pos) ); UI_IMPORT( int GetLightPosition(cUnknownClass *ULight,Vect3f *pos) ); @@ -122,16 +124,16 @@ UI_BEGIN(cInterfaceVisGeneric,KIND_UI_VISGENERIC) UI_IMPORT( int SetLightColor(cUnknownClass *ULight,const sColor4f *ambient=0,const sColor4f *diffuse=0,const sColor4f *illumination=0) ); UI_IMPORT( int GetLightColor(cUnknownClass *ULight,sColor4f *ambient=0,sColor4f *diffuse=0,sColor4f *illumination=0) ); UI_IMPORT( cUnknownClass* GetLight(int id) ); - UI_IMPORT( int ReleaseLight(cUnknownClass *ULight) );// óäàëÿåò òî÷å÷íûé èñòî÷íèê - // ôóíêöèè äëÿ ðàáîòû ñî ñëåäàìè + UI_IMPORT( int ReleaseLight(cUnknownClass *ULight) );// ������� �������� �������� + // ������� ��� ������ �� ������� UI_IMPORT( cUnknownClass* CreateTangentTrail(const Vect3f *pos,const sColor4f *c1,const Vect3f *dpos,const sColor4f *c2,float Time=10000.f,float dAnimTime=1.e30f,float Width=2.f) ); UI_IMPORT( int ReleaseTangentTrail(cUnknownClass* UTangentTrail) ); - // ñîçäàíèå ìèðà, ïî èíôîðìàöèè â ñêðèïòå fname, number - íîìåð ìèðà - UI_IMPORT( cUnknownClass* CreateWorld(char *fname,int number=0,int track=0,int LoadTerra=0) ); + // �������� ����, �� ���������� � ������� fname, number - ����� ���� + UI_IMPORT( cUnknownClass* CreateWorld(const std::filesystem::path &path,int number=0,int track=0,int LoadTerra=0) ); UI_IMPORT( int ReleaseWorld(cUnknownClass *UWorld=0) ); UI_IMPORT( int GetPolygonMapAttribute(int x1,int y1,int x2,int y2,int x3,int y3) ); - UI_IMPORT( cUnknownClass* FindObject(char *name) ); // ïîèñê îáúåêòà íà ìèðó ïî èìåíè îáúåêòà - UI_IMPORT( cUnknownClass* FindObjectByFileName(char *fname) ); // ïîèñê îáúåêòà íà ìèðó ïî èìåíè ôàéëà îáúåêòà + UI_IMPORT( cUnknownClass* FindObject(char *name) ); // ����� ������� �� ���� �� ����� ������� + UI_IMPORT( cUnknownClass* FindObjectByFileName(char *fname) ); // ����� ������� �� ���� �� ����� ����� ������� UI_IMPORT( cUnknownClass* GetMeshLibrary(cUnknownClass *UScene=0) ); UI_IMPORT( cUnknownClass* GetCameraList(cUnknownClass *UScene=0) ); UI_IMPORT( cUnknownClass* GetTileWater(cUnknownClass *UScene=0) ); diff --git a/MechoSoma/IVisGeneric/UMATH.H b/MechoSoma/IVisGeneric/UMATH.H index 62e9df3c..56ead1a7 100644 --- a/MechoSoma/IVisGeneric/UMATH.H +++ b/MechoSoma/IVisGeneric/UMATH.H @@ -7,6 +7,7 @@ #endif //__forceinline #endif //_MSC_VER +#include #include "xmath.h" #define EQUAL_FLT(a,b) (fabs((a)-(b))<.001f) diff --git a/MechoSoma/IVisGeneric/VisGenericDefine.h b/MechoSoma/IVisGeneric/VisGenericDefine.h index 58015fde..7743217c 100644 --- a/MechoSoma/IVisGeneric/VisGenericDefine.h +++ b/MechoSoma/IVisGeneric/VisGenericDefine.h @@ -32,4 +32,4 @@ enum eConstVisible // ñòàðûå îïðåäåëåíèÿ äëÿ ñîâìåñòèìîñòè, â ïðîöåññå ïåðåðàáîòêè äîëæíû áûòü óäàëåíû #define CONST_VISIBLE 1 -#endif __VISGENERICDEFINE_H__ \ No newline at end of file +#endif // __VISGENERICDEFINE_H__ \ No newline at end of file diff --git a/MechoSoma/RUNTIME/Chtree.cpp b/MechoSoma/RUNTIME/Chtree.cpp index 226cb0ee..e7c96021 100644 --- a/MechoSoma/RUNTIME/Chtree.cpp +++ b/MechoSoma/RUNTIME/Chtree.cpp @@ -1,7 +1,7 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include "chtree.h" +#include "Chtree.h" /* ----------------------------- STRUCT SECTION ----------------------------- */ /* ----------------------------- EXTERN SECTION ----------------------------- */ diff --git a/MechoSoma/RUNTIME/KEYS.CPP b/MechoSoma/RUNTIME/KEYS.CPP index 41b45c98..921e15ae 100644 --- a/MechoSoma/RUNTIME/KEYS.CPP +++ b/MechoSoma/RUNTIME/KEYS.CPP @@ -4,7 +4,7 @@ //#include "global.h" #pragma hdrstop -#include "keys.h" +#include "KEYS.H" #include "mch_common.h" // For far target @@ -19,7 +19,7 @@ void KBD_init(void) if(!KeyBuf) KeyBuf = new KeyBuffer; - XKey.init(key,unpress_key); + // XKey.init(key,unpress_key); } void key(int key) @@ -96,3 +96,12 @@ void KeyBuffer::quant(void) flag &= ~KBD_SHIFT_PRESSED; } +void KeyBuffer::copy(KeyBuffer* p) +{ + p->size = size; + p->table = table; + p->state_table = state_table; + p->flag = flag; + p->first_index = first_index; + p->last_index = last_index; +} diff --git a/MechoSoma/RUNTIME/LocalVersion.cpp b/MechoSoma/RUNTIME/LocalVersion.cpp index 7d8b1fc5..b725489c 100644 --- a/MechoSoma/RUNTIME/LocalVersion.cpp +++ b/MechoSoma/RUNTIME/LocalVersion.cpp @@ -22,7 +22,8 @@ char* getIniKey(char* fname,char* section,char* key); /* --------------------------- DEFINITION SECTION --------------------------- */ -static int lv_primaryLangID[] = +/* +static int lv_primaryLangID[] { LANG_AFRIKAANS, // 0 LANG_ALBANIAN, // 1 @@ -132,6 +133,7 @@ int win32_GetKeybLayoutID(void) return 2; } +*/ void lvInit(void) { diff --git a/MechoSoma/RUNTIME/SpriteDispatcher.cpp b/MechoSoma/RUNTIME/SpriteDispatcher.cpp index 0508df87..cc7b6ece 100644 --- a/MechoSoma/RUNTIME/SpriteDispatcher.cpp +++ b/MechoSoma/RUNTIME/SpriteDispatcher.cpp @@ -4,7 +4,7 @@ #include "SpriteDispatcher.h" #include "arcane_menu_d3d.h" -#include "scr_defs.h" +#include "SCR_DEFS.H" #include "aci_parser.h" #pragma warning( disable : 4244 ) diff --git a/MechoSoma/RUNTIME/TrackDispatcher.cpp b/MechoSoma/RUNTIME/TrackDispatcher.cpp index f46f2180..a36309ce 100644 --- a/MechoSoma/RUNTIME/TrackDispatcher.cpp +++ b/MechoSoma/RUNTIME/TrackDispatcher.cpp @@ -9,7 +9,7 @@ #include "aci_parser.h" #include "mch_script.h" -#include "terra.h" +#include "TERRA.H" #include "mch_common.h" // For far target @@ -144,7 +144,7 @@ mchTrackDispatcher::mchTrackDispatcher(void) { mchTrackInfo* tr; scrDataBlock* root,*p; - root = loadScript("RESOURCE\\mch_tracks.scb"); + root = loadScript("RESOURCE/mch_tracks.scb"); p = root -> nextLevel -> first(); while(p){ diff --git a/MechoSoma/RUNTIME/TrackRecorder.cpp b/MechoSoma/RUNTIME/TrackRecorder.cpp index aa60f144..626c7c92 100644 --- a/MechoSoma/RUNTIME/TrackRecorder.cpp +++ b/MechoSoma/RUNTIME/TrackRecorder.cpp @@ -5,7 +5,7 @@ #include "TrackRecorder.h" #include "race.h" -#include "terra.h" +#include "TERRA.H" #include "arcane_menu.h" #include "arcane_menu_d3d.h" diff --git a/MechoSoma/RUNTIME/arcane.cpp b/MechoSoma/RUNTIME/arcane.cpp index 0ec3e53c..94e03e7f 100644 --- a/MechoSoma/RUNTIME/arcane.cpp +++ b/MechoSoma/RUNTIME/arcane.cpp @@ -5,7 +5,7 @@ #include "arcane.h" #include "aci_parser.h" -#include "m3dsetup.h" +#include "M3DSETUP.H" #include "mch_common.h" // For far target diff --git a/MechoSoma/RUNTIME/arcane.h b/MechoSoma/RUNTIME/arcane.h index 401a41ee..36da3c29 100644 --- a/MechoSoma/RUNTIME/arcane.h +++ b/MechoSoma/RUNTIME/arcane.h @@ -2,7 +2,7 @@ #ifndef __ARCANE_H__ #define __ARCANE_H__ -#include "..\FX\fxlabInterface.h" +#include "fxlabInterface.h" enum mchArcaneID { ARC_STOP_TIME = 0, diff --git a/MechoSoma/RUNTIME/arcane_menu.cpp b/MechoSoma/RUNTIME/arcane_menu.cpp index a3e71e8c..5edafd34 100644 --- a/MechoSoma/RUNTIME/arcane_menu.cpp +++ b/MechoSoma/RUNTIME/arcane_menu.cpp @@ -2,7 +2,7 @@ #include "StdAfx.h" #include "iText.h" -#include "mch_rto.h" +#include "mch_rto.H" #include "mechosoma.h" #include "arcane.h" @@ -19,33 +19,34 @@ #include "LocalVersion.h" -#include "terra.h" -#include "mesh3ds.h" +#include "TERRA.H" +#include "Mesh3ds.h" #include "IGraph3d.h" -#include "hfont.h" -#include "tga.h" +#include "HFONT.H" +#include "TGA.H" -#include "scr_defs.h" -#include "aci_ids.h" +#include "SCR_DEFS.H" +#include "ACI_IDS.H" #include "aci_parser.h" -#include "aci_scr.h" +#include "ACI_SCR.H" #include "controls.h" #include "fxlabInterface.h" #include "savegame.h" -#include "md3d.h" +#include "Md3d.h" + #include "arcane_menu_d3d.h" #include "parts_pool.h" #include "demo_dispatcher.h" -#include "m3d_effects.h" +#include "M3d_effects.h" -#include "keys.h" -#include "chtree.h" +#include "KEYS.H" +#include "Chtree.h" #include "I-World.h" #include "TrackDispatcher.h" @@ -53,7 +54,9 @@ #include "online_game.h" +#ifdef _WIN32 #include "win32f.h" +#endif #pragma warning( disable : 4244 ) #pragma warning( disable : 4305 ) @@ -631,49 +634,49 @@ void mchArcaneScreenElement::InitCoords(char* name) XBuf.init(); XBuf < name < "_x"; - p = getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address()); + p = getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address()); if(strlen(p)) R.x = atoi(p); XBuf.init(); XBuf < name < "_y"; - p = getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address()); + p = getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address()); if(strlen(p)) R.y = atoi(p); XBuf.init(); XBuf < name < "_sx"; - p = getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address()); + p = getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address()); if(strlen(p)) SizeX = atoi(p); XBuf.init(); XBuf < name < "_sy"; - p = getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address()); + p = getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address()); if(strlen(p)) SizeY = atoi(p); XBuf.init(); XBuf < name < "_show_dir"; - p = getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address()); + p = getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address()); if(strlen(p)){ showDir = atoi(p); XBuf.init(); XBuf < name < "_show_idx"; - showIndex = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address())); + showIndex = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address())); if(showDir == 4){ XBuf.init(); XBuf < name < "_x0"; - R0.x = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address())); + R0.x = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address())); XBuf.init(); XBuf < name < "_y0"; - R0.y = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address())); + R0.y = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address())); } } XBuf.init(); XBuf < name < "_align_x"; - p = getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface",XBuf.address()); + p = getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface",XBuf.address()); if(strlen(p)){ align = atoi(p); if(align == 0) @@ -1957,18 +1960,18 @@ void mchInitArcaneScreen(void) mchA_Names = new xtList; - mchA_Alpha = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface","alpha")); + mchA_Alpha = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface","alpha")); - v = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface","alpha_hide_speed")); + v = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface","alpha_hide_speed")); mchA_AlphaHideSpeed = (256 - mchA_Alpha) / v; - v = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface","alpha_show_speed")); + v = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface","alpha_show_speed")); mchA_AlphaShowSpeed = (256 - mchA_Alpha) / v; - v = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface","menu_alpha_hide_speed")); + v = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface","menu_alpha_hide_speed")); mchA_MenuAlphaHideSpeed = (256 - mchA_Alpha) / v; - v = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface","menu_alpha_show_speed")); + v = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface","menu_alpha_show_speed")); mchA_MenuAlphaShowSpeed = (256 - mchA_Alpha) / v; mchA_MouseCrossBMP = new mchArcaneBMP("ARCANE\\ms_cross.bmp"); @@ -2073,7 +2076,8 @@ void mchInitArcaneScreen(void) p = new mchArcaneScreenElement; p -> type = AE_SEED_COUNTER; p -> InitCoords("seed_counter"); - p -> SetString(MCH_AM_SEED_COUNT_FNT,1,"999"); + char *t = "999"; + p -> SetString(MCH_AM_SEED_COUNT_FNT,1,t); p -> color = 7; p -> SetState(0); mch_arcScrD -> objList -> append(p); @@ -3895,8 +3899,8 @@ void mchA_ShowWorldMap(mchArcaneScreenElement* m) rp = mch_raceD -> racerLst -> first(); while(rp){ if(rp != mch_raceD -> activeRacer){ - x = (round(rp -> R().x) >> 4) / scale_delta - p -> SizeX/2; - y = (round(rp -> R().y) >> 4) / scale_delta - p -> SizeY/2; + x = (int(round(rp -> R().x)) >> 4) / scale_delta - p -> SizeX/2; + y = (int(round(rp -> R().y)) >> 4) / scale_delta - p -> SizeY/2; mchA_d3dOutSprite(m -> R.xi() + x + delta,m -> R.yi() + y + delta,1.0f,1.0f,AE_D3DSPR_MAP_POINTER,mchA_ColorF[4],256 - m -> Alpha); } rp = rp -> next; @@ -3905,15 +3909,15 @@ void mchA_ShowWorldMap(mchArcaneScreenElement* m) if(mchTimeMode == MCH_TIME_STOPPED){ v = camera_dispatcher -> observationPoint(); p = mchA_MapPointer[0]; - x = (round(v.x) >> 4) / scale_delta; - y = (round(v.y) >> 4) / scale_delta; + x = (int(round(v.x)) >> 4) / scale_delta; + y = (int(round(v.y)) >> 4) / scale_delta; mchA_d3dOutSprite(m -> R.xi() + x + delta,m -> R.yi() + y + delta,2.0f/16.0f,8.0f/16.0f,AE_D3DSPR_DUMMY,mchA_ColorF[7],256 - m -> Alpha,0,1); mchA_d3dOutSprite(m -> R.xi() + x + delta,m -> R.yi() + y + delta,2.0f/16.0f,8.0f/16.0f,AE_D3DSPR_DUMMY,mchA_ColorF[7],256 - m -> Alpha,M_PI/2.0f,1); } p = mchA_MapPointer[0]; - x = (round(rp0 -> R().x) >> 4) / scale_delta; - y = (round(rp0 -> R().y) >> 4) / scale_delta; + x = (int(round(rp0 -> R().x)) >> 4) / scale_delta; + y = (int(round(rp0 -> R().y)) >> 4) / scale_delta; mchA_d3dOutSprite(m -> R.xi() + x + delta,m -> R.yi() + y + delta,1.5f,1.5f,AE_D3DSPR_MAP_POINTER,mchA_ColorF[9],256 - m -> Alpha,0,1); mchA_d3dRectangleSq(m -> R.xi() + delta - 2,m -> R.yi() + delta - 2,132/scale_delta,132/scale_delta,1,256 - m -> Alpha); @@ -3933,8 +3937,8 @@ mchArcaneStatsDispatcher::mchArcaneStatsDispatcher(void) { int i; - X = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface","arc_stats_x")); - Y = atoi(getIniKey("RESOURCE\\ISCREEN\\iscreen.ini","world_interface","arc_stats_y")); + X = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface","arc_stats_x")); + Y = atoi(getIniKey("RESOURCE/ISCREEN/iscreen.ini","world_interface","arc_stats_y")); memset(statusFlags,0,5 * sizeof(int)); memset(racerIDs,0,5 * sizeof(int)); @@ -4437,9 +4441,12 @@ void mchA_DrawArrow(int x_,int y_,int sx,mchArcaneRacerSet* p) if(mchA_ArrowMesh){ mchA_ArrowMesh -> SetColor(1,1,1,1.0f); mchA_ArrowMesh -> SetScale(Vect3f(mchA_d3dResX * sc)); + + Vect3f v1(float(x_) * mchA_d3dResX,float(y_) * mchA_d3dResY,0.0f); + Vect3f v2(mchCameraAX + 40.0f,0,p -> arrowAngle * 180.0f / M_PI); gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)mchA_ArrowMesh, - &Vect3f(float(x_) * mchA_d3dResX,float(y_) * mchA_d3dResY,0.0f), - &Vect3f(mchCameraAX + 40.0f,0,p -> arrowAngle * 180.0f / M_PI)); + &v1, + &v2); mchA_DrawM3D(mchA_ArrowMesh); mchA_ArrowMesh -> SetScale(Vect3f(1,1,1)); mchA_ArrowMesh -> SetColor(1,1,1,1.0f); @@ -5331,9 +5338,12 @@ void mchA_DrawStar(int x,int y,float sz,float alpha) sz *= mchA_d3dResX; mchA_StarMesh -> SetScale(Vect3f(sz,sz,sz)); + + Vect3f v1((float)x * mchA_d3dResX,(float)y * mchA_d3dResY,0); + Vect3f v2(90,0,180.0f * mchA_Part_Angle / M_PI); gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)mchA_StarMesh, - &Vect3f((float)x * mchA_d3dResX,(float)y * mchA_d3dResY,0), - &Vect3f(90,0,180.0f * mchA_Part_Angle / M_PI)); + &v1, + &v2); mchA_DrawM3D(mchA_StarMesh); mchA_StarMesh -> SetScale(Vect3f(1,1,1)); @@ -5346,9 +5356,12 @@ void mchA_DrawSpeedStar(int x,int y,float sz) sz *= mchA_d3dResX; mchA_SpeedStarMesh -> SetScale(Vect3f(sz,sz,sz)); + + Vect3f v1((float)x * mchA_d3dResX,(float)y * mchA_d3dResY,0); + Vect3f v2(0,180.0f * mchA_Part_Angle / M_PI,0); gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)mchA_SpeedStarMesh, - &Vect3f((float)x * mchA_d3dResX,(float)y * mchA_d3dResY,0), - &Vect3f(0,180.0f * mchA_Part_Angle / M_PI,0)); + &v1, + &v2); mchA_DrawM3D(mchA_SpeedStarMesh); mchA_SpeedStarMesh -> SetScale(Vect3f(1,1,1)); @@ -6323,7 +6336,8 @@ mchArcaneRacerSet::mchArcaneRacerSet(void) starsEl -> align_x = AE_LEFT; starsEl -> align_y = AE_TOP; starsEl -> type = AE_STAR_COUNTER; - starsEl -> SetString(MCH_AM_STAR_COUNT_FNT,1,"99x99"); + char* t2 = "99x99"; + starsEl -> SetString(MCH_AM_STAR_COUNT_FNT,1,t2); starsEl -> color = 3; arrowEl = new mchArcaneScreenElement; @@ -6335,7 +6349,8 @@ mchArcaneRacerSet::mchArcaneRacerSet(void) speedEl -> type = AE_SPEED_COUNTER; speedEl -> align_x = AE_RIGHT; speedEl -> align_y = AE_TOP; - speedEl -> SetString(MCH_AM_STAR_COUNT_FNT,1,"99x99"); + char* t3 = "99x99"; + speedEl -> SetString(MCH_AM_STAR_COUNT_FNT,1,t3); speedEl -> color = 4; nameEl = new mchArcaneScreenElement; diff --git a/MechoSoma/RUNTIME/arcane_menu_d3d.cpp b/MechoSoma/RUNTIME/arcane_menu_d3d.cpp index b4654503..9e630b16 100644 --- a/MechoSoma/RUNTIME/arcane_menu_d3d.cpp +++ b/MechoSoma/RUNTIME/arcane_menu_d3d.cpp @@ -1,18 +1,18 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include "md3d.h" -#include "hfont.h" +#include "Md3d.h" +#include "HFONT.H" #include "hbm.h" -#include "base.h" +#include "Base.h" -#include "mch_rto.h" +#include "mch_rto.H" #include "arcane_menu.h" #include "arcane_menu_d3d.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "IGraph3d.h" #include "CameraDispatcher.h" @@ -562,7 +562,12 @@ void mchA_d3dSetClip(int x,int y,int sx,int sy) { // gb_IGraph3d->EndScene(); - RECT r = { round((float)x * mchA_d3dResX), round((float)y * mchA_d3dResY), round(float(x + sx) * mchA_d3dResX),round(float(y + sy) * mchA_d3dResY) }; + RECT r = { + LONG(round((float)x * mchA_d3dResX)), + LONG(round((float)y * mchA_d3dResY)), + LONG(round(float(x + sx) * mchA_d3dResX)), + LONG(round(float(y + sy) * mchA_d3dResY)) + }; if(!sx || !sy) return; d3dSetClipRect(&r); @@ -1019,4 +1024,3 @@ MD3DERROR mchA_d3dCreateChildSprite(int parent_id,int x,int y,int sx,int sy,int #endif return d3dCreateChildSprite(mchA_d3dSprParent[parent_id],x,y,sx,sy,&mchA_d3dSpr[child_id]); } - diff --git a/MechoSoma/RUNTIME/ctl_point.cpp b/MechoSoma/RUNTIME/ctl_point.cpp index 59566a66..dc8d1f61 100644 --- a/MechoSoma/RUNTIME/ctl_point.cpp +++ b/MechoSoma/RUNTIME/ctl_point.cpp @@ -3,7 +3,7 @@ #include "mechosoma.h" #include "ctl_point.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "arcane.h" #include "arcane_menu.h" @@ -13,7 +13,7 @@ #include "race.h" #include "sound.h" -#include "terra.h" +#include "TERRA.H" #include "mch_common.h" // For far target @@ -85,7 +85,9 @@ mchMouse3D::mchMouse3D(void) Visible = 0; position.set(0.f); m3dPtr = (cMesh*)gb_IVisGeneric -> CreateObject(M3D_KIND(M3D_MOUSE3D),M3D_TYPE(M3D_MOUSE3D)); - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)m3dPtr,&Vect3f(0,0,0),&Vect3f(0,0,0)); + Vect3f v1(0,0,0); + Vect3f v2(0,0,0); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)m3dPtr,&v1,&v2); } mchMouse3D::~mchMouse3D(void) @@ -96,7 +98,8 @@ void mchMouse3D::set(const Vect3f& pos) { position = pos; - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)m3dPtr, &position, &Vect3f(90,0,0)); + Vect3f v1(90,0,0); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)m3dPtr, &position, &v1); gb_IVisGeneric -> SetObjectVisible((cUnknownClass*)m3dPtr,0); if(mchTurnBasedGame && mchTimeMode == MCH_TIME_STOPPED && !camera_dispatcher -> isStartScenarioRunning() && !(mchGameFlags & MCH_START_TIME_FLAG)) @@ -200,8 +203,10 @@ void mchControlPoint::createObj(void) // if(mchDebugMode || mchTurnBasedGame){ if(mchDebugMode){ mPtr = (cMesh*)gb_IVisGeneric -> CreateObject(M3D_KIND(M3D_CONTROL_POINT),M3D_TYPE(M3D_CONTROL_POINT)); + Vect3f v1((float)PosX,(float)PosY,(float)PosZ); + Vect3f v2(0,0,0); gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)mPtr, - &Vect3f((float)PosX,(float)PosY,(float)PosZ),&Vect3f(0,0,0)); + &v1,&v2); mPtr -> SetAttribute(MESH_NOT_SHADE | MESH_LIGHTING_MAX); } } diff --git a/MechoSoma/RUNTIME/demo_dispatcher.cpp b/MechoSoma/RUNTIME/demo_dispatcher.cpp index a6daa8fa..d567f8cb 100644 --- a/MechoSoma/RUNTIME/demo_dispatcher.cpp +++ b/MechoSoma/RUNTIME/demo_dispatcher.cpp @@ -4,10 +4,10 @@ #include "mechosoma.h" #include "race.h" #include "CameraDispatcher.h" -#include "terra.h" +#include "TERRA.H" -#include "aci_ids.h" -#include "aci_scr.h" +#include "ACI_IDS.H" +#include "ACI_SCR.H" #include "TrackDispatcher.h" #include "demo_dispatcher.h" diff --git a/MechoSoma/RUNTIME/fcontainer.cpp b/MechoSoma/RUNTIME/fcontainer.cpp index e59b2a79..2000cd3b 100644 --- a/MechoSoma/RUNTIME/fcontainer.cpp +++ b/MechoSoma/RUNTIME/fcontainer.cpp @@ -1,8 +1,12 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ -#include "stdafx.h" +#include "StdAfx.h" -#include "fContainer.h" +#include "fcontainer.h" + +#ifndef _WIN32 +#define MAX_PATH 1024 +#endif /* ----------------------------- STRUCT SECTION ----------------------------- */ /* ----------------------------- EXTERN SECTION ----------------------------- */ diff --git a/MechoSoma/RUNTIME/intro.cpp b/MechoSoma/RUNTIME/intro.cpp index 2c8dc545..66c60419 100644 --- a/MechoSoma/RUNTIME/intro.cpp +++ b/MechoSoma/RUNTIME/intro.cpp @@ -8,7 +8,7 @@ #include "IGraph3d.h" -#include "hfont.h" +#include "HFONT.H" #include "hbm.h" #include "arcane_menu.h" diff --git a/MechoSoma/RUNTIME/intro_movie.cpp b/MechoSoma/RUNTIME/intro_movie.cpp index 2f40f1d0..214860e1 100644 --- a/MechoSoma/RUNTIME/intro_movie.cpp +++ b/MechoSoma/RUNTIME/intro_movie.cpp @@ -8,16 +8,20 @@ #include "sound.h" #include "PlayMpeg.h" -#include "md3d.h" +#include "Md3d.h" #include "iText.h" -#include "hFont.h" +#include "HFONT.H" #include "arcane_menu.h" #include "arcane_menu_d3d.h" #include "mch_common.h" // For far target +#ifndef _WIN32 +#define MAX_PATH 1024 +#endif + /* ----------------------------- STRUCT SECTION ----------------------------- */ /* ----------------------------- EXTERN SECTION ----------------------------- */ @@ -401,7 +405,7 @@ void mchIntroMovieDispatcher::init(void) mchIntroMovieImage* img; mchIntroMovieAction* acn; - root = loadScript("RESOURCE\\intro_movie.scb"); + root = loadScript("RESOURCE/intro_movie.scb"); p = root -> nextLevel -> first(); while(p){ switch(p -> ID){ diff --git a/MechoSoma/RUNTIME/mechosoma.cpp b/MechoSoma/RUNTIME/mechosoma.cpp index b7c34975..284d8ca6 100644 --- a/MechoSoma/RUNTIME/mechosoma.cpp +++ b/MechoSoma/RUNTIME/mechosoma.cpp @@ -5,27 +5,27 @@ #include "WinVideo.h" #include "iText.h" -#include "mch_rto.h" -#include "keys.h" +#include "mch_rto.H" +#include "KEYS.H" #include "controls.h" #include "ctl_point.h" -#include "terra.h" -#include "tga.h" +#include "TERRA.H" +#include "TGA.H" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "IGraph3d.h" #include "Xreal.h" #include "race.h" #include "intro.h" -#include "_xsound.h" +#include "xsound.h" #include "sound.h" #include "sound_api.h" -#include "aci_ids.h" -#include "aci_scr.h" +#include "ACI_IDS.H" +#include "ACI_SCR.H" #include "arcane_menu.h" #include "arcane_menu_d3d.h" #include "savegame.h" @@ -40,15 +40,19 @@ #include "TrackDispatcher.h" #include "TrackRecorder.h" -#include "xJoystick.h" +#include "XJoystick.h" #include "mechosoma.h" + +#ifdef _WIN32 #include "win32f.h" +#endif + #include "ResourceDispatcher.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "TexMgr.h" #include "GameClient.h" -#include "params.h" +#include "Params.h" #include "Statistics.h" #include "AllocationTracking.h" @@ -61,6 +65,20 @@ #include "mch_common.h" // For far target +#ifndef _WIN32 +#define TRUE 1 +#define FALSE 0 +#define MAX_PATH 1024 + +#define MK_LBUTTON 0x0001 +#define MK_RBUTTON 0x0002 + +#define DBGCHECK + +#include "Md3d.h" + +#endif + /* ----------------------------- EXTERN SECTION ----------------------------- */ extern vrtMap* vMap; @@ -365,8 +383,8 @@ int mchDetectJoystick = 0; int mch_readonlyINI = 0; char* mch_mainINI = "game.ini"; -char* mch_hotseatINI = "RESOURCE\\hotseat.ini"; -char* mch_optionsINI = "RESOURCE\\options.ini"; +char* mch_hotseatINI = "RESOURCE/hotseat.ini"; +char* mch_optionsINI = "RESOURCE/options.ini"; int mchDebugMode = 0; int mchDemoMode = 0; @@ -430,11 +448,12 @@ int xtInitApplication(void) if(mchPBEM_Game) wiInit(); - +#ifdef _WIN32 if(inHighPriority) win32_SetPriorityProcess(HIGH_PRIORITY_CLASS); else win32_SetPriorityProcess(NORMAL_PRIORITY_CLASS); +#endif // XCon < "MMX support "; // if(xt_mmxUse) XCon < "detected"; // else XCon < "is absent"; @@ -486,7 +505,7 @@ int xtInitApplication(void) mch_imageRTO -> SetNumFiles(2); mch_imageRTO -> SetFlag(0,IMG_RTO_INTRO_IMAGE | IMG_RTO_NO_IMAGE); // mch_imageRTO -> SetName("INTRO\\1c_logo.jpg",1); - mch_imageRTO -> SetName("INTRO\\splash.jpg",1); + mch_imageRTO -> SetName("INTRO/splash.jpg",1); mch_imageRTO -> SetFlag(1,IMG_RTO_START_MUSIC); quantRTO = gPtr; @@ -523,16 +542,32 @@ int xtInitApplication(void) dwScrX=1600,dwScrY=1200; break; } - if(xgrInitFlags&DIRECT3D_HICOLOR) { dwGraphMode=1; RenderMode = DIRECT3D_HICOLOR; XGR_Init(dwScrX,dwScrY,xgrInitFlags); } - else { dwGraphMode=0; RenderMode = XGRAPH_HICOLOR; XGR_Init(dwScrX,dwScrY,xgrInitFlags); } + + if(xgrInitFlags&DIRECT3D_HICOLOR){ + dwGraphMode = 1; + RenderMode = DIRECT3D_HICOLOR; + XGR_Init(dwScrX,dwScrY,xgrInitFlags); + } + else { + dwGraphMode = 0; + RenderMode = XGRAPH_HICOLOR; + XGR_Init(dwScrX,dwScrY,xgrInitFlags); + } + gb_IVisGeneric=CreateIVisGeneric(); gb_URenderDevice=gb_IVisGeneric->CreateGraph(dwScrX,dwScrY,dwGraphMode,xgrFullscreenMode,xgrColorDepth); gb_IGraph3d=gb_IVisGeneric->GetIGraph3d(gb_URenderDevice); - gb_IVisGeneric->SetGraphClipping(gb_URenderDevice, - &sRectangle4f(dwScrX*0.001f,dwScrX*0.001f,dwScrX*0.999f,dwScrY*0.999f)); + + { + sRectangle4f r1(dwScrX*0.001f,dwScrX*0.001f,dwScrX*0.999f,dwScrY*0.999f); + gb_IVisGeneric->SetGraphClipping(gb_URenderDevice,&r1); + } + #ifndef _DEBUG +#ifdef _WIN32 FreeConsole(); +#endif #endif allocation_tracking("xgrInit"); @@ -543,13 +578,28 @@ int xtInitApplication(void) gb_IVisGeneric->SetScene(gb_UScene); // уÑтановка активной Ñцены iCamera=gb_IVisGeneric->CreateCamera(); - gb_IVisGeneric->SetCameraPosition(iCamera,&Vect3f(0,0,512),&Vect3f(0,0,0),&Vect3f(0,0,512)); - gb_IVisGeneric->SetCameraFrustum(iCamera, // уÑтанавливаетÑÑ Ð¿Ð¸Ñ€Ð°Ð¼Ð¸Ð´Ð° видимоÑти - &Vect2f(0.5f,0.5f), // центр камеры - &sRectangle4f(-0.499f,-0.499f,0.499f,0.499f), // Ð²Ð¸Ð´Ð¸Ð¼Ð°Ñ Ð¾Ð±Ð»Ð°ÑÑ‚ÑŒ камеры - &Vect2f(1.0f,1.0f), // Ñ„Ð¾ÐºÑƒÑ ÐºÐ°Ð¼ÐµÑ€Ñ‹ - &Vect2f(10.0f,3000.0f), // ближайший и дальний z-плоÑкоÑти отÑÐµÑ‡ÐµÐ½Ð¸Ñ - &Vect2f(0.2f,0.90f)); // zNear и zFar Ð´Ð»Ñ Ð¼Ð°Ð¿Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð² zBuffer + + { + Vect3f v1(0,0,512); + Vect3f v2(0,0,0); + Vect3f v3(0,0,512); + gb_IVisGeneric->SetCameraPosition(iCamera,&v1,&v2,&v3); + } + + { + Vect2f v1(0.5f,0.5f); + sRectangle4f r1(-0.499f,-0.499f,0.499f,0.499f); + Vect2f v2(1.0f,1.0f); + Vect2f v3(10.0f,3000.0f); + Vect2f v4(0.2f,0.90f); + gb_IVisGeneric->SetCameraFrustum(iCamera, // уÑтанавливаетÑÑ Ð¿Ð¸Ñ€Ð°Ð¼Ð¸Ð´Ð° видимоÑти + &v1, // центр камеры + &r1, // Ð²Ð¸Ð´Ð¸Ð¼Ð°Ñ Ð¾Ð±Ð»Ð°ÑÑ‚ÑŒ камеры + &v2, // Ñ„Ð¾ÐºÑƒÑ ÐºÐ°Ð¼ÐµÑ€Ñ‹ + &v3, // ближайший и дальний z-плоÑкоÑти отÑÐµÑ‡ÐµÐ½Ð¸Ñ + &v4); // zNear и zFar Ð´Ð»Ñ Ð¼Ð°Ð¿Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð² zBuffer + } + gb_IVisGeneric->AttachCameraViewPort(iCamera,gb_URenderDevice); gameWnd = new mchGameWindow; @@ -577,15 +627,15 @@ int xtInitApplication(void) CONTROL_FP(); if(mchOpenNewChar) - gb_IVisGeneric->LoadObjectLibrary("RESOURCE\\m3d_n.scb"); + gb_IVisGeneric->LoadObjectLibrary("RESOURCE/m3d_n.scb"); else - gb_IVisGeneric->LoadObjectLibrary("RESOURCE\\m3d.scb"); + gb_IVisGeneric->LoadObjectLibrary("RESOURCE/m3d.scb"); - gb_IVisGeneric->LoadObjectLibrary("RESOURCE\\m3d_eff.scb"); - gb_IVisGeneric->LoadObjectLibrary("RESOURCE\\m3d_Xreal.scb"); - gb_IVisGeneric->LoadObjectLibrary("RESOURCE\\m3d_font.scb"); - gb_IVisGeneric->LoadObjectLibrary("RESOURCE\\m3d_font_add.scb"); - gb_IVisGeneric->LoadObjectLibrary("RESOURCE\\m3d_iscreen.scb"); + gb_IVisGeneric->LoadObjectLibrary("RESOURCE/m3d_eff.scb"); + gb_IVisGeneric->LoadObjectLibrary("RESOURCE/m3d_Xreal.scb"); + gb_IVisGeneric->LoadObjectLibrary("RESOURCE/m3d_font.scb"); + gb_IVisGeneric->LoadObjectLibrary("RESOURCE/m3d_font_add.scb"); + gb_IVisGeneric->LoadObjectLibrary("RESOURCE/m3d_iscreen.scb"); allocation_tracking("LoadObjectLibrary"); camera_dispatcher = new CameraDispatcher(gb_URenderDevice); @@ -638,11 +688,11 @@ void xtDoneApplication(void) if(!mchMusicMute) sndMusicStop(); mchFinitSound(); +#ifdef _WIN32 #ifdef _FINAL_VERSION_ if(mchFeedbackFlag) win32_shell_execute(iGetText(iTXT_MAILTO)); #endif - if(mchPBEM_Game){ wiFinit(); @@ -654,6 +704,7 @@ void xtDoneApplication(void) if(strlen(iGetText(iTXT_ONLINE_URL))) win32_shell_execute(iGetText(iTXT_ONLINE_URL)); } +#endif } void GameQuantRTO::Init(int id) @@ -1170,6 +1221,7 @@ void MainMenuRTO::Finit(void) void mchComline(void) { +#ifdef _WIN32 int i,num = __argc; char** p = __argv; @@ -1381,6 +1433,7 @@ void mchComline(void) //mch_RealRnd = 0; } #endif +#endif } void mchKeyTrap(void) @@ -2565,7 +2618,7 @@ void ShowImageRTO::Init(int id) } mchA_d3dLockBackBuffer(); - XKey.init(mchShowImageKeyPress,NULL); + XKey.init((void *)&mchShowImageKeyPress,NULL); XGR_MouseInit(XGR_MAXX/2,XGR_MAXY/2,0,0,1,NULL); XGR_MouseHide(); XGR_MouseSetPressHandler(XGM_LEFT_BUTTON,mchShowImageMousePress); @@ -2928,8 +2981,10 @@ void XrealEvolveQuant() global_time.next_frame(); #ifndef _FINAL_VERSION_ if(xreal_log){ +#ifdef _WIN32 bout < "controlfp: " <= _controlfp( 0, 0 ) < "\n"; bout < "XrealEvolveQuant: " <= global_time() < "\n"; +#endif } #endif Mdisp -> evolve_quant(); @@ -3423,6 +3478,7 @@ void LoadingRTO::Init(int id) mchA_PrepareLoadingImage(mchCurrentWorld,mchCurrentTrack); startTimer = clocki(); +#ifdef _WIN32 if(mchPBEM_DataFlag){ wi_D.connect(wiServerName,wiServerPort); @@ -3446,6 +3502,7 @@ void LoadingRTO::Init(int id) wi_D.open_request(WI_POST,wiGameURL,header,strlen(header),wi_D.output_buffer(),wi_D.output_size()); } } +#endif } int LoadingRTO::Quant(void) @@ -3465,6 +3522,7 @@ int LoadingRTO::Quant(void) if(d3dIsActive()) mchA_d3dFlushBackBuffer(0,0,XGR_MAXX,XGR_MAXY); +#ifdef _WIN32 if(mchPBEM_DataFlag){ ogQuant(); @@ -3486,6 +3544,7 @@ int LoadingRTO::Quant(void) if(v >= 255) gb_IGraph3d->Flush(); } +#endif if(v < 255){ gb_IGraph3d->BeginScene(); diff --git a/MechoSoma/RUNTIME/og_buffer.cpp b/MechoSoma/RUNTIME/og_buffer.cpp index 9ccdf9d2..3f94b39f 100644 --- a/MechoSoma/RUNTIME/og_buffer.cpp +++ b/MechoSoma/RUNTIME/og_buffer.cpp @@ -1,11 +1,15 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include -#include +#include +#include #include "online_game.h" +#ifndef _WIN32 +#include "port.h" +#endif + /* ----------------------------- STRUCT SECTION ----------------------------- */ /* ----------------------------- EXTERN SECTION ----------------------------- */ /* --------------------------- PROTOTYPE SECTION ---------------------------- */ @@ -100,42 +104,42 @@ ogBuffer& ogBuffer::operator< (unsigned char var) ogBuffer& ogBuffer::operator< (short var) { - char* s = itoa(var,wiConvertBuffer,radix); + char* s = port_itoa(var,wiConvertBuffer,radix); write(s,strlen(s)); return *this; } ogBuffer& ogBuffer::operator< (unsigned short var) { - char* s = ltoa(var,wiConvertBuffer,radix); + char* s = port_ltoa(var,wiConvertBuffer,radix); write(s,strlen(s)); return *this; } ogBuffer& ogBuffer::operator< (int var) { - char* s = itoa(var,wiConvertBuffer,radix); + char* s = port_itoa(var,wiConvertBuffer,radix); write(s,strlen(s)); return *this; } ogBuffer& ogBuffer::operator< (unsigned var) { - char* s = ultoa(var,wiConvertBuffer,radix); + char* s = port_ultoa(var,wiConvertBuffer,radix); write(s,strlen(s)); return *this; } ogBuffer& ogBuffer::operator< (long var) { - char* s = ltoa(var,wiConvertBuffer,radix); + char* s = port_ltoa(var,wiConvertBuffer,radix); write(s,strlen(s)); return *this; } ogBuffer& ogBuffer::operator< (unsigned long var) { - char* s = ultoa(var,wiConvertBuffer,radix); + char* s = port_ultoa(var,wiConvertBuffer,radix); write(s,strlen(s)); return *this; } diff --git a/MechoSoma/RUNTIME/parts_pool.cpp b/MechoSoma/RUNTIME/parts_pool.cpp index 47d0919a..2158e4fd 100644 --- a/MechoSoma/RUNTIME/parts_pool.cpp +++ b/MechoSoma/RUNTIME/parts_pool.cpp @@ -1,9 +1,9 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include "dispatcher.h" +#include "Dispatcher.h" -#include "Mechosoma.h" +#include "mechosoma.h" #include "parts_pool.h" #include "mch_common.h" // For far target diff --git a/MechoSoma/RUNTIME/race.cpp b/MechoSoma/RUNTIME/race.cpp index b783b1a9..1667d48c 100644 --- a/MechoSoma/RUNTIME/race.cpp +++ b/MechoSoma/RUNTIME/race.cpp @@ -7,17 +7,17 @@ #include "demo_dispatcher.h" #include "TrackDispatcher.h" #include "TrackRecorder.h" -#include "mesh3ds.h" -#include "xreal.h" -#include "params.h" -#include "terra.h" +#include "Mesh3ds.h" +#include "Xreal.h" +#include "Params.h" +#include "TERRA.H" #include "arcane.h" #include "arcane_menu.h" #include "sound.h" #include "iText.h" -#include "keys.h" +#include "KEYS.H" #include "controls.h" #include "CameraDispatcher.h" @@ -26,12 +26,12 @@ #include "track.h" -#include "aci_ids.h" +#include "ACI_IDS.H" #include "aci_parser.h" -#include "m3dsetup.h" +#include "M3DSETUP.H" #include "parts_pool.h" -#include "scr_defs.h" +#include "SCR_DEFS.H" #include "ai_arcane.h" @@ -41,9 +41,11 @@ #include "mch_script.h" #include "savegame.h" -#include "statistics.h" +#include "Statistics.h" +#ifdef _WIN32 #include "online_game.h" +#endif #include "cdcheck.h" @@ -3320,8 +3322,11 @@ void mchRacer::MoveSeed(int x,int y,int z) mouseSeed -> PosZ = z; if(mouseSeed -> mPtr) - gb_IVisGeneric->SetObjectPosition((cUnknownClass*)mouseSeed -> mPtr, - &Vect3f((float)mouseSeed -> PosX,(float)mouseSeed -> PosY,(float)mouseSeed -> PosZ),&Vect3f(0,0,0)); + { + Vect3f v1((float)mouseSeed -> PosX,(float)mouseSeed -> PosY,(float)mouseSeed -> PosZ); + Vect3f v2(0,0,0); + gb_IVisGeneric->SetObjectPosition((cUnknownClass*)mouseSeed -> mPtr,&v1,&v2); + } } void mchRacer::NextSeed(void) @@ -3752,14 +3757,14 @@ void mchInitWorldsPrm(void) void mchRacer::SetTractionPrm(int fl,float v) { - set_traction_by_distance = fl; // çàâèñèìîñòü îò ðàññòîÿíèÿ ìåæäó ñåìåíàìè - traction_modulation = v; // 0..2 - ìîäóëÿöèÿ òÿãè + set_traction_by_distance = fl; // ����������� �� ���������� ����� �������� + traction_modulation = v; // 0..2 - ��������� ���� } void mchRacer::GetTractionPrm(int& fl,float& v) { - fl = set_traction_by_distance; // çàâèñèìîñòü îò ðàññòîÿíèÿ ìåæäó ñåìåíàìè - v = traction_modulation; // 0..2 - ìîäóëÿöèÿ òÿãè + fl = set_traction_by_distance; // ����������� �� ���������� ����� �������� + v = traction_modulation; // 0..2 - ��������� ���� } void mchRacerStats::ReplacePart(int pt) @@ -4244,6 +4249,7 @@ void mchRaceDispatcher::KeyTrap(void) if(mch_trkRec) mch_trkRec -> KeyTrap(k); +#ifdef _WIN32 if(k == VK_SPACE){ if(mchGameMode == MCH_ENTIRE_CONTROL_HS && mchPBEM_Game){ if(mchTimeMode == MCH_TIME_WAITING_TURN && !(activeRacer -> flags & MCH_FINISHED) && mchPBEM_CheckFlag(PBEM_DATA_SENT) && og_inP.express_game()){ @@ -4278,6 +4284,7 @@ void mchRaceDispatcher::KeyTrap(void) firstRacer(mchPBEM_CurPlayer); } } +#endif id = mchGetKeyID_First(k); @@ -4318,8 +4325,8 @@ void mchRaceDispatcher::KeyTrap(void) break; case MCH_KEY_START_TIME: if(!mchTurnBasedGame) break; - if(mchGameMode == MCH_ENTIRE_CONTROL_HS && mchPBEM_Game){ +#ifdef _WIN32 if(mchPBEM_GameMode == MCH_PBEM_REPLAY_TURN && (mchTimeMode == MCH_TIME_RUNNING || mchPBEM_Pause)){ if(!mchPBEM_Pause){ mchGameFlags |= MCH_STOP_TIME_FLAG | MCH_TOGGLE_PAUSE_FLAG; @@ -4350,6 +4357,7 @@ void mchRaceDispatcher::KeyTrap(void) ogSetRefreshTime(); } } +#endif } else { if(mchTimeMode == MCH_TIME_STOPPED && (activeRacer -> seedLst.size() || activeRacer -> flags & MCH_AI)) @@ -4826,6 +4834,7 @@ void mchRacer::SetPointControl(void) int mchRaceDispatcher::online_checkEndGame(void) { +#ifdef _WIN32 int num_not_finished_humans; mchRacer* p; ogPlayerInfo* pl; @@ -4891,6 +4900,7 @@ int mchRaceDispatcher::online_checkEndGame(void) } return 0; +#endif } void mchRaceDispatcher::InitReplay(int all_flag) diff --git a/MechoSoma/RUNTIME/resource.cpp b/MechoSoma/RUNTIME/resource.cpp index 58aad43b..30cf73e1 100644 --- a/MechoSoma/RUNTIME/resource.cpp +++ b/MechoSoma/RUNTIME/resource.cpp @@ -21,9 +21,9 @@ XZIP_Resource* mch_vmapRes = NULL; #endif int mchUseContainer = 0; -char* acsResourceDir = "RESOURCE\\ISCREEN\\"; -char* acsResourceDirL = "RESOURCE\\ISCREEN\\RES_LOW\\"; -char* acsResourceDirH = "RESOURCE\\ISCREEN\\RES_HIGH\\"; +char* acsResourceDir = "RESOURCE/ISCREEN/"; +char* acsResourceDirL = "RESOURCE/ISCREEN/RES_LOW/"; +char* acsResourceDirH = "RESOURCE/ISCREEN/RES_HIGH/"; XBuffer mch_ResXBuf; int acsOpenResource(char* fname,XStream& fh,int res_flag) @@ -71,7 +71,7 @@ void mchXResourceInit(void) { #ifdef _XRESOURCE_ if(mchUseContainer){ - mchRes = new XZIP_Resource("RESOURCE\\resource.pak",XZIP_ENABLE_ZIP_HEADERS); + mchRes = new XZIP_Resource("RESOURCE/resource.pak",XZIP_ENABLE_ZIP_HEADERS); } #endif } diff --git a/MechoSoma/RUNTIME/setup.cpp b/MechoSoma/RUNTIME/setup.cpp index ed8d2831..da063926 100644 --- a/MechoSoma/RUNTIME/setup.cpp +++ b/MechoSoma/RUNTIME/setup.cpp @@ -2,13 +2,13 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include "_xsound.h" +#include "xsound.h" #include "mechosoma.h" #include "aci_parser.h" -#include "aci_evnt.h" -#include "aci_ids.h" -#include "aci_scr.h" +#include "ACI_EVNT.H" +#include "ACI_IDS.H" +#include "ACI_SCR.H" #include "sound.h" #include "sound_api.h" @@ -16,15 +16,22 @@ #include "arcane_menu_d3d.h" -#include "maths.h" -#include "base.h" -#include "mesh3ds.h" +#include "Maths.h" +#include "Base.h" +#include "Mesh3ds.h" +#ifdef _WIN32 #include "wininet_api.h" #include "online_game.h" +#else +#define _MAX_PATH 1024 +#define MAX_PATH 1024 +#include "filesystem.h" +#include "port.h" +#endif #include "CameraDispatcher.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "mch_common.h" // For far target @@ -121,7 +128,7 @@ void mchA_d3dSetGamma(float v); /* --------------------------- DEFINITION SECTION --------------------------- */ -// HotSeat ïàðàìåòðû +// HotSeat ��������� int hsStartAssembled = 1; int hsTurnSeedsMax = 5; int hsWaitTurnTime = 100; @@ -192,24 +199,25 @@ char* getIniKey(char* fname,char* section,char* key) char* p = NULL; static char buf[256]; - static char path[_MAX_PATH]; if(!xINI_InitFlag) xINI_Init(); - if(_fullpath(path,fname,_MAX_PATH) == NULL) ErrH.Abort("Invalid path..."); + const auto path = file::normalize_path(fname); if(xINI_Enable){ - p = xINI_GetKey(path,section,key); + p = xINI_GetKey(path.c_str(),section,key); if(p) strcpy(buf,p); else *buf = 0; } +#ifdef _WIN32 if(!p){ if(!GetPrivateProfileString(section,key,NULL,buf,256,path)) *buf = 0; } +#endif return buf; } @@ -238,8 +246,10 @@ void putIniKey(char* fname,char* section,char* key,char* val) if(xINI_Enable) flag = xINI_PutKey(path,section,key,val); +#ifdef _WIN32 if(!flag) WritePrivateProfileString(section,key,val,path); +#endif } void mchSetup(void) @@ -258,9 +268,11 @@ void mchSetup(void) xgrColorDepth = 16 + 16 * flag; } +#ifdef _WIN32 wiServerPort = atoi(getIniKey(mch_mainINI,"online","server_port")); wiServerName = strdup(getIniKey(mch_mainINI,"online","server")); wiGameURL = strdup(getIniKey(mch_mainINI,"online","url")); +#endif mchPBEM_DisableReturnFlag = atoi(getIniKey(mch_mainINI,"online","disable_return")); @@ -687,6 +699,7 @@ void mchOptionData::Update(void) void hsOnlineSetup(void) { +#ifdef _WIN32 int i; ogPlayerInfo* p; @@ -738,10 +751,12 @@ void hsOnlineSetup(void) // if(mchPBEM_CurPlayer == -1) // mchPBEM_CurPlayer = 0; +#endif } void cdCheck(char* f0,char* f1) { +#ifdef _WIN32 char* str = new char[MAX_PATH]; char* label = new char[64]; char* system = new char[64]; @@ -772,4 +787,5 @@ void cdCheck(char* f0,char* f1) delete str; delete label; delete system; +#endif } diff --git a/MechoSoma/RUNTIME/tga.cpp b/MechoSoma/RUNTIME/tga.cpp index 59ac965f..473ed96f 100644 --- a/MechoSoma/RUNTIME/tga.cpp +++ b/MechoSoma/RUNTIME/tga.cpp @@ -2,7 +2,7 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include "tga.h" +#include "TGA.H" #include "mch_common.h" // For far target diff --git a/MechoSoma/RUNTIME/track.cpp b/MechoSoma/RUNTIME/track.cpp index fb03bf9a..c8eed51c 100644 --- a/MechoSoma/RUNTIME/track.cpp +++ b/MechoSoma/RUNTIME/track.cpp @@ -2,14 +2,14 @@ #include "StdAfx.h" #include "track.h" -#include "terra.h" +#include "TERRA.H" #include "TrackRecorder.h" #include "mechosoma.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #ifdef _FCONTAINER_LOAD_ -#include "fContainer.h" +#include "fcontainer.h" #endif #include "mch_common.h" // For far target diff --git a/MechoSoma/RUNTIME/wininet_api_port.cpp b/MechoSoma/RUNTIME/wininet_api_port.cpp new file mode 100644 index 00000000..5b215131 --- /dev/null +++ b/MechoSoma/RUNTIME/wininet_api_port.cpp @@ -0,0 +1,104 @@ + +/* ---------------------------- INCLUDE SECTION ----------------------------- */ + +#include "StdAfx.h" + +#include + +#include "wininet_api.h" +#include "Xreal_utl.h" + +/* ----------------------------- STRUCT SECTION ----------------------------- */ + +typedef struct +{ + int status; +} REQUEST_CONTEXT; + +/* ----------------------------- EXTERN SECTION ----------------------------- */ +/* --------------------------- PROTOTYPE SECTION ---------------------------- */ + +/* --------------------------- DEFINITION SECTION --------------------------- */ + +char* wiServerName = NULL; +char* wiGameURL = NULL; +int wiServerPort = 8500; + +wiDispatcher wi_D; + +void* wiCritical = NULL; + +void wiInit(void) +{ +} + +void wiFinit(void) +{ +} + +wiDispatcher::wiDispatcher(void) +{ +} + +wiDispatcher::~wiDispatcher(void) +{ +} + +void wiDispatcher::expand_inbuf(int sz) +{ +} + +void wiDispatcher::alloc_inbuf(int sz) +{ +} + +void wiDispatcher::free_inbuf(void) +{ +} + +void wiDispatcher::alloc_outbuf(int sz) +{ +} + +void wiDispatcher::free_outbuf(void) +{ +} + +int wiDispatcher::connect(char* server,unsigned int port) +{ + return 0; +} + +void wiDispatcher::disconnect(void) +{ +} + +int wiDispatcher::open_request(int action,char* obj,char* header,int header_len,char* data,int data_len) +{ + return 1; +} + +void wiDispatcher::close_request(void) +{ +} + +void wiDispatcher::quant(void) +{ +} + +int wiDispatcher::get_request_status(void) +{ + return 0; +} + +char* wiDispatcher::get_request_status_str(void) +{ +} + +wiCriticalSection::wiCriticalSection(void* section) +{ +} + +wiCriticalSection::~wiCriticalSection(void) +{ +} diff --git a/MechoSoma/RUNTIME/xINI.cpp b/MechoSoma/RUNTIME/xINI.cpp index 34674fc9..0243958a 100644 --- a/MechoSoma/RUNTIME/xINI.cpp +++ b/MechoSoma/RUNTIME/xINI.cpp @@ -32,13 +32,10 @@ void xINI_Init(void) xINI_File* p; xINI_List = new xtList; -/* +#ifndef _WIN32 p = new xINI_File("game.ini"); xINI_List -> append(p); - p = new xINI_File("RESOURCE\\bots.ini"); - xINI_List -> append(p); - p = new xINI_File("RESOURCE\\options.ini"); xINI_List -> append(p); @@ -47,7 +44,7 @@ void xINI_Init(void) p = new xINI_File("RESOURCE\\ISCREEN\\iscreen.ini"); xINI_List -> append(p); -*/ +#endif p = new xINI_File("RESOURCE\\ISCREEN\\local.ini"); xINI_List -> append(p); diff --git a/MechoSoma/RUNTIME/xINI_File.cpp b/MechoSoma/RUNTIME/xINI_File.cpp index a5dca6dc..f4d5a337 100644 --- a/MechoSoma/RUNTIME/xINI_File.cpp +++ b/MechoSoma/RUNTIME/xINI_File.cpp @@ -8,7 +8,16 @@ /* --------------------------- PROTOTYPE SECTION ---------------------------- */ /* --------------------------- DEFINITION SECTION --------------------------- */ +#ifdef _WIN32 #define _xINI_BINARY_ONLY_ +#endif + +#ifndef _WIN32 +#define _MAX_PATH 1024 +#include "filesystem.h" +#include "iniparser.h" +#include "port.h" +#endif void xINI_FileKey::putValue(const char* p) { @@ -81,11 +90,9 @@ void xINI_FileSection::putKey(const char* key_name,const char* key_value) xINI_File::xINI_File(const char* nm) { - char path[_MAX_PATH]; + const auto path = file::normalize_path(nm); - if(_fullpath(path,nm,_MAX_PATH) == NULL) ErrH.Abort("Invalid INI path..."); - - name = strdup(path); + name = strdup(path.c_str()); list = NULL; } @@ -151,7 +158,8 @@ void xINI_File::save_text(char* fname) void xINI_File::load(void) { - if(is_binary()) + isBinary = is_binary(); + if(isBinary) load_binary(); #ifndef _xINI_BINARY_ONLY_ else @@ -159,6 +167,16 @@ void xINI_File::load(void) #endif } +void xINI_File::save(void) +{ + if(isBinary){ + save_binary(name); + pack(); + } else { + save_text(name); + } +} + void xINI_File::load_binary(void) { int i,sz; @@ -189,6 +207,7 @@ void xINI_File::load_binary(void) void xINI_File::load_text(void) { +#ifdef _WIN32 int sz; char* buf,*vbuf,*p; @@ -234,6 +253,31 @@ void xINI_File::load_text(void) delete buf; delete vbuf; +#else + xINI_FileSection* sp; + + const auto fileObject = iniparser_load(name); + const auto sectionsNumber = iniparser_getnsec(fileObject); + + for(int i = 0; i < sectionsNumber; i++){ + const auto sectionName = iniparser_getsecname(fileObject, i); + sp = new xINI_FileSection(sectionName); + + const auto keysNumber = iniparser_getsecnkeys(fileObject, sectionName); + std::vector keys(keysNumber); + iniparser_getseckeys(fileObject, sectionName, &keys[0]); + + for(const auto key : keys){ + const auto p = strstr(key, ":"); + if(p == nullptr){ + continue; + } + sp -> putKey(p + 1, iniparser_getstring(fileObject, key, "")); + } + + sectionList.append(sp); + } +#endif } void xINI_FileSection::save(XStream& fh,int binary) diff --git a/MechoSoma/RUNTIME/xINI_File.h b/MechoSoma/RUNTIME/xINI_File.h index 1e95cf45..dc471887 100644 --- a/MechoSoma/RUNTIME/xINI_File.h +++ b/MechoSoma/RUNTIME/xINI_File.h @@ -59,6 +59,7 @@ class xINI_FileSection class xINI_File { char* name; + bool isBinary; xtList sectionList; void load_text(void); @@ -73,7 +74,7 @@ class xINI_File char* getName(void) const { return name; } void load(void); - void save(void){ save_binary(name); pack(); } + void save(void); void save_text(char* fname); void save_binary(char* fname); diff --git a/MechoSoma/Sound/MpegSound_port.cpp b/MechoSoma/Sound/MpegSound_port.cpp new file mode 100644 index 00000000..729d9a0d --- /dev/null +++ b/MechoSoma/Sound/MpegSound_port.cpp @@ -0,0 +1,55 @@ +#include "PlayMpeg.h" + +bool MpegInitLibrary(void* LPDIRECTSOUND_pDS) +{ + return true; +} + +void MpegDeinitLibrary() +{ +} + +MpegSound::MpegSound() +{ +} + +MpegSound::~MpegSound() +{ +} + +bool MpegSound::OpenToPlay(const char* fname,bool cycled) +{ + return true; +} + +void MpegSound::Stop() +{ +} + +void MpegSound::Pause() +{ +} + +void MpegSound::Resume() +{ +} + +MpegState MpegSound::IsPlay() +{ + return MPEG_STOP; +} + +void MpegSound::SetVolume(int volume) +{ + +} + +int MpegSound::GetVolume() +{ + return 0; +} + +int MpegSound::GetLen() +{ + return -1; +} diff --git a/MechoSoma/Sound/PlayMpeg.h b/MechoSoma/Sound/PlayMpeg.h index 16244cfc..9593f836 100644 --- a/MechoSoma/Sound/PlayMpeg.h +++ b/MechoSoma/Sound/PlayMpeg.h @@ -5,10 +5,19 @@ //#include "dsound.h" +#ifndef _WIN32 +#include +typedef const char *LPCSTR; +typedef void *LPVOID; +typedef uint32_t DWORD; +#define WINAPI +#define NULL 0 +#endif + #define MPP_STAT #ifdef MPP_STAT double MpegCPUUsing();//Âîçâðàùàåò èñïîëüçóåìîå íà ïðîèãðûâàíèå Mpeg âðåìÿ (1 - âñ¸ âðåìÿ çàãðóçêè) -#endif MPP_STAT +#endif // MPP_STAT // bool MpegInitLibrary(void* LPDIRECTSOUND_pDS); diff --git a/MechoSoma/Sound/StdAfx.cpp b/MechoSoma/Sound/StdAfx.cpp deleted file mode 100644 index 47ffd96b..00000000 --- a/MechoSoma/Sound/StdAfx.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "StdAfx.h" -void dprintf(char *format, ...) -{ - va_list args; - char buffer[512]; - - va_start(args,format); - - strcpy(buffer + vsprintf(buffer,format,args), "\r\n"); - - OutputDebugString(buffer); -} - -void ERRORM(BOOL b,char *format, ...) -{ - if(b)return; -// if(g_pDD)g_pDD->FlipToGDISurface(); - va_list args; - char buffer[512]; - va_start(args,format); - strcpy(buffer + vsprintf(buffer,format,args), "\r\n"); - OutputDebugString(buffer); - - MessageBox(g_hWnd, buffer, "Game", MB_OK|MB_ICONSTOP|MB_APPLMODAL); - exit(0); -} - -char TEXTMSG[1024]; -int __cdecl AssertFail(char szErr[], char szFileName[], int nLine, char szMessage[]) -{ -// if(g_pDD)g_pDD->FlipToGDISurface(); - - if (szMessage != NULL) - wsprintf(TEXTMSG, "Assert(%s);\nFile %s, line %d. %s", szErr, szFileName, nLine, szMessage); - else - wsprintf(TEXTMSG, "Assert(%s);\nFile %s, line %d.", szErr, szFileName, nLine); - switch (MessageBox(g_hWnd, TEXTMSG, "Game", MB_ABORTRETRYIGNORE | MB_ICONSTOP | MB_APPLMODAL)) - { - case IDABORT: - exit(0); - return 2; - case IDRETRY: -// if(FullScreen && g_pDD) -// g_pDD->SetCooperativeLevel(g_hWnd , DDSCL_NORMAL); - return 1; - // Fall Through // - case IDIGNORE: - return 0; - } // switch - return 0; -} // AssertFail diff --git a/MechoSoma/Sound/StdAfx.h b/MechoSoma/Sound/StdAfx.h deleted file mode 100644 index cfb028e0..00000000 --- a/MechoSoma/Sound/StdAfx.h +++ /dev/null @@ -1,44 +0,0 @@ -#include - -extern HWND g_hWnd; - -#define _NOSTD_ - -void dprintf(char *format, ...); - -//õ¸ûø b=false òvòþôøª ¸þþñ•õýøõ ø òv¿þôøª ø÷ ÿ¨þó¨ðüüv -void ERRORM(BOOL b, char *format=NULL, ...); - -int __cdecl AssertFail(char szErr[], char szFileName[], int nLine, char szMessage[]); -#define MDebugBreak() __asm { int 3 } -#define ASSERT(f) \ - do {\ - if(!(f))\ - {\ - if(AssertFail(#f, __FILE__, __LINE__,NULL))\ - {\ - MDebugBreak();\ - }\ - }\ - } while(0) -#define VERIFY(x) ASSERT(x) - -#include "..\TextConverter\parse\paramblock.h" - -#ifndef _DEBUG -#undef ASSERT -#undef VERIFY -#define ASSERT( expr ) ( (void)0 ) -#define VERIFY(x) (x) -#endif _DEBUG - - -#include - -#include "array.h" - -#define SIZE(ar) (sizeof(ar)/sizeof(ar[0])) - -#define PI 3.14159265358979323846 -inline int round(double x){return (int)(x+0.5);} -inline float frand(){return rand()/(float)RAND_MAX;} diff --git a/MechoSoma/Sound/sound.cpp b/MechoSoma/Sound/sound.cpp index aa0b938c..6637604e 100644 --- a/MechoSoma/Sound/sound.cpp +++ b/MechoSoma/Sound/sound.cpp @@ -2,10 +2,12 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include +#include + #include "mechosoma.h" -#include "md3d.h" -#include "_xsound.h" +#include "Md3d.h" +#include "xsound.h" #include "aci_parser.h" #include "sound.h" @@ -494,9 +496,9 @@ void mchSoundDispatcher::Load(char* scr_name,int local) eff = lst -> first(); while(eff){ if(local) - map_localEFF.insert(hash_multimap::value_type(eff -> ID,eff)); + map_localEFF.insert(std::unordered_multimap::value_type(eff -> ID,eff)); else - map_globalEFF.insert(hash_multimap::value_type(eff -> ID,eff)); + map_globalEFF.insert(std::unordered_multimap::value_type(eff -> ID,eff)); eff -> Load(); eff = eff -> next; @@ -545,8 +547,8 @@ void mchSoundDispatcher::StartEFF(int id,int x,int y,float vol,float speed) int i,eff_size = 0,eff_id; mchSoundEFF* p = NULL; - hash_multimap::iterator si; - pair::iterator,hash_multimap::iterator> pr; + std::unordered_multimap::iterator si; + pair::iterator,std::unordered_multimap::iterator> pr; eff_size = map_localEFF.count(id); @@ -593,7 +595,7 @@ void mchSoundDispatcher::SetCoordsEFF(int id,int x,int y) { mchSoundEFF* p = NULL; - hash_multimap::iterator si = map_localEFF.find(id); + std::unordered_multimap::iterator si = map_localEFF.find(id); if(si == map_localEFF.end()){ si = map_globalEFF.find(id); @@ -618,7 +620,7 @@ void mchSoundDispatcher::StopEFF(int id) mchSoundEFF* p = NULL; - hash_multimap::iterator si = map_localEFF.find(id); + std::unordered_multimap::iterator si = map_localEFF.find(id); if(si == map_localEFF.end()){ si = map_globalEFF.find(id); @@ -1037,9 +1039,9 @@ int mchSoundDispatcher::GetStatusEFF(int id) { int i,eff_size = 0,eff_id; mchSoundEFF* p = NULL; - - hash_multimap::iterator si; - pair::iterator,hash_multimap::iterator> pr; + + std::unordered_multimap::iterator si; + pair::iterator,std::unordered_multimap::iterator> pr; eff_size = map_localEFF.count(id); diff --git a/MechoSoma/Sound/sound.h b/MechoSoma/Sound/sound.h index 5821ed77..e6fa8a9d 100644 --- a/MechoSoma/Sound/sound.h +++ b/MechoSoma/Sound/sound.h @@ -135,7 +135,7 @@ struct mchSoundDispatcher xtList* globalTimers; xtList* localTimers; - typedef hash_multimap SoundMap; + typedef std::unordered_multimap SoundMap; SoundMap map_globalEFF; SoundMap map_localEFF; diff --git a/MechoSoma/Sound/sound_api.cpp b/MechoSoma/Sound/sound_api.cpp index 6a4d35b3..be5aa9fa 100644 --- a/MechoSoma/Sound/sound_api.cpp +++ b/MechoSoma/Sound/sound_api.cpp @@ -2,12 +2,12 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include -#include "mch_rto.h" +#include "mch_rto.H" #include "mechosoma.h" #include "race.h" -#include "mesh3ds.h" -#include "terra.h" +#include "Mesh3ds.h" +#include "TERRA.H" #include "arcane.h" #include "CameraDispatcher.h" @@ -15,14 +15,14 @@ #include "arcane_menu.h" -#include "_xsound.h" +#include "xsound.h" #include "aci_parser.h" #include "sound.h" #include "sound_api.h" #include "snd_def.h" -#include "aci_ids.h" -#include "aci_scr.h" +#include "ACI_IDS.H" +#include "ACI_SCR.H" #include "PlayWSC.h" @@ -70,7 +70,9 @@ int sndCameraVolumeZ1 = 1000; int sndCameraVolumeV0 = 0; int sndCameraVolumeV1 = -3000; +#ifdef _MPPLUS_SOUNDTRACK_ MpegSound* mpeg_player = 0; +#endif int sndMinVolume = 4000; diff --git a/MechoSoma/Terra/JPEG_FM.cpp b/MechoSoma/Terra/JPEG_FM.cpp index c877426e..5b8dc4d9 100644 --- a/MechoSoma/Terra/JPEG_FM.cpp +++ b/MechoSoma/Terra/JPEG_FM.cpp @@ -1,15 +1,15 @@ -#include "stdafx.h" +#include "StdAfx.h" #include #ifdef _MECHOSOMA_ -#include "Mechosoma.h" +#include "mechosoma.h" #endif #include -#include "_xtool.h" +#include "xtool.h" #define XMD_H extern "C" { -#include "jpeglib.h" +#include } diff --git a/MechoSoma/Terra/LAND.CPP b/MechoSoma/Terra/LAND.CPP index 7a32f2e4..afb76d56 100644 --- a/MechoSoma/Terra/LAND.CPP +++ b/MechoSoma/Terra/LAND.CPP @@ -1,12 +1,12 @@ #include "StdAfx.h" -#include "terra.h" +#include "TERRA.H" #include "tgai.h" //#include "vmap.h" //#include "world.h" //#include "render.h" //#include "color.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #ifdef _SURMAP_ #include "common.h" #include "sqint.h" @@ -31,7 +31,7 @@ unsigned int sin_GM[2][512*3]; s_terra terra; int h_l=160; -//const h_l=120; //èíòåíñèâíîñòü 255 // 1/2 - 180 +//const h_l=120; //������������� 255 // 1/2 - 180 int d_x=4; int d_xw=8; int delta_s; @@ -557,11 +557,11 @@ void GeoSetZone(int x,int y,int rad,int level,int delta) GeoPoint((x + xx[j]) & clip_mask_x,(y + yy[j]) & clip_mask_y,level,delta,0); } - GeoPoint(0,0,level,delta,2);//çäåñü äåëüòà è ëåâåë íîáõîäèìû äëÿ ïðàâèëüíîãî ìàñøòàáèðîâàíèÿ ïî èçìåíåííîé ïîâåðõíîñòè + GeoPoint(0,0,level,delta,2);//����� ������ � ����� ��������� ��� ����������� ��������������� �� ���������� ����������� } #endif -void pixSet(int x,int y,int delta,int terrain)// çàãîëîâî÷íèêå terrain ïî óìîë÷àíèþ -1 +void pixSet(int x,int y,int delta,int terrain)//� ������������� terrain �� ��������� -1 { //// if(!delta) return; x=XCYCL(x); @@ -608,7 +608,7 @@ void pixSet(int x,int y,int delta,int terrain)// #endif if (terrain!=-1) SetTer(x,y,terrain%TERRAIN_MAX); -// ÏÐîâåðêà íà âîäó +// �������� �� ���� if(h < vMap->LevelH2O ){ if (GetW(XCYCL(x-1),y)>0 || GetW(XCYCL(x+1),y)>0 || GetW(x,y)>0 || GetW(x,YCYCL(y-1))>0 || GetW(x,YCYCL(y+1))>0 ) SetW(x,y); } @@ -641,7 +641,7 @@ void RenderRegStr(int Yh,int Yd) while (i!=j) { RenderStr(i); - i=YCYCL(++i); // ÐÀÇÍÈÖÀ ÌÅÆÄÓ i++ ++i òóò ÎÃÐÎÌÍÀß (2048 íå çàöèêëèâàåòñÿ) + i=YCYCL(++i); // ������� ����� i++ ++i ��� �������� (2048 �� �������������) } } @@ -660,10 +660,10 @@ void RenderPrepare1(void) h_l1=h_l; // k=h_l1/(sqrt(257*257-h_l1*h_l1)); // delta_s=round(k*256)*fraction; - k=h_l1/(sqrt((double)257*257-h_l1*h_l1)); // k -ýòî tg óãëà ïàäåíèÿ ñâåòà + k=h_l1/(sqrt((double)257*257-h_l1*h_l1)); // k -��� tg ���� ������� ����� delta_s=round(k*(1<<8)*(1<>8)*256)+1; - int j=XS_Buf+( 1024*(1< VxBuf[0][Y][0]; for(j;j>=0;j--){ //,pvh--,pvd-- @@ -823,7 +823,7 @@ void RenderPrepare1(void) h_l1=h_l; k=h_l1/(sqrt(257*257-h_l1*h_l1)); delta_s=round(k*65536*2); - //Ðàñ÷åò ñóøè + //������ ���� for(i=0;i>1); int cmpy=V_SIZE; cmpy=(cmpy>>1); - if(dxL<-cmpx) dxL+=H_SIZE; if(dxL>cmpx)dxL-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó + if(dxL<-cmpx) dxL+=H_SIZE; if(dxL>cmpx)dxL-=H_SIZE; //������������� �� ��������� if(dyL<-cmpy) dyL+=V_SIZE; if(dyL>cmpy)dyL-=V_SIZE; double LLight=sqrt((dxL)*(dxL)+(dyL)*(dyL) ); float f_dzx=1/tgAnglLight[round(LLight)]; DrawMeshShade(&Sh,xL,yL,f_dzx); //int dxS=Sh.x-xL,dyS=Sh.y-yL; - //if(dxS<-cmpx) dxS+=H_SIZE; if(dxS>cmpx)dxS-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó + //if(dxS<-cmpx) dxS+=H_SIZE; if(dxS>cmpx)dxS-=H_SIZE; //������������� �� ��������� //if(dyS<-cmpy) dyS+=V_SIZE; if(dyS>cmpy)dyS-=V_SIZE; //int LSh=sqrt((dxS)*(dxS)+(dyS)*(dyS) ); float dshx=(dxL)/LLight; @@ -1116,7 +1116,7 @@ void RenderShadowM3DPLold(int xL, int yL, int zL) v=GetAlt(XCYCL(round(Sh.x+dshx*stl+dshy*j)),YCYCL(round(Sh.y+dshy*stl-dshx*j))); //f_dzx=1/tgAnglLight[LSh+stl]; int xshade=round((stl)-(Sh.z-v)*f_dzx); - while( xshade0)&&(shadeBuf[xshade]>= v)) { SetAt(XCYCL(round(Sh.x+dshx*stl+dshy*j)),YCYCL(round(Sh.y+dshy*stl-dshx*j)),At_SHADOWS); //*(pc0+x_cycl)>>=1; @@ -1137,10 +1137,10 @@ void RenderShadowM3DPLold(int xL, int yL, int zL) } -void RenderShadowM3DPL(int xL, int yL, int zL) //Íå èñïðàâëåííûå áàãè òåíè: -{ // 1.òåíü øèðå èç-çà òðàññèðîâêè || ëó÷àìè - // 2.Ðàññòîÿíèå äî òåíè ñ÷èòàåòñÿ äî ëåâîãî óãëà áèòìàïà, - // à íàäî äî öåíòðà +void RenderShadowM3DPL(int xL, int yL, int zL) //�� ������������ ���� ����: +{ // 1.���� ���� ��-�� ����������� || ������ + // 2.���������� �� ���� ��������� �� ������ ���� �������, + // � ���� �� ������ cMesh *Mesh=M3D->First(); while(Mesh) { @@ -1154,7 +1154,7 @@ void RenderShadowM3DPL(int xL, int yL, int zL) // int cmpx=H_SIZE; cmpx=(cmpx>>1); int cmpy=V_SIZE; cmpy=(cmpy>>1); - if(dxL<-cmpx) dxL+=H_SIZE; if(dxL>cmpx)dxL-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó + if(dxL<-cmpx) dxL+=H_SIZE; if(dxL>cmpx)dxL-=H_SIZE; //������������� �� ��������� if(dyL<-cmpy) dyL+=V_SIZE; if(dyL>cmpy)dyL-=V_SIZE; double LLight=sqrt((dxL)*(dxL)+(dyL)*(dyL) ); @@ -1164,7 +1164,7 @@ void RenderShadowM3DPL(int xL, int yL, int zL) // DrawMeshShade(&Sh,xL,yL,f_dzx); int dxS=Sh.x-xL,dyS=Sh.y-yL; - if(dxS<-cmpx) dxS+=H_SIZE; if(dxS>cmpx)dxS-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó + if(dxS<-cmpx) dxS+=H_SIZE; if(dxS>cmpx)dxS-=H_SIZE; //������������� �� ��������� if(dyS<-cmpy) dyS+=V_SIZE; if(dyS>cmpy)dyS-=V_SIZE; int LSh=sqrt((dxS)*(dxS)+(dyS)*(dyS) ); double dshx=(dxL)/LLight; @@ -1184,7 +1184,7 @@ void RenderShadowM3DPL(int xL, int yL, int zL) // //f_dzx=1/tgAnglLight[LSh+stl]; f_dzx=(double)(LSh+stl)/(hLight-v); int xshade=round((stl)-(Sh.z-v)*f_dzx); - while( xshade>0 )//èëè cmpy ò.å. 1/2 êàðòû + while( xshade>0 )//��� cmpy �.�. 1/2 ����� { if( (xshade v)&&((LSh+stl)>=1; @@ -1215,7 +1215,7 @@ void clearShBit() void renderHiBmp(int num_track) { - //Îòêðûòèå Ñêðèïòà ñêðèïòà + //�������� ������� ������� XBuffer buft; char tmpstr[10]; buft < "SLight" < itoa(num_track%10,tmpstr,10) < ".sst"; @@ -1224,7 +1224,7 @@ void renderHiBmp(int num_track) minLightForShadow =8; int i,j; - //Êîíâåð ïàëèòðû â Try Color + //������ ������� � Try Color double dr,dg,db; for(i=0; i<32; i++){ dr=(double)( (((vMap ->TrPal[i][200]>>11)&0x1f)<<3) - (((vMap ->TrPal[i][0]>>11)&0x1f)<<3) )/200; @@ -1260,7 +1260,7 @@ void renderHiBmp(int num_track) vidBufB= new unsigned char [1][YS_Buf][XS_Buf]; tempG=new short[1][YS_Buf][XS_Buf]; tempV=new short[1][YS_Buf][XS_Buf]; - //Ïåðåìåùåíèå ïîâåðõíîñòè ïîä âîäîé íà âîêñåëüíóþ êàðòó + //����������� ����������� ��� ����� �� ���������� ����� for(i=0; iAtBuf[0][i][j] & At_WATER){ @@ -1270,8 +1270,8 @@ void renderHiBmp(int num_track) } } } - //Ñîçäàíèå íîðìàëåé ãîðèçîíòàëüíûõ- âåðòèêàëüíûõ - for(i=0; i VxBuf; @@ -1289,7 +1289,7 @@ void renderHiBmp(int num_track) //256*3+lxVh+Vh+rxVh-lxVd-Vd-rxVd //(*tempV)[i][j]=vMap -> VxBuf[0][YCYCL(i-1)][XCYCL(j-1)]+vMap -> VxBuf[0][YCYCL(i-1)][j]+vMap -> VxBuf[0][YCYCL(i-1)][XCYCL(j+1)]- vMap -> VxBuf[0][YCYCL(i+1)][XCYCL(j-1)]- vMap -> VxBuf[0][YCYCL(i+1)][j]- vMap -> VxBuf[0][YCYCL(i+1)][XCYCL(j+1)]; (*tempV)[i][j]=lxVh+Vh+rxVh-lxVd-Vd-rxVd; - //î÷èñòêà ClTrBuf + //������� ClTrBuf vMap -> ClTrBuf[0][i][j]=0; (*vidBuf)[i][j]=0; (*vidBufR)[i][j]=0; @@ -1298,7 +1298,7 @@ void renderHiBmp(int num_track) vMap -> AtBuf[0][i][j]&=~At_SHADOW; } } - //Ïåðåìåùåíèå ïîâåðõíîñòè îáðàòíî + //����������� ����������� ������� for(i=0; iAtBuf[0][i][j] & At_WATER){ @@ -1311,7 +1311,7 @@ void renderHiBmp(int num_track) int t_x,t_y, t_r,t_g,t_b,t_a,t_dlinaTeni; double t_begOffLight, t_dOffLight, t_minOffLight, t_begDelta_s, t_dDelta_s, t_minDelta_s, t_begLight, t_radius;//t_dLight, -//Ðåíäåð èñòî÷íèêîâ áåç òåíè +//������ ���������� ��� ���� for(i=0; i ClTrBuf[0][i][j]=0; (*vidBufR)[i][j]=0; @@ -1392,7 +1392,7 @@ void renderHiBmp(int num_track) } } -//Ðåíäåð èñòî÷íèêîâ ñ òåíüþ +//������ ���������� � ����� for(i=0; i ClTrBuf)),(unsigned char*)(*(vMap -> ClTrBuf)),(unsigned char*)(*(vMap -> ClTrBuf)) ); - /////// Ñëîæåíèå èòîãîâûõ èñòî÷íèêîâ ñ ïàëèòðîéïîâåðõíîñòè êàðòû + /////// �������� �������� ���������� � ������������������� ����� for(i=0; i>8) +terra.ambient_light[0][type]); if (l > minLightForShadow){ if (s-tgAnglLight[dlina] > V+1) { -// if(*(pa+off) & At_SHADOWV) l-=l>>2; //×òî-áû òåíü íà ïåðåñå÷åíèè áûëà ïîñâåòëåå +// if(*(pa+off) & At_SHADOWV) l-=l>>2; //���-�� ���� �� ����������� ���� ��������� // else l=l>>1; l=l>>1; *(pa+off)|=At_SHADOWV; } else { - //Íå òåíü(Âîêñåëüíàÿ) + //�� ����(����������) s=V; if (*(pa+off)&At_SHADOWS) { // if(*(pa+off) & At_SHADOWV) l-=l>>2; @@ -1693,11 +1693,11 @@ void render025HiBmp1(int xl, int yl) int i,j; -//Ðåíäåð îò 1-ãî èñòî÷íèêà âåðõíÿÿ ÷åòâåðòü +//������ �� 1-�� ��������� ������� �������� unsigned char *pc; char type; double d_bs=0;//int d_bs=0; - //int delta_s=15<<16; //Íà÷àëüíîå çíà÷åíèå óáûâàíèÿ òåíè + //int delta_s=15<<16; //��������� �������� �������� ���� double delta_s=begDelta_s; double dd_s=dDelta_s; unsigned char V; @@ -1710,7 +1710,7 @@ void render025HiBmp1(int xl, int yl) int ddg=dOffLight; //2<<10 int Light=begLight; //int dLight= 2<<12; -//Î÷èñòêà áóâåðîâ òåíè +//������� ������� ���� for(i=0; i>8) +terra.ambient_light[0][type]); if (l > minLightForShadow){ if (s-tgAnglLight[dlina] > V+1) { -// if(*(pa+off) & At_SHADOWV) l-=l>>2; //×òî-áû òåíü íà ïåðåñå÷åíèè áûëà ïîñâåòëåå +// if(*(pa+off) & At_SHADOWV) l-=l>>2; //���-�� ���� �� ����������� ���� ��������� // else l=l>>1; l=l>>1; *(pa+off)|=At_SHADOWV; } else { - //Íå òåíü(Âîêñåëüíàÿ) + //�� ����(����������) s=V; if (*(pa+off)&At_SHADOWS) { // if(*(pa+off) & At_SHADOWV) l-=l>>2; @@ -1823,11 +1823,11 @@ void render025HiBmp2(int xl, int yl) int i,j; -//Ðåíäåð îò 1-ãî èñòî÷íèêà âåðõíÿÿ ÷åòâåðòü +//������ �� 1-�� ��������� ������� �������� unsigned char *pc; char type; double d_bs=0;//int d_bs=0; - //int delta_s=15<<16; //Íà÷àëüíîå çíà÷åíèå óáûâàíèÿ òåíè + //int delta_s=15<<16; //��������� �������� �������� ���� double delta_s=begDelta_s; double dd_s=dDelta_s; unsigned char V; @@ -1840,7 +1840,7 @@ void render025HiBmp2(int xl, int yl) int ddg=dOffLight; //2<<10 int Light=begLight; //int dLight= 2<<12; -//Î÷èñòêà áóâåðîâ òåíè +//������� ������� ���� for(i=0; i>8) +terra.ambient_light[0][type]); if (l > minLightForShadow){ if (s-tgAnglLight[dlina] > V+1) { -// if(*(pa+off) & At_SHADOWV) l-=l>>2; //×òî-áû òåíü íà ïåðåñå÷åíèè áûëà ïîñâåòëåå +// if(*(pa+off) & At_SHADOWV) l-=l>>2; //���-�� ���� �� ����������� ���� ��������� // else l=l>>1; l=l>>1; *(pa+off)|=At_SHADOWV; } else { - //Íå òåíü(Âîêñåëüíàÿ) + //�� ����(����������) s=V; if (*(pa+off)&At_SHADOWS) { // if(*(pa+off) & At_SHADOWV) l-=l>>2; @@ -1953,11 +1953,11 @@ void render025HiBmp3(int xl, int yl) int i,j; -//Ðåíäåð îò 1-ãî èñòî÷íèêà âåðõíÿÿ ÷åòâåðòü +//������ �� 1-�� ��������� ������� �������� unsigned char *pc; char type; double d_bs=0;//int d_bs=0; - //int delta_s=15<<16; //Íà÷àëüíîå çíà÷åíèå óáûâàíèÿ òåíè + //int delta_s=15<<16; //��������� �������� �������� ���� double delta_s=begDelta_s; double dd_s=dDelta_s; unsigned char V; @@ -1970,7 +1970,7 @@ void render025HiBmp3(int xl, int yl) int ddg=dOffLight; //2<<10 int Light=begLight; //int dLight= 2<<12; -//Î÷èñòêà áóâåðîâ òåíè +//������� ������� ���� for(i=0; i>8) +terra.ambient_light[0][type]); if (l > minLightForShadow){ if (s-tgAnglLight[dlina] > V+1) { -// if(*(pa+off) & At_SHADOWV) l-=l>>2; //×òî-áû òåíü íà ïåðåñå÷åíèè áûëà ïîñâåòëåå +// if(*(pa+off) & At_SHADOWV) l-=l>>2; //���-�� ���� �� ����������� ���� ��������� // else l=l>>1; l=l>>1; *(pa+off)|=At_SHADOWV; } else { - //Íå òåíü(Âîêñåëüíàÿ) + //�� ����(����������) s=V; if (*(pa+off)&At_SHADOWS) { // if(*(pa+off) & At_SHADOWV) l-=l>>2; @@ -2085,10 +2085,10 @@ void render025HiBmp3(int xl, int yl) #include "land.h" s_renderV renderV; -void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) //Íå èñïðàâëåííûå áàãè òåíè: -{ // 1.òåíü øèðå èç-çà òðàññèðîâêè || ëó÷àìè - // 2.Ðàññòîÿíèå äî òåíè ñ÷èòàåòñÿ äî ëåâîãî óãëà áèòìàïà, - // à íàäî äî öåíòðà +void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) //�� ������������ ���� ����: +{ // 1.���� ���� ��-�� ����������� || ������ + // 2.���������� �� ���� ��������� �� ������ ���� �������, + // � ���� �� ������ extern cInterfaceVisGeneric *gb_IVisGeneric; cM3D *M3D=(cM3D*)gb_IVisGeneric->GetM3D(); assert(M3D); @@ -2096,7 +2096,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // while(Mesh) { //if(IS_STATIC(Mesh->Type) && (Mesh->NumberTrack&STATIC_NUMBER) ) { - if( IS_STATIC(Mesh->Type) && (!(Mesh->Attribute&MESH_NOT_SHADE)) ) { //Ïåðâàÿ ïðîâåðêà íå îáÿçàòåëüíà ò.ê. Surmape íåò íå ñòàòè÷åñêèõ îáúåêòîâ + if( IS_STATIC(Mesh->Type) && (!(Mesh->Attribute&MESH_NOT_SHADE)) ) { //������ �������� �� ����������� �.�. Surmape ��� �� ����������� �������� cShadow Sh; Sh.number=Mesh->ID; @@ -2106,7 +2106,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // int cmpx=H_SIZE; cmpx=(cmpx>>1); int cmpy=V_SIZE; cmpy=(cmpy>>1); - if(dxL<-cmpx) dxL+=H_SIZE; if(dxL>cmpx)dxL-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó + if(dxL<-cmpx) dxL+=H_SIZE; if(dxL>cmpx)dxL-=H_SIZE; //������������� �� ��������� if(dyL<-cmpy) dyL+=V_SIZE; if(dyL>cmpy)dyL-=V_SIZE; double LLight=sqrt((dxL)*(dxL)+(dyL)*(dyL) ); @@ -2116,7 +2116,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // DrawMeshShade(&Sh,xL,yL,f_dzx,RadiusL); int dxS=Sh.x-xL,dyS=Sh.y-yL; - if(dxS<-cmpx) dxS+=H_SIZE; if(dxS>cmpx)dxS-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó + if(dxS<-cmpx) dxS+=H_SIZE; if(dxS>cmpx)dxS-=H_SIZE; //������������� �� ��������� if(dyS<-cmpy) dyS+=V_SIZE; if(dyS>cmpy)dyS-=V_SIZE; int LSh=sqrt((dxS)*(dxS)+(dyS)*(dyS) ); double dshx=(dxL)/LLight; @@ -2136,7 +2136,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // //f_dzx=1/tgAnglLight[LSh+stl]; f_dzx=(double)(LSh+stl)/(zL-v); int xshade=round((stl)-(Sh.z-v)*f_dzx); - while( xshade>0 )//èëè cmpy ò.å. 1/2 êàðòû + while( xshade>0 )//��� cmpy �.�. 1/2 ����� { if( (xshade v)&&((LSh+stl)>=1; @@ -2151,7 +2151,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // }*/ -/* { //Ïîêàç ãðàíèö è ñàìîãî áèòìàïà òåíè, äëÿ îòëàäêè +/* { //����� ������ � ������ ������� ����, ��� ������� for (int j=0;jcmpx)dxSC-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó ðàññòîÿíèÿ - if(dySC<-cmpy) dySC+=V_SIZE; if(dySC>cmpy)dySC-=V_SIZE; //îò èñòî÷íèêà äî öåíòðà òåíè + if(dxSC<-cmpx) dxSC+=H_SIZE; if(dxSC>cmpx)dxSC-=H_SIZE; //������������� �� ��������� ���������� + if(dySC<-cmpy) dySC+=V_SIZE; if(dySC>cmpy)dySC-=V_SIZE; //�� ��������� �� ������ ���� int Rlb=sqrt((double)(dxSC*dxSC)+(double)(dySC*dySC)); float cosPovK,sinPovK; @@ -2180,7 +2180,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // int boundYL=-Sh.yShade/2; int boundYR=+Sh.yShade/2; - //Ðàñ÷åò íàèáîëåå áëèçêîé òî÷êè êîòîðàÿ ìîæåò áûòü ïðè âûñîòå ïîâåðõíîñòè 1024 + //������ �������� ������� ����� ������� ����� ���� ��� ������ ����������� 1024 //int ddl=(Rlb-Sh.xShade/2); //float ctgT; //if(zL>0)ctgT=(float)ddl/(float)zL; @@ -2193,25 +2193,25 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // x[0]=(round(Sh.x+dshx*dl+dshy*0)), y[0]=(round(Sh.y+dshy*dl-dshx*0)); x[1]=(round(Sh.x+dshx*dl+dshy*Sh.yShade)), y[1]=(round(Sh.y+dshy*dl-dshx*Sh.yShade)); //if(Sh.number==10){ - // int a=0; //Äëÿ îñòàíîâêè ïðè îòëàäêå íà îïðåäåëåííîé ìîäåëè + // int a=0; //��� ��������� ��� ������� �� ������������ ������ //} x[2]=(round(Sh.x+dshx*Sh.xShade+dshy*0)), y[2]=(round(Sh.y+dshy*Sh.xShade-dshx*0)); x[3]=(round(Sh.x+dshx*Sh.xShade+dshy*Sh.yShade)), y[3]=(round(Sh.y+dshy*Sh.xShade-dshx*Sh.yShade)); int i,t; - // íóëåâóþ ÿ÷åéêó ïîìåùàåì ñàìóþ âåðõíþþ âåøèíó + //� ������� ������ �������� ����� ������� ������ for(i=1; i<4; i++) if(y[0]>y[i]) { t=x[0]; x[0]=x[i]; x[i]=t; t=y[0]; y[0]=y[i]; y[i]=t;} - // ïåðâóþ ÿ÷åéêó ïîìåùàåì ñàìóþ íèæíèþ âåøèíó + //� ������ ������ �������� ����� ������ ������ for(i=2; i<4; i++) if(y[1]y[3]) { t=x[2]; x[2]=x[3]; x[3]=t; t=y[2]; y[2]=y[3]; y[3]=t;} - // òðåòüåé îñòàåòñÿ ñàìàÿ íèçøàÿ èç îñòàâøèõñÿ âåðøèí + //� ������� �������� ����� ������ �� ���������� ������ int dx02,dx03,dx21,dx31; - int curXl=(x[0]<<16)+(1<<15),curXr=(x[0]<<16)+(1<<15); //Ëåâàÿ è ïðàâàÿ ãðàíèöû ÷åòûðåõóãîëüíèêà + int curXl=(x[0]<<16)+(1<<15),curXr=(x[0]<<16)+(1<<15); //����� � ������ ������� ���������������� int X=x[0], Y=y[0]; int dxl,dxr; - //Òåïåðü 3 ýòàïà çàïîëíåíèÿ ÷åòûðåõóãîëüíèêà - //1-é îò 0 äî 2-é âåðøèíû - if((y[2]-y[0]) >0){ // ñàìî ñîáîé (y[3]-y[0]) >0 + //������ 3 ����� ���������� ���������������� + //1-� �� 0 �� 2-� ������� + if((y[2]-y[0]) >0){ // ���� ����� (y[3]-y[0]) >0 dx02=((x[0]-x[2]<<16) ) / (y[2]-y[0]); //+(1<<15) dx03=((x[0]-x[3]<<16) ) / (y[3]-y[0]); //+(1<<15) if(dx02>dx03){ dxl=dx02; dxr=dx03;} @@ -2221,8 +2221,8 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // int V=GetAlt(XCYCL(X),YCYCL(Y))>>SHIFT_FRACTION_VX; int dxSL=(X-xL), dySL=(Y-yL); - if(dxSL<-cmpx) dxSL+=H_SIZE; if(dxSL>cmpx)dxSL-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó ðàññòîÿíèÿ - if(dySL<-cmpy) dySL+=V_SIZE; if(dySL>cmpy)dySL-=V_SIZE; //îò èñòî÷íèêà äî òî÷êè + if(dxSL<-cmpx) dxSL+=H_SIZE; if(dxSL>cmpx)dxSL-=H_SIZE; //������������� �� ��������� ���������� + if(dySL<-cmpy) dySL+=V_SIZE; if(dySL>cmpy)dySL-=V_SIZE; //�� ��������� �� ����� float L=sqrt(dxSL*dxSL+ dySL*dySL); float ddxSL,ddySL; if(L>0) { ddxSL=dxSL/L; ddySL=dySL/L; } @@ -2234,7 +2234,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // float ys=dySL + dL*ddySL; int xns=round(xs*cosPovK + ys*sinPovK); int yns=round(xs*sinPovK - ys*cosPovK); - //èçâëå÷åíèå èç òåíè è ïðîâåðêà ïî Z áóôåðó + //���������� �� ���� � �������� �� Z ������ if( (xns > boundXL) && (xns< boundXR) && (yns>boundYL) && (ynsV ) SetAt(XCYCL(X),YCYCL(Y),At_SHADOWV); @@ -2245,19 +2245,19 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // curXl-=dxl; curXr-=dxr; } } - //2-é îò 2 äî 3-é âåðøèíû - if((y[3]-y[2]) >0){ // ñàìî ñîáîé (y[1]-y[2])>0 + //2-� �� 2 �� 3-� ������� + if((y[3]-y[2]) >0){ // ���� ����� (y[1]-y[2])>0 dx21=((x[2]-x[1]<<16) ) / (y[1]-y[2]); //+(1<<15) - dx03=((x[0]-x[3]<<16) ) / (y[3]-y[0]);//Ïîâòîð âìåñòî óñëîâèÿ //+(1<<15) - if(dx02>dx03){ dxl=dx21; dxr=dx03; curXl=x[2]<<16+(1<<15);} //Îïðåäåëåíèå ñ êàêîé ñòîðîíû 2è 3ÿ âåðøèíû; è - else { dxl=dx03; dxr=dx21; curXr=x[2]<<16+(1<<15); } // êîððåêöèÿ curXr(curXl) ÷òîáûíå íàêàïëèâàëàñü îøèáêà + dx03=((x[0]-x[3]<<16) ) / (y[3]-y[0]);//������ ������ ������� //+(1<<15) + if(dx02>dx03){ dxl=dx21; dxr=dx03; curXl=x[2]<<16+(1<<15);} //����������� � ����� ������� 2� 3� �������; � + else { dxl=dx03; dxr=dx21; curXr=x[2]<<16+(1<<15); } // ��������� curXr(curXl) ������� ������������� ������ for (Y; Y<=y[3]; Y++){ for(X=(curXl>>16); X<=(curXr>>16); X++){ //SetAt(XCYCL(X),YCYCL(Y),At_SHADOWV); int V=GetAlt(XCYCL(X),YCYCL(Y))>>SHIFT_FRACTION_VX; int dxSL=(X-xL), dySL=(Y-yL); - if(dxSL<-cmpx) dxSL+=H_SIZE; if(dxSL>cmpx)dxSL-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó ðàññòîÿíèÿ - if(dySL<-cmpy) dySL+=V_SIZE; if(dySL>cmpy)dySL-=V_SIZE; //îò èñòî÷íèêà äî òî÷êè + if(dxSL<-cmpx) dxSL+=H_SIZE; if(dxSL>cmpx)dxSL-=H_SIZE; //������������� �� ��������� ���������� + if(dySL<-cmpy) dySL+=V_SIZE; if(dySL>cmpy)dySL-=V_SIZE; //�� ��������� �� ����� float L=sqrt(dxSL*dxSL+ dySL*dySL); float ddxSL,ddySL; if(L>0) { ddxSL=dxSL/L; ddySL=dySL/L; } @@ -2269,7 +2269,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // float ys=dySL + dL*ddySL; int xns=round(xs*cosPovK + ys*sinPovK); int yns=round(xs*sinPovK - ys*cosPovK); - //èçâëå÷åíèå èç òåíè è ïðîâåðêà ïî Z áóôåðó + //���������� �� ���� � �������� �� Z ������ if( (xns > boundXL) && (xns< boundXR) && (yns>boundYL) && (ynsV ) SetAt(XCYCL(X),YCYCL(Y),At_SHADOWV); @@ -2278,10 +2278,10 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // curXl-=dxl; curXr-=dxr; } } - //3-é îò 3 äî 1-îé âåðøèíû - if((y[1]-y[3]) >0){ // ñàìî ñîáîé (y[1]-y[2])>0 + //3-� �� 3 �� 1-�� ������� + if((y[1]-y[3]) >0){ // ���� ����� (y[1]-y[2])>0 dx21=((x[2]-x[1]<<16) ) / (y[1]-y[2]);//+(1<<15) - dx31=((x[3]-x[1]<<16) ) / (y[1]-y[3]);//Ïîâòîð âìåñòî óñëîâèÿ //+(1<<15) + dx31=((x[3]-x[1]<<16) ) / (y[1]-y[3]);//������ ������ ������� //+(1<<15) if(dx02>dx03){ dxl=dx21; dxr=dx31; curXr=x[3]<<16+(1<<15);} else { dxl=dx31; dxr=dx21; curXl=x[3]<<16+(1<<15);} for (Y; Y<=y[1]; Y++){ @@ -2289,8 +2289,8 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // //SetAt(XCYCL(X),YCYCL(Y),At_SHADOWV); int V=GetAlt(XCYCL(X),YCYCL(Y))>>SHIFT_FRACTION_VX; int dxSL=(X-xL), dySL=(Y-yL); - if(dxSL<-cmpx) dxSL+=H_SIZE; if(dxSL>cmpx)dxSL-=H_SIZE; //Ðàñöèêëèâàíèå ïî èñòî÷íèêó ðàññòîÿíèÿ - if(dySL<-cmpy) dySL+=V_SIZE; if(dySL>cmpy)dySL-=V_SIZE; //îò èñòî÷íèêà äî òî÷êè + if(dxSL<-cmpx) dxSL+=H_SIZE; if(dxSL>cmpx)dxSL-=H_SIZE; //������������� �� ��������� ���������� + if(dySL<-cmpy) dySL+=V_SIZE; if(dySL>cmpy)dySL-=V_SIZE; //�� ��������� �� ����� float L=sqrt(dxSL*dxSL+ dySL*dySL); float ddxSL,ddySL; if(L>0) { ddxSL=dxSL/L; ddySL=dySL/L; } @@ -2302,7 +2302,7 @@ void s_renderV::RenderShadowM3DPL(int xL, int yL, int zL, int RadiusL) // float ys=dySL + dL*ddySL; int xns=round(xs*cosPovK + ys*sinPovK); int yns=round(xs*sinPovK - ys*cosPovK); - //èçâëå÷åíèå èç òåíè è ïðîâåðêà ïî Z áóôåðó + //���������� �� ���� � �������� �� Z ������ if( (xns > boundXL) && (xns< boundXR) && (yns>boundYL) && (ynsV ) SetAt(XCYCL(X),YCYCL(Y),At_SHADOWV); @@ -2322,9 +2322,9 @@ void s_renderV::init(void) k_Ambient=30; k_SAmbient=30; /* for(int i=0; i VxBuf; //unsigned char (*tVL)[YS_Buf][XS_Buf]=vMap -> SpecBuf; Z0 =(tV[0][i][j]<<2); @@ -2380,9 +2380,9 @@ void s_renderV::main(int num_track) N_Y[0][i][j]=(B<<8)/ModV>>2; N_Z[0][i][j]=(C<<8)/ModV>>2; - //î÷èñòêà + //������� shadowBuf[0][i][j]=0; - //Çàíåñåíèå àìáèåíòíîãî èñòî÷íèêà è ñàìîñâåòÿùèõñÿ ïîâåðõíîñòåé + //��������� ����������� ��������� � �������������� ������������ int rt=0;//(*vidBufRI)[i][j]*k_Ambient/100; int gt=0;//(*vidBufGI)[i][j]*k_Ambient/100; int bt=0;//(*vidBufBI)[i][j]*k_Ambient/100; @@ -2414,7 +2414,7 @@ void s_renderV::main(int num_track) sur_scr.row[0].get_el(i,xL); sur_scr.row[1].get_el(i,yL); - xVis=xL, yVis=yL, zVis=GetAlt(xL,yL)+50; // Äëÿ ðàñ÷åòà óãëà çðåíèÿ + xVis=xL, yVis=yL, zVis=GetAlt(xL,yL)+50; // ��� ������� ���� ������ sur_scr.row[2].get_el(i,zL); sur_scr.row[3].get_el(i,rL); sur_scr.row[4].get_el(i,gL); @@ -2437,7 +2437,7 @@ void s_renderV::main(int num_track) sur_scr.row[14].get_el(i,t_dlinaTeni);*/ - calculateLightOnDistance(Radius); //Ðàñ÷åò ÿðêîñòè â çàâèñèìîñòè îò ðàññòîÿíèÿ + calculateLightOnDistance(Radius); //������ ������� � ����������� �� ���������� calculateShadowVx(xL,yL,zL,Radius); // if(Radius <=1024){ RenderShadowM3DPL(xL,yL,zL,Radius); @@ -2445,16 +2445,16 @@ void s_renderV::main(int num_track) // else { // RenderShadowM3DPL(xL,yL,zL,1023); // } - prepareGaussFilter(k_SmusShadow);// (ðàäèóñ/10) - //float kl=1,kml=0.001; //kml - êîýôôèöèåíò ìàñøòàáèðîâàíèÿ ïî ðàññòîÿíèþ çàòóõàíèå èñòî÷íèêà + prepareGaussFilter(k_SmusShadow);// (������/10) + //float kl=1,kml=0.001; //kml - ����������� ��������������� �� ���������� ��������� ��������� double k_zat=1;//0.999;//0.2 //int begL=255; - float Ld,Ls,Ldif,Lspec; //Ld - îñâåùåíèå ñ ó÷åòîì êîýôôèöèåíòà äèôôóçíîãî îòðàæåíèÿ - //Ls - îñâåùåíèå ñ ó÷åòîì êîýôôèöèåíòà ñïåêóëÿðíîãî îòðàæåíèÿ + float Ld,Ls,Ldif,Lspec; //Ld - ��������� � ������ ������������ ���������� ��������� + //Ls - ��������� � ������ ������������ ������������ ��������� int l; - //íåïîñðåäñòâåííî ðåíäåð + //��������������� ������ int x,y,xx,yy; int dx,dy,dz; int dxVis,dyVis,dzVis,lVis; @@ -2463,7 +2463,7 @@ void s_renderV::main(int num_track) for( yy=yL-Radius; yy>SHIFT_FRACTION_VX)-zL; - //Òåíü, êîòîðàÿ âûõîäèò çà ãðàíèöû ìèðà áûëà ïîëîæåíà àòðèáóòîì At_SHADOWS + //����, ������� ������� �� ������� ���� ���� �������� ��������� At_SHADOWS if( abs(dy)>V_SIZE/2 || (abs(dx) > H_SIZE/2) ) ShadowIs=At_SHADOWS; else { //if( ((abs(dy)< V_SIZE/2+3) && (abs(dy)> V_SIZE/2-3)) || ((abs(dx)< H_SIZE/2+3) && (abs(dx)> H_SIZE/2-3)) ){ // ShadowIs=At_SHADOW; //} //else - //Òåíü, êîòîðàÿ íå âûõîäèò çà ãðàíèöû ìèðà áûëà ïîëîæåíà àòðèáóòîì At_SHADOWV + //����, ������� �� ������� �� ������� ���� ���� �������� ��������� At_SHADOWV ShadowIs=At_SHADOWV; } - //dxVis=calcDX(xVis,x); //Äëÿ ðàñ÷åòà óãëà çðåíèÿ + //dxVis=calcDX(xVis,x); //��� ������� ���� ������ dxVis=xx-xVis; dzVis=zVis-(vBuf[0][y][x]>>SHIFT_FRACTION_VX); lVis=round(sqrt(dxVis*dxVis+dyVis*dyVis+dzVis*dzVis)); @@ -2493,14 +2493,14 @@ void s_renderV::main(int num_track) l=round(sqrt(dx*dx+dy*dy+dz*dz)); unsigned char atr=GetAt(x,y); unsigned char terrain=atr&Tr_MASK;//GetTer(x,y); - //L=(float)begL/((float)l*kml+kl); // ßðêîñòü èñòî÷íèêà â äàííîé òî÷êå + //L=(float)begL/((float)l*kml+kl); // ������� ��������� � ������ ����� //L=begL*(pow(k_zat,l>>2)); //L=begL-k_zat*(float)l; if(L<0)L=0; float lightDistance=tableLightOnDistance[round(sqrt(dx*dx+dy*dy))];//+XRnd(10); Ld=lightDistance*dif_k[terrain]; Ls=lightDistance; float nxL=(float)dx/l,nyL=(float)dy/l,nzL=(float)dz/l; - float cosA=((int)N_X[0][y][x]*nxL + (int)N_Y[0][y][x]*nyL +(int)N_Z[0][y][x]*nzL)/64;// íà 64 óìíîæåíà íîðìàëü âîêñåëåé (<<8 è >>2) + float cosA=((int)N_X[0][y][x]*nxL + (int)N_Y[0][y][x]*nyL +(int)N_Z[0][y][x]*nzL)/64;// �� 64 �������� ������� �������� (<<8 � >>2) if (cosA<0) cosA=0; Ldif=Ld*cosA; if(Ldif>256)Ldif=256; //+Lambient float cosLV=nxL*nxVis + nyL*nyVis + nzL*nzVis; @@ -2509,12 +2509,12 @@ void s_renderV::main(int num_track) if (cosG > 255) cosG=255; if(cosG < 0)cosG=0; //if(cosG < -255)cosG=-255; Lspec=Ls*COSnG[terrain][256+cosG]; int ro,go,bo; -/* if((atr&At_SHADOWV)==0){//if(shadowBuf[0][y][x]==0){ //íåò òåíè +/* if((atr&At_SHADOWV)==0){//if(shadowBuf[0][y][x]==0){ //��� ���� ro=vidBufRI[0][y][x]*Ldif*kR/256 + (rL*Lspec/(256*256)); go=vidBufGI[0][y][x]*Ldif*kG/256 + (gL*Lspec/(256*256)); bo=vidBufBI[0][y][x]*Ldif*kB/256 + (bL*Lspec/(256*256)); } - else { //åñòü òåíü + else { //���� ���� ro=0; go=0; bo=0; //ro=(vidBufRI[0][y][x]*Ldif/256)*k_ambient/100; //go=(vidBufGI[0][y][x]*Ldif/256)*k_ambient/100; @@ -2594,8 +2594,8 @@ void s_renderV::main(int num_track) vMap->saveVMM(); - //Êîíâåðò èç Try â High Color äëÿ ïîêàçà íà ýêðàíå - // È èçìåíåíèå ðåæèìà ïîêàçà íà ýêðàíå + //������� �� Try � High Color ��� ������ �� ������ + // � ��������� ������ ������ �� ������ for(i=0; iClBuf[0][i][j]=((((*vidBufRO)[i][j]>>3)&0x1f)<<11)+((((*vidBufGO)[i][j]>>2)&0x3f)<<5)+(((*vidBufBO)[i][j]>>3)&0x1f); @@ -2603,7 +2603,7 @@ void s_renderV::main(int num_track) } GCM.setFV( 1 , FLAG_Show_PrimaryOrRender_World); - //Ïîêàç ãäå òåíü + //����� ��� ���� //for(i=0; iClTrBuf[0][i][j]=255; //} @@ -2678,7 +2678,7 @@ void s_renderV::calculateShadowVx(int xl, int yl,int zl, int Radius_Light) (*b_ds)[BUF_CENTR]=0;(*b_ds_i)[BUF_CENTR]=0; int i,j; - //Î÷èñòêà àòðèáóòîâ òåíè (At_SHADOWV è At_SHADOS) + //������� ��������� ���� (At_SHADOWV � At_SHADOS) for(i=0;iAtBuf[0][i][j]&=~At_SHADOW; char typeL,typeR; @@ -2689,8 +2689,8 @@ void s_renderV::calculateShadowVx(int xl, int yl,int zl, int Radius_Light) int offL,offR; float sL,dsL,sR,dsR; unsigned char ShadowIs; - //Ðàñ÷åò òåíè Âåðõíåé ÷åòâåðòè - //Î÷èñòêà áóâåðîâ òåíè + //������ ���� ������� �������� + //������� ������� ���� for(i=0; i VL) { *(pa+offL)|=ShadowIs; } //Òåíü - else { //Íå òåíü(Âîêñåëüíàÿ) + if (sL > VL) { *(pa+offL)|=ShadowIs; } //���� + else { //�� ����(����������) //*(pa+offL)&=~At_SHADOWV; sL=VL; dsL=(float)(zl-VL)/(float)(i); } - if (sR > VR) { *(pa+offR)|=ShadowIs; } //Òåíü + if (sR > VR) { *(pa+offR)|=ShadowIs; } //���� else { - //Íå òåíü(Âîêñåëüíàÿ) + //�� ����(����������) //*(pa+offR)&=~At_SHADOWV; sR=VR; dsR=(float)(zl-VR)/(float)(i); @@ -2757,8 +2757,8 @@ void s_renderV::calculateShadowVx(int xl, int yl,int zl, int Radius_Light) d_bs=(float)i/(i+1); } - //Ðàñ÷åò òåíè íèæíåé ÷åòâåðòè - //Î÷èñòêà áóâåðîâ òåíè + //������ ���� ������ �������� + //������� ������� ���� for(i=0; i VL) { *(pa+offL)|=ShadowIs; } //Òåíü - else { //Íå òåíü(Âîêñåëüíàÿ) + if (sL > VL) { *(pa+offL)|=ShadowIs; } //���� + else { //�� ����(����������) //*(pa+offL)&=~At_SHADOWV; sL=VL; dsL=(float)(zl-VL)/(float)(i); } - if (sR > VR) { *(pa+offR)|=ShadowIs; } //Òåíü + if (sR > VR) { *(pa+offR)|=ShadowIs; } //���� else { - //Íå òåíü(Âîêñåëüíàÿ) + //�� ����(����������) //*(pa+offR)&=~At_SHADOWV; sR=VR; dsR=(float)(zl-VR)/(float)(i); @@ -2826,8 +2826,8 @@ void s_renderV::calculateShadowVx(int xl, int yl,int zl, int Radius_Light) } - //Ðàñ÷åò òåíè ëåâîé ÷åòâåðòè - //Î÷èñòêà áóâåðîâ òåíè + //������ ���� ����� �������� + //������� ������� ���� for(i=0; i VL) { *(pa+offL)|=ShadowIs; } //Òåíü - else { //Íå òåíü(Âîêñåëüíàÿ) + if (sL > VL) { *(pa+offL)|=ShadowIs; } //���� + else { //�� ����(����������) //*(pa+offL)&=~At_SHADOWV; sL=VL; dsL=(float)(zl-VL)/(float)(i); } - if (sR > VR) { *(pa+offR)|=ShadowIs; } //Òåíü + if (sR > VR) { *(pa+offR)|=ShadowIs; } //���� else { - //Íå òåíü(Âîêñåëüíàÿ) + //�� ����(����������) //*(pa+offR)&=~At_SHADOWV; sR=VR; dsR=(float)(zl-VR)/(float)(i); @@ -2894,8 +2894,8 @@ void s_renderV::calculateShadowVx(int xl, int yl,int zl, int Radius_Light) d_bs=(float)i/(i+1); } - //Ðàñ÷åò òåíè ïðàâîé ÷åòâåðòè - //Î÷èñòêà áóâåðîâ òåíè + //������ ���� ������ �������� + //������� ������� ���� for(i=0; i VL) { *(pa+offL)|=ShadowIs; } //Òåíü - else { //Íå òåíü(Âîêñåëüíàÿ) + if (sL > VL) { *(pa+offL)|=ShadowIs; } //���� + else { //�� ����(����������) //*(pa+offL)&=~At_SHADOWV; sL=VL; dsL=(float)(zl-VL)/(float)(i); } - if (sR > VR) { *(pa+offR)|=ShadowIs; } //Òåíü + if (sR > VR) { *(pa+offR)|=ShadowIs; } //���� else { - //Íå òåíü(Âîêñåëüíàÿ) + //�� ����(����������) //*(pa+offR)&=~At_SHADOWV; sR=VR; dsR=(float)(zl-VR)/(float)(i); @@ -3008,10 +3008,10 @@ void s_renderV::init(void) void s_renderV::main(int num_track) { - //Èíèöèàëèçàöèÿ (ïîòîì íóæíî çàìåíèòü íà çàãðóçêó äàííûõ) + //������������� (����� ����� �������� �� �������� ������) init(); - //Îòêðûòèå Ñêðèïòà ñêðèïòà + //�������� ������� ������� XBuffer buft; char tmpstr[10]; buft < "SLightR" < itoa(num_track%10,tmpstr,10) < ".sst"; @@ -3037,10 +3037,10 @@ void s_renderV::main(int num_track) thead.load3layers(GetTargetName("input.tga"),H_SIZE,V_SIZE,(unsigned char*)(*vidBufRI),(unsigned char*)(*vidBufGI),(unsigned char*)(*vidBufBI) ); - //Ñîçäàíèå íîðìàëåé âîêñåëåé - for(i=0; i VxBuf; unsigned char (*tVL)[YS_Buf][XS_Buf]=vMap -> SpecBuf; Z0 =(tV[0][i][j]<<8) | tVL[0][i][j]; @@ -3052,7 +3052,7 @@ void s_renderV::main(int num_track) N_Y[0][i][j]=(B<<8)/ModV>>2; N_Z[0][i][j]=(C<<8)/ModV>>2; - //î÷èñòêà + //������� shadowBuf[0][i][j]=0; (*vidBufRO)[i][j]=0; (*vidBufGO)[i][j]=0; @@ -3086,16 +3086,16 @@ void s_renderV::main(int num_track) sur_scr.row[8].get_el(i,k_ambient); - calculateLightOnDistance(Radius); //Ðàñ÷åò ÿðêîñòè â çàâèñèìîñòè îò ðàññòîÿíèÿ + calculateLightOnDistance(Radius); //������ ������� � ����������� �� ���������� - //float kl=1,kml=0.001; //kml - êîýôôèöèåíò ìàñøòàáèðîâàíèÿ ïî ðàññòîÿíèþ çàòóõàíèå èñòî÷íèêà + //float kl=1,kml=0.001; //kml - ����������� ��������������� �� ���������� ��������� ��������� double k_zat=1;//0.999;//0.2 //int begL=255; float L,Ldif,Lspec; int l; - //íåïîñðåäñòâåííî ðåíäåð + //��������������� ������ int x,y; int dx,dy,dz; for( y=0; y>2)); //L=begL-k_zat*(float)l; if(L<0)L=0; L=tableLightOnDistance[l]; float nxL=(float)dx/l,nyL=(float)dy/l,nzL=(float)dz/l; - float cosA=((int)N_X[0][y][x]*nxL + (int)N_Y[0][y][x]*nyL +(int)N_Z[0][y][x]*nzL)/64;// íà 64 óìíîæåíà íîðìàëü âîêñåëåé (<<8 è >>2) + float cosA=((int)N_X[0][y][x]*nxL + (int)N_Y[0][y][x]*nyL +(int)N_Z[0][y][x]*nzL)/64;// �� 64 �������� ������� �������� (<<8 � >>2) if (cosA<0) cosA=0; Ldif=L*cosA; if(Ldif>256)Ldif=256; //+Lambient float cosLV=nxL*nxVis + nyL*nyVis + nzL*nzVis; @@ -3118,12 +3118,12 @@ void s_renderV::main(int num_track) if (cosG > 255) cosG=255; if(cosG < 0)cosG=0; Lspec=L*COSnG[GetTer(x,y)][256+cosG]; int ro,go,bo; - if(shadowBuf[0][y][x]==0){ //íåò òåíè + if(shadowBuf[0][y][x]==0){ //��� ���� ro=vidBufRI[0][y][x]*Ldif/256 + (rL*Lspec/(256*256)); go=vidBufGI[0][y][x]*Ldif/256 + (gL*Lspec/(256*256)); bo=vidBufBI[0][y][x]*Ldif/256 + (bL*Lspec/(256*256)); } - else { //åñòü òåíü + else { //���� ���� ro=(vidBufRI[0][y][x]*Ldif/256)*k_ambient/100; go=(vidBufGI[0][y][x]*Ldif/256)*k_ambient/100; bo=(vidBufBI[0][y][x]*Ldif/256)*k_ambient/100; @@ -3144,7 +3144,7 @@ void s_renderV::main(int num_track) thead.save3layers(GetTargetName("track0.tga"),H_SIZE,V_SIZE,(unsigned char*)(*vidBufRO),(unsigned char*)(*vidBufGO),(unsigned char*)(*vidBufBO) ); - //Êîíâåðò èç Try â High Color äëÿ ïîêàçà íà ýêðàíå + //������� �� Try � High Color ��� ������ �� ������ for(i=0; iClBuf[0][i][j]=((((*vidBufRO)[i][j]>>3)&0x1f)<<11)+((((*vidBufGO)[i][j]>>2)&0x3f)<<5)+(((*vidBufBO)[i][j]>>3)&0x1f); diff --git a/MechoSoma/Terra/RENDER.H b/MechoSoma/Terra/RENDER.H index 599d63a1..e2dd7c05 100644 --- a/MechoSoma/Terra/RENDER.H +++ b/MechoSoma/Terra/RENDER.H @@ -4,6 +4,10 @@ #endif //__forceinline #endif //_MSC_VER +#ifndef _WIN32 +#define __forceinline inline +#endif + //@caiiiycuk can't find defined of SHIFT_FRACTION_VX #define SHIFT_FRACTION_VX 6 #define VX_FRACTION 6 // from LAND.CPP diff --git a/MechoSoma/Terra/VMAP.CPP b/MechoSoma/Terra/VMAP.CPP index 16d3c65f..8fd1b6e0 100644 --- a/MechoSoma/Terra/VMAP.CPP +++ b/MechoSoma/Terra/VMAP.CPP @@ -6,7 +6,7 @@ #include #ifdef _MECHOSOMA_ -#include "Mechosoma.h" +#include "mechosoma.h" #endif #define XMD_H @@ -14,8 +14,8 @@ extern "C" { #include "jpeglib.h" } -#include "mesh3ds.h" -#include "terra.h" +#include "Mesh3ds.h" +#include "TERRA.H" #include "tgai.h" #ifdef _SURMAP_ @@ -37,6 +37,10 @@ extern int ShowFog; #define SESSION #endif +#ifndef _WIN32 +#include "port.h" +#endif + /* ----------------------------- EXTERN SECTION ---------------------------- */ //extern int* SI; //extern int* CO; @@ -346,13 +350,15 @@ void vrtMap::saveTrPal(void) { // Set Color water; char buf [16]; - SaveINIstringV(GetTargetName(wTable[cWorld].fname),"Global Parameters","Color H2O",itoa(H2OC,buf,10)); - SaveINIstringV(GetTargetName(wTable[cWorld].fname),"Global Parameters","Alpha H2O",itoa(H2OA,buf,10)); + SaveINIstringV(GetTargetName(wTable[cWorld].fname),"Global Parameters","Color H2O",port_itoa(H2OC,buf,10)); + SaveINIstringV(GetTargetName(wTable[cWorld].fname),"Global Parameters","Alpha H2O",port_itoa(H2OA,buf,10)); vMap->pmap.open(GetTargetName(vMap->paletteName),XS_OUT); vMap->pmap.write(&(vMap->TrPal[0][0]),TERRAIN_MAX*256*2); vMap->pmap.close(); } + +#ifdef _WIN32 int getTick(void) #define CPUID __asm _emit 0xf __asm _emit 0xa2 #define RDTSC __asm _emit 0xf __asm _emit 0x31 @@ -374,6 +380,7 @@ int getTick(void) } return time; } +#endif void vrtMap::calcH2Ocolor(int terr) { #ifdef _USE_NOT_XGRAPH_ @@ -1161,13 +1168,13 @@ void vrtMap::fileLoad(void) #endif #ifdef _MECHOSOMA_ - mch_vmapResourceInit(); //Ïîäãîòîâêà êîíòåéíåðà ìèðà(â ìåõîñîìå) + mch_vmapResourceInit(); //���������� ���������� ����(� ��������) #endif } void vrtMap::open(char* name,int nWorld) { - //Êîïèðîâàíèå òîëüêî èìåíè êàòàëîãà â dirWorldPrm + //����������� ������ ����� �������� � dirWorldPrm char* dir,*dirtemp; char *dirend=dirtemp=dir=strdup(name); while(*dirtemp) { @@ -1178,11 +1185,11 @@ void vrtMap::open(char* name,int nWorld) dirWorldPrm = strdup(dir); free(dir); // - // ÇÀÃÐÓÇÊÀ òàáëèöû ìèðîâ èç PRM + // �������� ������� ����� �� PRM pFile -> init(name); maxWorld = atoi(pFile -> getAtom()); if(maxWorld < 1) ErrH.Abort("Empty world list"); - register int i; + int i; char* atom; wTable = new vrtWorld[maxWorld]; for(i = 0;i < maxWorld;i++){ @@ -1204,7 +1211,7 @@ void vrtMap::open(char* name,int nWorld) } void vrtMap::load(char* name,int nWorld,int nTrack) { - //Êîïèðîâàíèå òîëüêî èìåíè êàòàëîãà â dirWorldPrm + //����������� ������ ����� �������� � dirWorldPrm char* dir,*dirtemp; char *dirend=dirtemp=dir=strdup(name); while(*dirtemp) { @@ -1218,7 +1225,7 @@ void vrtMap::load(char* name,int nWorld,int nTrack) pFile -> init(name); maxWorld = atoi(pFile -> getAtom()); if(maxWorld < 1) ErrH.Abort("Empty world list"); - register int i; + int i; char* atom; wTable = new vrtWorld[maxWorld]; char str_dir[256]; @@ -1229,10 +1236,10 @@ void vrtMap::load(char* name,int nWorld,int nTrack) atom = pFile -> getAtom(); if(!atom) ErrH.Abort("Null world path"); //wTable[i].fname = strdup(atom); - //Îòñå÷åíèå world.ini îò ïóòè ê êàòàëîãó ìèðà - strcpy(str_dir,dirWorldPrm);//êîïèðîâàíèå â ñòðîêó ïóòè äî êàòàëîãà ñ worlds.prm + //��������� world.ini �� ���� � �������� ���� + strcpy(str_dir,dirWorldPrm);//����������� � ������ ���� �� �������� � worlds.prm if(*dirWorldPrm) strcat(str_dir,"\\"); - strcat(str_dir,atom); //äîáàâëåíèå â ñòðîêó ïóòè äî êàòàëîãà ñ ìèðîì + strcat(str_dir,atom); //���������� � ������ ���� �� �������� � ����� int k,L=strlen(str_dir); if(L) for(k=L-1; k>=0; k--){ if(str_dir[k]=='\\') { @@ -1251,7 +1258,7 @@ void vrtMap::load(char* name,int nWorld,int nTrack) if(nWorld >= maxWorld || nWorld < 0) nWorld = 0; #ifdef _SURMAP_ cWorld = nWorld; -#else //åñëè Ìåõîñîèà +#else //���� �������� cWorld=0; for(i=0; i< maxWorld; i++){ if ( (wTable[i].numberMechosomWorld==nWorld) && (wTable[i].numberMechosomTrack==nTrack) ){ @@ -1349,12 +1356,12 @@ void vrtMap::reload(int nWorld, int nTrack) { if(nWorld >= maxWorld || nWorld < 0) ErrH.Abort("World Index out of range"); #ifdef _SURMAP_ -// if(cWorld == nWorld) return;//Îòêëþ÷åíî èç çà çàãðóçêè ìèðà èäóùåé çà reload +// if(cWorld == nWorld) return;//��������� �� �� �������� ���� ������ �� reload #endif #ifdef _SURMAP_ cWorld = nWorld; -#else //åñëè Ìåõîñîèà +#else //���� �������� cWorld=0; int i; for(i=0; i< maxWorld; i++){ @@ -1498,7 +1505,7 @@ void vrtMap::reload(int nWorld, int nTrack) _close(h); remove(kname); #if defined(RUSSIAN_VERSION) && !defined(GERMAN_VERSION) - ErrH.Abort("Íåäîñòàòî÷íî ìåñòà íà æåñòêîì äèñêå äëÿ ðàáîòû â ðåæèìå ñîõðàíåíèÿ âñåõ èçìåíåèé!"); + ErrH.Abort("������������ ����� �� ������� ����� ��� ������ � ������ ���������� ���� ��������!"); #else ErrH.Abort("Can't create KEEP File. Please, free more disk space for this feature working."); #endif @@ -1691,8 +1698,8 @@ void vrtMap::checkAndRecoverWater() void vrtMap::load3Buf(int X,int Y,int num_track) #ifdef _SURMAP_ { - X=0;Y=YS_Buf;//ÒÎëüêî äëÿ íà÷àëà ! - //Çàãðóçêà âîäû + X=0;Y=YS_Buf;//������ ��� ������ ! + //�������� ���� LevelH2O=0; LevelH2O = atoi(GetINIstringV(GetTargetName(wTable[cWorld].fname),"Global Parameters","LevelH2O")); if(LevelH2O<0)LevelH2O =0; @@ -1706,7 +1713,7 @@ void vrtMap::load3Buf(int X,int Y,int num_track) const char id2[4]={'S','M','W','2'}; fmap.seek(0,XS_BEG); fmap.read(&VmpHeader,sizeof(VmpHeader)); - if (*(int*)VmpHeader.id == *(int*)id2 ){ //Çàãðóçêà 2 ôîðèàòà VMP + if (*(int*)VmpHeader.id == *(int*)id2 ){ //�������� 2 ������� VMP fmap.read(&VxBuf[0][0][0],XS_Buf*YS_Buf*2); fmap.read(&AtBuf[0][0][0],XS_Buf*YS_Buf); // WORLD RENDER @@ -1716,7 +1723,7 @@ void vrtMap::load3Buf(int X,int Y,int num_track) } } else { - if (*(int*)VmpHeader.id == *(int*)id1 ){ //Çàãðóçêà 1 ôîðèàòà VMP + if (*(int*)VmpHeader.id == *(int*)id1 ){ //�������� 1 ������� VMP unsigned char* tVxBuf; tVxBuf=new unsigned char [YS_Buf*XS_Buf]; @@ -1735,8 +1742,8 @@ void vrtMap::load3Buf(int X,int Y,int num_track) save3BufOnly(); } else { - if (*(int*)VmpHeader.id == *(int*)id ){ //Çàãðóçêà 0 ôîðìàòà VMP (â SpecBuf âûñîòà âîêñåëåé ïîä âîäîé) - //Çàãðóçêà è UPDATE 0 ôîðìàòà VMP + if (*(int*)VmpHeader.id == *(int*)id ){ //�������� 0 ������� VMP (� SpecBuf ������ �������� ��� �����) + //�������� � UPDATE 0 ������� VMP unsigned char* tVxBuf; tVxBuf=new unsigned char [YS_Buf*XS_Buf]; @@ -1745,7 +1752,7 @@ void vrtMap::load3Buf(int X,int Y,int num_track) for(i=0; iAtBuf[0][i][j] & At_WATER){ @@ -1765,7 +1772,7 @@ void vrtMap::load3Buf(int X,int Y,int num_track) save3BufOnly(); } else { - //Çàãðóçêà è UPDATE Non standart OLD!(êîòîðûé åùå èñïîëüçóåò ãåíåðàòîð ìèðà) + //�������� � UPDATE Non standart OLD!(������� ��� ���������� ��������� ����) unsigned char* tVxBuf; tVxBuf=new unsigned char [XS_Buf]; fmap.seek(0,XS_BEG); @@ -1804,7 +1811,7 @@ void vrtMap::load3Buf(int X,int Y,int num_track) } } -//Ðèñîâàíèå world_border +//��������� world_border #ifdef WORLD_BORDER for(i=0;i>kmBuf)*(YS_Buf>>kmBuf)); } - else ErrH.Abort("Ñòàðûé ôîðìàò ìèðà"); + else ErrH.Abort("������ ������ ����"); //#if defined (HI_COLOR_WORLD) if(loadClBufJ(0,YS_Buf-1,num_track) ==0) loadClBuf(0,YS_Buf-1,num_track); @@ -1866,13 +1873,13 @@ void vrtMap::load3Buf(int X,int Y,int num_track) int vrtMap::loadClBufForRender(int X,int Y,int num_track) { - X=0;Y=YS_Buf;//ÒÎëüêî äëÿ íà÷àëà ! + X=0;Y=YS_Buf;//������ ��� ������ ! if(num_track==-1)num_track=0; int i,j; XBuffer buft; char tmpstr[10]; - buft < "i_track" < itoa(num_track%10,tmpstr,10) < ".tga"; + buft < "i_track" < port_itoa(num_track%10,tmpstr,10) < ".tga"; XStream ss(0); #ifdef _MECHOSOMA_ if(!vmapOpenResource(GetTargetName(buft),ss)) return 0; @@ -1906,13 +1913,13 @@ int vrtMap::loadClBufForRender(int X,int Y,int num_track) int vrtMap::loadClBuf(int X,int Y,int num_track) { - X=0;Y=YS_Buf;//ÒÎëüêî äëÿ íà÷àëà ! + X=0;Y=YS_Buf;//������ ��� ������ ! if(num_track==-1)num_track=0; int i,j; XBuffer buft; char tmpstr[10]; - buft < "track" < itoa(num_track%10,tmpstr,10) < ".tga"; + buft < "track" < port_itoa(num_track%10,tmpstr,10) < ".tga"; XStream ss(0); #ifdef _MECHOSOMA_ if(!vmapOpenResource(GetTargetName(buft), ss)){ @@ -1946,7 +1953,7 @@ int vrtMap::loadClBuf(int X,int Y,int num_track) delete line; return 1; -/* //Çàãðóçêà è ñìåøèâàíèå ïî àëüôà êàíàëó. +/* //�������� � ���������� �� ����� ������. int i,j; XBuffer buft; char tmpstr[10]; @@ -2041,13 +2048,13 @@ my_error_exit (j_common_ptr cinfo) int vrtMap::loadClBufJ(int X,int Y,int num_track) { - X=0;Y=YS_Buf;//ÒÎëüêî äëÿ íà÷àëà ! + X=0;Y=YS_Buf;//������ ��� ������ ! if(num_track==-1)num_track=0; int i,j=0; XBuffer buft; char tmpstr[10]; - buft < "track" < itoa(num_track%10,tmpstr,10) < ".jpg"; + buft < "track" < port_itoa(num_track%10,tmpstr,10) < ".jpg"; struct jpeg_decompress_struct cinfo; @@ -2590,18 +2597,18 @@ void vrtMap::save3Buf(void) saveTrPal(); } void vrtMap::saveVMM(void) - //Çàïèñü VMM + //������ VMM { int j,i; XStream fo; fo.open(GetTargetName("output.vmm"), XS_OUT); - // Çàïèñü çàãîëîâêà + // ������ ��������� const char idm[4]={'M','M','W','1'}; fmap.seek(0,XS_BEG); *(int*)VmpHeader.id = *(int*)idm; VmpHeader.XS=1024;VmpHeader.YS=1024;VmpHeader.NX=0;VmpHeader.NY=0; fo.write(&VmpHeader,sizeof(VmpHeader)); - //Ò.ê. Ýòî SUrmap, kmVxBu=0 ðàâåí 0, ïîýòîìó ñäâèãàåì íà ôèêñèðîâàííóþ 1 + //�.�. ��� SUrmap, kmVxBu=0 ����� 0, ������� �������� �� ������������� 1 unsigned char VB[XS_Buf>>1]; for (j=0; j<(YS_Buf>>1); j++){ for(i=0; i<(XS_Buf>>1); i++){ @@ -2821,10 +2828,10 @@ void vrtMap::scaling16(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int ys // Pred LOOP test ebp,3h je l_loop1t - dec ecx //Óìåíüøàåì íà 1 îñíîâíîé loop ò.ê. Pred&End LOOP îáðàáîòàþò 4 pix. + dec ecx //��������� �� 1 �������� loop �.�. Pred&End LOOP ���������� 4 pix. mov eax,ebp and eax,3h - push eax // Ñîõðàíåíèå êîë. ïîâòîðîâ End LOOP + push eax // ���������� ���. �������� End LOOP neg eax and eax,3h push ecx // Save loop LOOP @@ -2839,8 +2846,8 @@ p_loop1: mov cx,[ebx+eax] mov [edi],cx xor cx,cx - test ah,020h // Ýòî (At_WATER << 1) - jne p_loop2 //Åñëè âîäà- òî îñòàåòñÿ 0 + test ah,020h // ��� (At_WATER << 1) + jne p_loop2 //���� ����- �� �������� 0 mov cl,[esi+offsetVx+ebp] p_loop2: movd eax,MM5 @@ -2942,8 +2949,8 @@ e_loop1: mov cx,[ebx+eax] mov [edi],cx xor cx,cx - test ah,020h // Ýòî (At_WATER << 1) - jne e_loop2 //Åñëè âîäà- òî îñòàåòñÿ 0 + test ah,020h // ��� (At_WATER << 1) + jne e_loop2 //���� ����- �� �������� 0 mov cl,[esi+offsetVx+ebp] e_loop2: movd eax,MM5 @@ -3013,7 +3020,7 @@ void vrtMap::viewV(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int yside) int y0=YCYCL(cy)<<16; // Compute the xy coordinates; a and b will be the position inside the - // single map cell (0..255). //a,b äðîáíàÿ ÷àñòü + // single map cell (0..255). //a,b ������� ����� u0=(x0>>16)&clip_mask_x; a=(x0>>8)&255; v0=((y0>>16)&clip_mask_y); b=(y0>>8)&255; u1=(u0+1)&clip_mask_x; @@ -3029,7 +3036,7 @@ void vrtMap::viewV(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int yside) h0=(h0<<8)+a*(h1-h0); h2=(h2<<8)+a*(h3-h2); hCamera=((h0<<8)+b*(h2-h0))>>16>>VX_FRACTION; - hCamera+=30;//Âûñîòà êàìåðû íàä ïîâåðõíîñòüþ + hCamera+=30;//������ ������ ��� ������������ // Draw the landscape from near to far without overdraw for ( d=0; d<1000; d+=1 ){//d+=1+(d>>6) @@ -3076,7 +3083,7 @@ void vrtMap::viewV(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int yside) //h0=(h0<<8)+a*(h1-h0); //h2=(h2<<8)+a*(h3-h2); //c=((h0<<8)+b*(h2-h0)); - c=h0<<16; //Ñóììèðîâàíèå öâåòà ïîêà âûêëþ÷åíî + c=h0<<16; //������������ ����� ���� ��������� // Compute screen height using the scaling factor y=(((hCamera-h)*scaling)>>10)+240;//100 @@ -3086,9 +3093,9 @@ void vrtMap::viewV(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int yside) short *b=vp+a*XGR_MAXX+i; int sc,cc; if ( lastc[i]==-1 ) lastc[i]=c; - //sc=(c-lastc[i])/(a-y); // Ïåðåõîä öâåòà áóäåò ñäåëàí ïîòîì + //sc=(c-lastc[i])/(a-y); // ������� ����� ����� ������ ����� sc=0; - cc=c;//lastc[i];//Ïåðåõîä öâåòà áóäåò ñäåëàí ïîòîì + cc=c;//lastc[i];//������� ����� ����� ������ ����� if ( a>(XGR_MAXY-1) ) { b-=(a-(XGR_MAXY-1))*XGR_MAXX; cc+=(a-(XGR_MAXY-1))*sc; a=(XGR_MAXY-1); } @@ -3157,7 +3164,7 @@ void vrtMap::viewV2D(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int ysid int x0=XCYCL(cx)<<16; int y0=YCYCL(cy)<<16; - //hCamera=600;//Âûñîòà êàìåðû íàä ïîâåðõíîñòüþ + //hCamera=600;//������ ������ ��� ������������ unsigned short* lv = &(vMap -> VxBuf[0][0][0]); @@ -3219,7 +3226,7 @@ void vrtMap::viewV2D(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int ysid //h0=(h0<<8)+a*(h1-h0); //h2=(h2<<8)+a*(h3-h2); //c=((h0<<8)+b*(h2-h0)); - c=h0<<16; //Ñóììèðîâàíèå öâåòà ïîêà âûêëþ÷åíî*/ + c=h0<<16; //������������ ����� ���� ���������*/ unsigned char* lc1 = &(vMap -> ClTrBuf[0][0][0]);// unsigned char* lc2 = &(vMap -> AtBuf[0][0][0]);// //c=TrPal[lc2[u0+v0]& TrW_MASK][lc1[u0+v0]]<<16; @@ -3241,9 +3248,9 @@ void vrtMap::viewV2D(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int ysid short *b=vp+a*XGR_MAXX+i; int sc,cc; if ( lastc[i]==-1 ) lastc[i]=c; - //sc=(c-lastc[i])/(a-y); // Ïåðåõîä öâåòà áóäåò ñäåëàí ïîòîì + //sc=(c-lastc[i])/(a-y); // ������� ����� ����� ������ ����� sc=0; - cc=c;//lastc[i];//Ïåðåõîä öâåòà áóäåò ñäåëàí ïîòîì + cc=c;//lastc[i];//������� ����� ����� ������ ����� if ( a>(XGR_MAXY-1) ) { b-=(a-(XGR_MAXY-1))*XGR_MAXX; cc+=(a-(XGR_MAXY-1))*sc; a=(XGR_MAXY-1); } @@ -3340,7 +3347,7 @@ void vrtMap::scaling16HC(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int } -#else //Mechosoma version Ñ ïîñòîÿííûì óðîâíåì âîäû ! è ñîêðàùåííûì âîêñåëüíûì ïðîñòðàíñòâîì +#else //Mechosoma version � ���������� ������� ���� ! � ����������� ���������� ������������� void vrtMap::scaling16(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int yside) { // xt_mmxUse=0; @@ -3367,7 +3374,7 @@ void vrtMap::scaling16(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int ys // request(MIN(y0,y1) - MAX_RADIUS/2,MAX(y0,y1) + MAX_RADIUS/2,MIN(x0,x1) - 4,MAX(x0,x1) + 4); - register int i,j,fx,fy; + int i,j,fx,fy; unsigned short* lc = &(vMap -> ClBuf[0][0][0]);// unsigned char* la = &(vMap -> AtBuf[0][0][0]); unsigned char* lv = &(vMap -> VxBuf[0][0][0]); @@ -3402,7 +3409,7 @@ void vrtMap::scaling16(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int ys //#ifdef MMX // } // else { -// //Òóò äîëæåí áûòü óñêîðåííûé êîä äëÿ MMX +// //��� ������ ���� ���������� ��� ��� MMX // } //#endif @@ -3412,7 +3419,7 @@ void vrtMap::scaling16(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int ys -// Ñòàðàÿ âåðñèÿ äëÿ ìåõîñîìû ( ãäå åùå åñòü ClTrBuf ) +// ������ ������ ��� �������� ( ��� ��� ���� ClTrBuf ) /* void vrtMap::scaling16(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int yside) { @@ -3522,10 +3529,10 @@ void vrtMap::scaling16(int XSrcSize,int cx,int cy,int xc,int yc,int xside,int ys // Pred LOOP test ebp,3h je l_loop1t - dec ecx //Óìåíüøàåì íà 1 îñíîâíîé loop ò.ê. Pred&End LOOP îáðàáîòàþò 4 pix. + dec ecx //��������� �� 1 �������� loop �.�. Pred&End LOOP ���������� 4 pix. mov eax,ebp and eax,3h - push eax // Ñîõðàíåíèå êîë. ïîâòîðîâ End LOOP + push eax // ���������� ���. �������� End LOOP neg eax and eax,3h push ecx // Save loop LOOP @@ -3540,9 +3547,9 @@ p_loop1: mov cx,[ebx+eax] mov [edi],cx xor cx,cx -//. test ah,020h // Ýòî (At_WATER << 1) -//. jne p_loop2 //Åñëè âîäà- òî îñòàåòñÿ 0 - movd MM0,ebp //Äëÿ ìîäèôèöèðîâàííîãî VxBuf +//. test ah,020h // ��� (At_WATER << 1) +//. jne p_loop2 //���� ����- �� �������� 0 + movd MM0,ebp //��� ����������������� VxBuf psrlq MM0,1 paddd MM0,MM4 movd eax,MM0 @@ -3601,7 +3608,7 @@ l_loop1: //. psrlw MM1,8+1+4 //zBuf //. pcmpeqw MM1,MM6 //zBuf //. pand MM2,MM1 //zBuf - movd MM0,ebp //Äëÿ ìîäèôèöèðîâàííîãî VxBuf + movd MM0,ebp //��� ����������������� VxBuf psrlq MM0,1 paddd MM0,MM4 movd eax,MM0 @@ -3659,9 +3666,9 @@ e_loop1: mov cx,[ebx+eax] mov [edi],cx xor cx,cx -//. test ah,020h // Ýòî (At_WATER << 1) -//. jne e_loop2 //Åñëè âîäà- òî îñòàåòñÿ 0 - movd MM0,ebp //Äëÿ ìîäèôèöèðîâàííîãî VxBuf +//. test ah,020h // ��� (At_WATER << 1) +//. jne e_loop2 //���� ����- �� �������� 0 + movd MM0,ebp //��� ����������������� VxBuf psrlq MM0,1 paddd MM0,MM4 movd eax,MM0 @@ -4573,7 +4580,7 @@ sAllWorldsTable::sAllWorldsTable(char* worlds_prm_name) maxWorld = atoi(pFile -> getAtom()); if(maxWorld < 1) ErrH.Abort("Empty world list"); it= new sWorldTable[maxWorld]; - register int i; + int i; char* atom; for(i = 0;i < maxWorld;i++){ atom = pFile -> getAtom(); @@ -4592,10 +4599,10 @@ sAllWorldsTable::sAllWorldsTable(char* worlds_prm_name) *dirend = '\0'; char tString[256]; - strcpy(tString,dirWorldPrm);//êîïèðîâàíèå â ñòðîêó ïóòè äî êàòàëîãà ñ worlds.prm + strcpy(tString,dirWorldPrm);//����������� � ������ ���� �� �������� � worlds.prm if(*dirWorldPrm) strcat(tString,"\\"); - strcat(tString,dir); //äîáàâëåíèå â ñòðîêó ïóòè äî êàòàëîãà ñ world.ini - //ïîëó÷àåì ïóòü äî êàòàëîãà ñ ìèðîì + strcat(tString,dir); //���������� � ������ ���� �� �������� � world.ini + //�������� ���� �� �������� � ����� free(dir); it[i].dir = strdup(tString); @@ -4603,7 +4610,7 @@ sAllWorldsTable::sAllWorldsTable(char* worlds_prm_name) it[i].numberMechosomWorld = atoi(pFile -> getAtom()); it[i].numberMechosomTrack = atoi(pFile -> getAtom()); - //Âðåìåííî ! ïîëó÷åíèå ïóòåé äî world.ini è äð. + //�������� ! ��������� ����� �� world.ini � ��. XBuffer tS; tS.init(); tS < dirWorldPrm; @@ -4620,11 +4627,11 @@ sAllWorldsTable::sAllWorldsTable(char* worlds_prm_name) tS.init(); tS < it[i].dir; if(*it[i].dir) tS < "\\"; - if(!mch_vmapResourceInit(tS)) continue; //Íóæíî â ñëó÷àå ZIP êîíòåéíåðà + if(!mch_vmapResourceInit(tS)) continue; //����� � ������ ZIP ���������� tS < Ch_pointsFileName; Ch_points.load(tS,0); - it[i].QuantityTrack=Ch_points.max_number; //Çàïèñü â òàáëèöó êîëè÷åñòâà òðýêîâ + it[i].QuantityTrack=Ch_points.max_number; //������ � ������� ���������� ������ free(Ch_pointsFileName); diff --git a/MechoSoma/Terra/VMAP.H b/MechoSoma/Terra/VMAP.H index 969568c4..7e0a4e3c 100644 --- a/MechoSoma/Terra/VMAP.H +++ b/MechoSoma/Terra/VMAP.H @@ -1,4 +1,4 @@ -#include "_xtool.h" +#include "xtool.h" //const unsigned int H_POWER = H_SIZE_POWER; //const unsigned int H_SIZE = 1 << H_POWER; diff --git a/MechoSoma/Terra/ch_points.cpp b/MechoSoma/Terra/ch_points.cpp index 5b9869dc..6d426073 100644 --- a/MechoSoma/Terra/ch_points.cpp +++ b/MechoSoma/Terra/ch_points.cpp @@ -1,12 +1,16 @@ #include -#include "terra.h" -#include "mesh3ds.h" +#include "TERRA.H" +#include "Mesh3ds.h" #ifdef _SURMAP_ #include "sqint.h" #include "sqexp.h" #endif +#ifndef _WIN32 +#include "port.h" +#endif + //int editCh_point=-1; sCh_points Ch_points; @@ -102,7 +106,7 @@ void sCh_points::load(char* fname,int number_track) XBuffer xb; char tmpstr[10]; int i; - xb < fname < itoa(number_track,tmpstr,10); + xb < fname < port_itoa(number_track,tmpstr,10); currient_track=number_track; if(!Cmap.open(xb,XS_IN)) return; long s = Cmap.size(); @@ -141,7 +145,7 @@ void sCh_points::save(char* fname,int number_track) if(number_track==-1) number_track=currient_track; XBuffer xb; char tmpstr[10]; - xb < fname < itoa(number_track,tmpstr,10); + xb < fname < port_itoa(number_track,tmpstr,10); if(!Cmap.open(xb,XS_OUT)) return; Cmap.write(&El,sizeof(El)); Cmap.write(&Link,sizeof(Link)); diff --git a/MechoSoma/Terra/jconfig.h b/MechoSoma/Terra/jconfig.h deleted file mode 100644 index 2f4da14c..00000000 --- a/MechoSoma/Terra/jconfig.h +++ /dev/null @@ -1,45 +0,0 @@ -/* jconfig.vc --- jconfig.h for Microsoft Visual C++ on Windows 95 or NT. */ -/* see jconfig.doc for explanations */ - -#define HAVE_PROTOTYPES -#define HAVE_UNSIGNED_CHAR -#define HAVE_UNSIGNED_SHORT -/* #define void char */ -/* #define const */ -#undef CHAR_IS_UNSIGNED -#define HAVE_STDDEF_H -#define HAVE_STDLIB_H -#undef NEED_BSD_STRINGS -#undef NEED_SYS_TYPES_H -#undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */ -#undef NEED_SHORT_EXTERNAL_NAMES -#undef INCOMPLETE_TYPES_BROKEN - -/* Define "boolean" as unsigned char, not int, per Windows custom */ -#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ -typedef unsigned char boolean; -#endif -#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ - - -#ifdef JPEG_INTERNALS - -#undef RIGHT_SHIFT_IS_UNSIGNED - -#endif /* JPEG_INTERNALS */ - -#ifdef JPEG_CJPEG_DJPEG - -#define BMP_SUPPORTED /* BMP image file format */ -#define GIF_SUPPORTED /* GIF image file format */ -#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ -#undef RLE_SUPPORTED /* Utah RLE image file format */ -#define TARGA_SUPPORTED /* Targa image file format */ - -#define TWO_FILE_COMMANDLINE /* optional */ -#define USE_SETMODE /* Microsoft has setmode() */ -#undef NEED_SIGNAL_CATCHER -#undef DONT_USE_B_MODE -#undef PROGRESS_REPORT /* optional */ - -#endif /* JPEG_CJPEG_DJPEG */ diff --git a/MechoSoma/Terra/jerror.h b/MechoSoma/Terra/jerror.h deleted file mode 100644 index 79084f2e..00000000 --- a/MechoSoma/Terra/jerror.h +++ /dev/null @@ -1,291 +0,0 @@ -/* - * jerror.h - * - * Copyright (C) 1994-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file defines the error and message codes for the JPEG library. - * Edit this file to add new codes, or to translate the message strings to - * some other language. - * A set of error-reporting macros are defined too. Some applications using - * the JPEG library may wish to include this file to get the error codes - * and/or the macros. - */ - -/* - * To define the enum list of message codes, include this file without - * defining macro JMESSAGE. To create a message string table, include it - * again with a suitable JMESSAGE definition (see jerror.c for an example). - */ -#ifndef JMESSAGE -#ifndef JERROR_H -/* First time through, define the enum list */ -#define JMAKE_ENUM_LIST -#else -/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ -#define JMESSAGE(code,string) -#endif /* JERROR_H */ -#endif /* JMESSAGE */ - -#ifdef JMAKE_ENUM_LIST - -typedef enum { - -#define JMESSAGE(code,string) code , - -#endif /* JMAKE_ENUM_LIST */ - -JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */ - -/* For maintenance convenience, list is alphabetical by message code name */ -JMESSAGE(JERR_ARITH_NOTIMPL, - "Sorry, there are legal restrictions on arithmetic coding") -JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") -JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") -JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode") -JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS") -JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range") -JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported") -JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition") -JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") -JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") -JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") -JMESSAGE(JERR_BAD_LIB_VERSION, - "Wrong JPEG library version: library is %d, caller expects %d") -JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") -JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") -JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") -JMESSAGE(JERR_BAD_PROGRESSION, - "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") -JMESSAGE(JERR_BAD_PROG_SCRIPT, - "Invalid progressive parameters at scan script entry %d") -JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") -JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") -JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") -JMESSAGE(JERR_BAD_STRUCT_SIZE, - "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") -JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") -JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") -JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") -JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet") -JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d") -JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request") -JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d") -JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x") -JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d") -JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d") -JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)") -JMESSAGE(JERR_EMS_READ, "Read from EMS failed") -JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed") -JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan") -JMESSAGE(JERR_FILE_READ, "Input file read error") -JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?") -JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet") -JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow") -JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry") -JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels") -JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") -JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") -JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, - "Cannot transcode due to multiple use of quantization table %d") -JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") -JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") -JMESSAGE(JERR_NOTIMPL, "Not implemented yet") -JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time") -JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported") -JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined") -JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image") -JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined") -JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") -JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") -JMESSAGE(JERR_QUANT_COMPONENTS, - "Cannot quantize more than %d color components") -JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") -JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") -JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") -JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker") -JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x") -JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers") -JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF") -JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s") -JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") -JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") -JMESSAGE(JERR_TFILE_WRITE, - "Write failed on temporary file --- out of disk space?") -JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") -JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") -JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") -JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation") -JMESSAGE(JERR_XMS_READ, "Read from XMS failed") -JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed") -JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) -JMESSAGE(JMSG_VERSION, JVERSION) -JMESSAGE(JTRC_16BIT_TABLES, - "Caution: quantization tables are too coarse for baseline JPEG") -JMESSAGE(JTRC_ADOBE, - "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") -JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") -JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") -JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") -JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x") -JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d") -JMESSAGE(JTRC_DRI, "Define Restart Interval %u") -JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u") -JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u") -JMESSAGE(JTRC_EOI, "End Of Image") -JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") -JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d") -JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, - "Warning: thumbnail image size does not match data length %u") -JMESSAGE(JTRC_JFIF_EXTENSION, - "JFIF extension marker: type 0x%02x, length %u") -JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") -JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u") -JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") -JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u") -JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors") -JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors") -JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization") -JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") -JMESSAGE(JTRC_RST, "RST%d") -JMESSAGE(JTRC_SMOOTH_NOTIMPL, - "Smoothing not supported with nonstandard sampling ratios") -JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") -JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") -JMESSAGE(JTRC_SOI, "Start of Image") -JMESSAGE(JTRC_SOS, "Start Of Scan: %d components") -JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d") -JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d") -JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") -JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") -JMESSAGE(JTRC_THUMB_JPEG, - "JFIF extension marker: JPEG-compressed thumbnail image, length %u") -JMESSAGE(JTRC_THUMB_PALETTE, - "JFIF extension marker: palette thumbnail image, length %u") -JMESSAGE(JTRC_THUMB_RGB, - "JFIF extension marker: RGB thumbnail image, length %u") -JMESSAGE(JTRC_UNKNOWN_IDS, - "Unrecognized component IDs %d %d %d, assuming YCbCr") -JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") -JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") -JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") -JMESSAGE(JWRN_BOGUS_PROGRESSION, - "Inconsistent progression sequence for component %d coefficient %d") -JMESSAGE(JWRN_EXTRANEOUS_DATA, - "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") -JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") -JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") -JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") -JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") -JMESSAGE(JWRN_MUST_RESYNC, - "Corrupt JPEG data: found marker 0x%02x instead of RST%d") -JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") -JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") - -#ifdef JMAKE_ENUM_LIST - - JMSG_LASTMSGCODE -} J_MESSAGE_CODE; - -#undef JMAKE_ENUM_LIST -#endif /* JMAKE_ENUM_LIST */ - -/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ -#undef JMESSAGE - - -#ifndef JERROR_H -#define JERROR_H - -/* Macros to simplify using the error and trace message stuff */ -/* The first parameter is either type of cinfo pointer */ - -/* Fatal errors (print message and exit) */ -#define ERREXIT(cinfo,code) \ - ((cinfo)->err->msg_code = (code), \ - (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) -#define ERREXIT1(cinfo,code,p1) \ - ((cinfo)->err->msg_code = (code), \ - (cinfo)->err->msg_parm.i[0] = (p1), \ - (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) -#define ERREXIT2(cinfo,code,p1,p2) \ - ((cinfo)->err->msg_code = (code), \ - (cinfo)->err->msg_parm.i[0] = (p1), \ - (cinfo)->err->msg_parm.i[1] = (p2), \ - (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) -#define ERREXIT3(cinfo,code,p1,p2,p3) \ - ((cinfo)->err->msg_code = (code), \ - (cinfo)->err->msg_parm.i[0] = (p1), \ - (cinfo)->err->msg_parm.i[1] = (p2), \ - (cinfo)->err->msg_parm.i[2] = (p3), \ - (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) -#define ERREXIT4(cinfo,code,p1,p2,p3,p4) \ - ((cinfo)->err->msg_code = (code), \ - (cinfo)->err->msg_parm.i[0] = (p1), \ - (cinfo)->err->msg_parm.i[1] = (p2), \ - (cinfo)->err->msg_parm.i[2] = (p3), \ - (cinfo)->err->msg_parm.i[3] = (p4), \ - (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) -#define ERREXITS(cinfo,code,str) \ - ((cinfo)->err->msg_code = (code), \ - strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ - (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) - -#define MAKESTMT(stuff) do { stuff } while (0) - -/* Nonfatal errors (we can keep going, but the data is probably corrupt) */ -#define WARNMS(cinfo,code) \ - ((cinfo)->err->msg_code = (code), \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) -#define WARNMS1(cinfo,code,p1) \ - ((cinfo)->err->msg_code = (code), \ - (cinfo)->err->msg_parm.i[0] = (p1), \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) -#define WARNMS2(cinfo,code,p1,p2) \ - ((cinfo)->err->msg_code = (code), \ - (cinfo)->err->msg_parm.i[0] = (p1), \ - (cinfo)->err->msg_parm.i[1] = (p2), \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) - -/* Informational/debugging messages */ -#define TRACEMS(cinfo,lvl,code) \ - ((cinfo)->err->msg_code = (code), \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) -#define TRACEMS1(cinfo,lvl,code,p1) \ - ((cinfo)->err->msg_code = (code), \ - (cinfo)->err->msg_parm.i[0] = (p1), \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) -#define TRACEMS2(cinfo,lvl,code,p1,p2) \ - ((cinfo)->err->msg_code = (code), \ - (cinfo)->err->msg_parm.i[0] = (p1), \ - (cinfo)->err->msg_parm.i[1] = (p2), \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) -#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ - MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ - _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ - (cinfo)->err->msg_code = (code); \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) -#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ - MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ - _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ - (cinfo)->err->msg_code = (code); \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) -#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \ - MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ - _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ - _mp[4] = (p5); \ - (cinfo)->err->msg_code = (code); \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) -#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ - MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ - _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ - _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ - (cinfo)->err->msg_code = (code); \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) -#define TRACEMSS(cinfo,lvl,code,str) \ - ((cinfo)->err->msg_code = (code), \ - strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ - (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) - -#endif /* JERROR_H */ diff --git a/MechoSoma/Terra/jmorecfg.h b/MechoSoma/Terra/jmorecfg.h deleted file mode 100644 index e7d6a77b..00000000 --- a/MechoSoma/Terra/jmorecfg.h +++ /dev/null @@ -1,367 +0,0 @@ -/* - * jmorecfg.h - * - * Copyright (C) 1991-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains additional configuration options that customize the - * JPEG software for special applications or support machine-dependent - * optimizations. Most users will not need to touch this file. - */ - - -/* - * Define BITS_IN_JSAMPLE as either - * 8 for 8-bit sample values (the usual setting) - * 12 for 12-bit sample values - * Only 8 and 12 are legal data precisions for lossy JPEG according to the - * JPEG standard, and the IJG code does not support anything else! - * We do not support run-time selection of data precision, sorry. - */ - -#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ - - -/* - * Maximum number of components (color channels) allowed in JPEG image. - * To meet the letter of the JPEG spec, set this to 255. However, darn - * few applications need more than 4 channels (maybe 5 for CMYK + alpha - * mask). We recommend 10 as a reasonable compromise; use 4 if you are - * really short on memory. (Each allowed component costs a hundred or so - * bytes of storage, whether actually used in an image or not.) - */ - -#define MAX_COMPONENTS 10 /* maximum number of image components */ - - -/* - * Basic data types. - * You may need to change these if you have a machine with unusual data - * type sizes; for example, "char" not 8 bits, "short" not 16 bits, - * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits, - * but it had better be at least 16. - */ - -/* Representation of a single sample (pixel element value). - * We frequently allocate large arrays of these, so it's important to keep - * them small. But if you have memory to burn and access to char or short - * arrays is very slow on your hardware, you might want to change these. - */ - -#if BITS_IN_JSAMPLE == 8 -/* JSAMPLE should be the smallest type that will hold the values 0..255. - * You can use a signed char by having GETJSAMPLE mask it with 0xFF. - */ - -#ifdef HAVE_UNSIGNED_CHAR - -typedef unsigned char JSAMPLE; -#define GETJSAMPLE(value) ((int) (value)) - -#else /* not HAVE_UNSIGNED_CHAR */ - -typedef char JSAMPLE; -#ifdef CHAR_IS_UNSIGNED -#define GETJSAMPLE(value) ((int) (value)) -#else -#define GETJSAMPLE(value) ((int) (value) & 0xFF) -#endif /* CHAR_IS_UNSIGNED */ - -#endif /* HAVE_UNSIGNED_CHAR */ - -#define MAXJSAMPLE 255 -#define CENTERJSAMPLE 128 - -#endif /* BITS_IN_JSAMPLE == 8 */ - - -#if BITS_IN_JSAMPLE == 12 -/* JSAMPLE should be the smallest type that will hold the values 0..4095. - * On nearly all machines "short" will do nicely. - */ - -typedef short JSAMPLE; -#define GETJSAMPLE(value) ((int) (value)) - -#define MAXJSAMPLE 4095 -#define CENTERJSAMPLE 2048 - -#endif /* BITS_IN_JSAMPLE == 12 */ - - -/* Representation of a DCT frequency coefficient. - * This should be a signed value of at least 16 bits; "short" is usually OK. - * Again, we allocate large arrays of these, but you can change to int - * if you have memory to burn and "short" is really slow. - */ - -typedef short JCOEF; - - -/* Compressed datastreams are represented as arrays of JOCTET. - * These must be EXACTLY 8 bits wide, at least once they are written to - * external storage. Note that when using the stdio data source/destination - * managers, this is also the data type passed to fread/fwrite. - */ - -#ifdef HAVE_UNSIGNED_CHAR - -typedef unsigned char JOCTET; -#define GETJOCTET(value) (value) - -#else /* not HAVE_UNSIGNED_CHAR */ - -typedef char JOCTET; -#ifdef CHAR_IS_UNSIGNED -#define GETJOCTET(value) (value) -#else -#define GETJOCTET(value) ((value) & 0xFF) -#endif /* CHAR_IS_UNSIGNED */ - -#endif /* HAVE_UNSIGNED_CHAR */ - - -/* These typedefs are used for various table entries and so forth. - * They must be at least as wide as specified; but making them too big - * won't cost a huge amount of memory, so we don't provide special - * extraction code like we did for JSAMPLE. (In other words, these - * typedefs live at a different point on the speed/space tradeoff curve.) - */ - -/* UINT8 must hold at least the values 0..255. */ - -#ifdef HAVE_UNSIGNED_CHAR -typedef unsigned char UINT8; -#else /* not HAVE_UNSIGNED_CHAR */ -#ifdef CHAR_IS_UNSIGNED -typedef char UINT8; -#else /* not CHAR_IS_UNSIGNED */ -typedef short UINT8; -#endif /* CHAR_IS_UNSIGNED */ -#endif /* HAVE_UNSIGNED_CHAR */ - -/* UINT16 must hold at least the values 0..65535. */ - -#ifdef HAVE_UNSIGNED_SHORT -typedef unsigned short UINT16; -#else /* not HAVE_UNSIGNED_SHORT */ -typedef unsigned int UINT16; -#endif /* HAVE_UNSIGNED_SHORT */ - -/* INT16 must hold at least the values -32768..32767. */ - -#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ -typedef short INT16; -#endif - -/* INT32 must hold at least signed 32-bit values. */ - -#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ -typedef long INT32; -#endif - -/* Datatype used for image dimensions. The JPEG standard only supports - * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore - * "unsigned int" is sufficient on all machines. However, if you need to - * handle larger images and you don't mind deviating from the spec, you - * can change this datatype. - */ - -typedef unsigned int JDIMENSION; - -#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */ - - -/* These macros are used in all function definitions and extern declarations. - * You could modify them if you need to change function linkage conventions; - * in particular, you'll need to do that to make the library a Windows DLL. - * Another application is to make all functions global for use with debuggers - * or code profilers that require it. - */ - -/* a function called through method pointers: */ -#define METHODDEF(type) static type -/* a function used only in its module: */ -#define LOCAL(type) static type -/* a function referenced thru EXTERNs: */ -#define GLOBAL(type) type -/* a reference to a GLOBAL function: */ -#define EXTERN(type) extern type - - -/* This macro is used to declare a "method", that is, a function pointer. - * We want to supply prototype parameters if the compiler can cope. - * Note that the arglist parameter must be parenthesized! - * Again, you can customize this if you need special linkage keywords. - */ - -#ifdef HAVE_PROTOTYPES -#define JMETHOD(type,methodname,arglist) type (*methodname) arglist -#else -#define JMETHOD(type,methodname,arglist) type (*methodname) () -#endif - - -/* Here is the pseudo-keyword for declaring pointers that must be "far" - * on 80x86 machines. Most of the specialized coding for 80x86 is handled - * by just saying "FAR *" where such a pointer is needed. In a few places - * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol. - */ - - #ifdef FAR - #undef FAR - #endif - -#ifdef NEED_FAR_POINTERS -#define FAR far -#else -#define FAR -#endif - - -/* - * On a few systems, type boolean and/or its values FALSE, TRUE may appear - * in standard header files. Or you may have conflicts with application- - * specific header files that you want to include together with these files. - * Defining HAVE_BOOLEAN before including jpeglib.h should make it work. - */ - -#ifndef HAVE_BOOLEAN -typedef int boolean; -#endif -#ifndef FALSE /* in case these macros already exist */ -#define FALSE 0 /* values of boolean */ -#endif -#ifndef TRUE -#define TRUE 1 -#endif - - -/* - * The remaining options affect code selection within the JPEG library, - * but they don't need to be visible to most applications using the library. - * To minimize application namespace pollution, the symbols won't be - * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined. - */ - -#ifdef JPEG_INTERNALS -#define JPEG_INTERNAL_OPTIONS -#endif - -#ifdef JPEG_INTERNAL_OPTIONS - - -/* - * These defines indicate whether to include various optional functions. - * Undefining some of these symbols will produce a smaller but less capable - * library. Note that you can leave certain source files out of the - * compilation/linking process if you've #undef'd the corresponding symbols. - * (You may HAVE to do that if your compiler doesn't like null source files.) - */ - -/* Arithmetic coding is unsupported for legal reasons. Complaints to IBM. */ - -/* Capability options common to encoder and decoder: */ - -#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ -#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ -#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ - -/* Encoder capability options: */ - -#undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ -#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ -#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ -#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ -/* Note: if you selected 12-bit data precision, it is dangerous to turn off - * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit - * precision, so jchuff.c normally uses entropy optimization to compute - * usable tables for higher precision. If you don't want to do optimization, - * you'll have to supply different default Huffman tables. - * The exact same statements apply for progressive JPEG: the default tables - * don't work for progressive mode. (This may get fixed, however.) - */ -#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */ - -/* Decoder capability options: */ - -#undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ -#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ -#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ -#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ -#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ -#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ -#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ -#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ -#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ -#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ - -/* more capability options later, no doubt */ - - -/* - * Ordering of RGB data in scanlines passed to or from the application. - * If your application wants to deal with data in the order B,G,R, just - * change these macros. You can also deal with formats such as R,G,B,X - * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing - * the offsets will also change the order in which colormap data is organized. - * RESTRICTIONS: - * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. - * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not - * useful if you are using JPEG color spaces other than YCbCr or grayscale. - * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE - * is not 3 (they don't understand about dummy color components!). So you - * can't use color quantization if you change that value. - */ - -#define RGB_RED 0 /* Offset of Red in an RGB scanline element */ -#define RGB_GREEN 1 /* Offset of Green */ -#define RGB_BLUE 2 /* Offset of Blue */ -#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ - - -/* Definitions for speed-related optimizations. */ - - -/* If your compiler supports inline functions, define INLINE - * as the inline keyword; otherwise define it as empty. - */ - -#ifndef INLINE -#ifdef __GNUC__ /* for instance, GNU C knows about inline */ -#define INLINE __inline__ -#endif -#ifndef INLINE -#define INLINE /* default is to define it as empty */ -#endif -#endif - - -/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying - * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER - * as short on such a machine. MULTIPLIER must be at least 16 bits wide. - */ - -#ifndef MULTIPLIER -#define MULTIPLIER int /* type for fastest integer multiply */ -#endif - - -/* FAST_FLOAT should be either float or double, whichever is done faster - * by your compiler. (Note that this type is only used in the floating point - * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.) - * Typically, float is faster in ANSI C compilers, while double is faster in - * pre-ANSI compilers (because they insist on converting to double anyway). - * The code below therefore chooses float if we have ANSI-style prototypes. - */ - -#ifndef FAST_FLOAT -#ifdef HAVE_PROTOTYPES -#define FAST_FLOAT float -#else -#define FAST_FLOAT double -#endif -#endif - -#endif /* JPEG_INTERNAL_OPTIONS */ diff --git a/MechoSoma/Terra/jpeglib.h b/MechoSoma/Terra/jpeglib.h deleted file mode 100644 index b9356f39..00000000 --- a/MechoSoma/Terra/jpeglib.h +++ /dev/null @@ -1,1096 +0,0 @@ -/* - * jpeglib.h - * - * Copyright (C) 1991-1998, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file defines the application interface for the JPEG library. - * Most applications using the library need only include this file, - * and perhaps jerror.h if they want to know the exact error codes. - */ - -#ifndef JPEGLIB_H -#define JPEGLIB_H - -/* - * First we include the configuration files that record how this - * installation of the JPEG library is set up. jconfig.h can be - * generated automatically for many systems. jmorecfg.h contains - * manual configuration options that most people need not worry about. - */ - -#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */ -#include "jconfig.h" /* widely used configuration options */ -#endif -#include "jmorecfg.h" /* seldom changed options */ - - -/* Version ID for the JPEG library. - * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". - */ - -#define JPEG_LIB_VERSION 62 /* Version 6b */ - - -/* Various constants determining the sizes of things. - * All of these are specified by the JPEG standard, so don't change them - * if you want to be compatible. - */ - -#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ -#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ -#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */ -#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */ -#define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */ -#define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */ -#define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */ -/* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard; - * the PostScript DCT filter can emit files with many more than 10 blocks/MCU. - * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU - * to handle it. We even let you do this from the jconfig.h file. However, - * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe - * sometimes emits noncompliant files doesn't mean you should too. - */ -#define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */ -#ifndef D_MAX_BLOCKS_IN_MCU -#define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */ -#endif - - -/* Data structures for images (arrays of samples and of DCT coefficients). - * On 80x86 machines, the image arrays are too big for near pointers, - * but the pointer arrays can fit in near memory. - */ - -typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */ -typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */ -typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ - -typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */ -typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */ -typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */ -typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */ - -typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */ - - -/* Types for JPEG compression parameters and working tables. */ - - -/* DCT coefficient quantization tables. */ - -typedef struct { - /* This array gives the coefficient quantizers in natural array order - * (not the zigzag order in which they are stored in a JPEG DQT marker). - * CAUTION: IJG versions prior to v6a kept this array in zigzag order. - */ - UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */ - /* This field is used only during compression. It's initialized FALSE when - * the table is created, and set TRUE when it's been output to the file. - * You could suppress output of a table by setting this to TRUE. - * (See jpeg_suppress_tables for an example.) - */ - boolean sent_table; /* TRUE when table has been output */ -} JQUANT_TBL; - - -/* Huffman coding tables. */ - -typedef struct { - /* These two fields directly represent the contents of a JPEG DHT marker */ - UINT8 bits[17]; /* bits[k] = # of symbols with codes of */ - /* length k bits; bits[0] is unused */ - UINT8 huffval[256]; /* The symbols, in order of incr code length */ - /* This field is used only during compression. It's initialized FALSE when - * the table is created, and set TRUE when it's been output to the file. - * You could suppress output of a table by setting this to TRUE. - * (See jpeg_suppress_tables for an example.) - */ - boolean sent_table; /* TRUE when table has been output */ -} JHUFF_TBL; - - -/* Basic info about one component (color channel). */ - -typedef struct { - /* These values are fixed over the whole image. */ - /* For compression, they must be supplied by parameter setup; */ - /* for decompression, they are read from the SOF marker. */ - int component_id; /* identifier for this component (0..255) */ - int component_index; /* its index in SOF or cinfo->comp_info[] */ - int h_samp_factor; /* horizontal sampling factor (1..4) */ - int v_samp_factor; /* vertical sampling factor (1..4) */ - int quant_tbl_no; /* quantization table selector (0..3) */ - /* These values may vary between scans. */ - /* For compression, they must be supplied by parameter setup; */ - /* for decompression, they are read from the SOS marker. */ - /* The decompressor output side may not use these variables. */ - int dc_tbl_no; /* DC entropy table selector (0..3) */ - int ac_tbl_no; /* AC entropy table selector (0..3) */ - - /* Remaining fields should be treated as private by applications. */ - - /* These values are computed during compression or decompression startup: */ - /* Component's size in DCT blocks. - * Any dummy blocks added to complete an MCU are not counted; therefore - * these values do not depend on whether a scan is interleaved or not. - */ - JDIMENSION width_in_blocks; - JDIMENSION height_in_blocks; - /* Size of a DCT block in samples. Always DCTSIZE for compression. - * For decompression this is the size of the output from one DCT block, - * reflecting any scaling we choose to apply during the IDCT step. - * Values of 1,2,4,8 are likely to be supported. Note that different - * components may receive different IDCT scalings. - */ - int DCT_scaled_size; - /* The downsampled dimensions are the component's actual, unpadded number - * of samples at the main buffer (preprocessing/compression interface), thus - * downsampled_width = ceil(image_width * Hi/Hmax) - * and similarly for height. For decompression, IDCT scaling is included, so - * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE) - */ - JDIMENSION downsampled_width; /* actual width in samples */ - JDIMENSION downsampled_height; /* actual height in samples */ - /* This flag is used only for decompression. In cases where some of the - * components will be ignored (eg grayscale output from YCbCr image), - * we can skip most computations for the unused components. - */ - boolean component_needed; /* do we need the value of this component? */ - - /* These values are computed before starting a scan of the component. */ - /* The decompressor output side may not use these variables. */ - int MCU_width; /* number of blocks per MCU, horizontally */ - int MCU_height; /* number of blocks per MCU, vertically */ - int MCU_blocks; /* MCU_width * MCU_height */ - int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */ - int last_col_width; /* # of non-dummy blocks across in last MCU */ - int last_row_height; /* # of non-dummy blocks down in last MCU */ - - /* Saved quantization table for component; NULL if none yet saved. - * See jdinput.c comments about the need for this information. - * This field is currently used only for decompression. - */ - JQUANT_TBL * quant_table; - - /* Private per-component storage for DCT or IDCT subsystem. */ - void * dct_table; -} jpeg_component_info; - - -/* The script for encoding a multiple-scan file is an array of these: */ - -typedef struct { - int comps_in_scan; /* number of components encoded in this scan */ - int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */ - int Ss, Se; /* progressive JPEG spectral selection parms */ - int Ah, Al; /* progressive JPEG successive approx. parms */ -} jpeg_scan_info; - -/* The decompressor can save APPn and COM markers in a list of these: */ - -typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr; - -struct jpeg_marker_struct { - jpeg_saved_marker_ptr next; /* next in list, or NULL */ - UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */ - unsigned int original_length; /* # bytes of data in the file */ - unsigned int data_length; /* # bytes of data saved at data[] */ - JOCTET FAR * data; /* the data contained in the marker */ - /* the marker length word is not counted in data_length or original_length */ -}; - -/* Known color spaces. */ - -typedef enum { - JCS_UNKNOWN, /* error/unspecified */ - JCS_GRAYSCALE, /* monochrome */ - JCS_RGB, /* red/green/blue */ - JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */ - JCS_CMYK, /* C/M/Y/K */ - JCS_YCCK /* Y/Cb/Cr/K */ -} J_COLOR_SPACE; - -/* DCT/IDCT algorithm options. */ - -typedef enum { - JDCT_ISLOW, /* slow but accurate integer algorithm */ - JDCT_IFAST, /* faster, less accurate integer method */ - JDCT_FLOAT /* floating-point: accurate, fast on fast HW */ -} J_DCT_METHOD; - -#ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */ -#define JDCT_DEFAULT JDCT_ISLOW -#endif -#ifndef JDCT_FASTEST /* may be overridden in jconfig.h */ -#define JDCT_FASTEST JDCT_IFAST -#endif - -/* Dithering options for decompression. */ - -typedef enum { - JDITHER_NONE, /* no dithering */ - JDITHER_ORDERED, /* simple ordered dither */ - JDITHER_FS /* Floyd-Steinberg error diffusion dither */ -} J_DITHER_MODE; - - -/* Common fields between JPEG compression and decompression master structs. */ - -#define jpeg_common_fields \ - struct jpeg_error_mgr * err; /* Error handler module */\ - struct jpeg_memory_mgr * mem; /* Memory manager module */\ - struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\ - void * client_data; /* Available for use by application */\ - boolean is_decompressor; /* So common code can tell which is which */\ - int global_state /* For checking call sequence validity */ - -/* Routines that are to be used by both halves of the library are declared - * to receive a pointer to this structure. There are no actual instances of - * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct. - */ -struct jpeg_common_struct { - jpeg_common_fields; /* Fields common to both master struct types */ - /* Additional fields follow in an actual jpeg_compress_struct or - * jpeg_decompress_struct. All three structs must agree on these - * initial fields! (This would be a lot cleaner in C++.) - */ -}; - -typedef struct jpeg_common_struct * j_common_ptr; -typedef struct jpeg_compress_struct * j_compress_ptr; -typedef struct jpeg_decompress_struct * j_decompress_ptr; - - -/* Master record for a compression instance */ - -struct jpeg_compress_struct { - jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */ - - /* Destination for compressed data */ - struct jpeg_destination_mgr * dest; - - /* Description of source image --- these fields must be filled in by - * outer application before starting compression. in_color_space must - * be correct before you can even call jpeg_set_defaults(). - */ - - JDIMENSION image_width; /* input image width */ - JDIMENSION image_height; /* input image height */ - int input_components; /* # of color components in input image */ - J_COLOR_SPACE in_color_space; /* colorspace of input image */ - - double input_gamma; /* image gamma of input image */ - - /* Compression parameters --- these fields must be set before calling - * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to - * initialize everything to reasonable defaults, then changing anything - * the application specifically wants to change. That way you won't get - * burnt when new parameters are added. Also note that there are several - * helper routines to simplify changing parameters. - */ - - int data_precision; /* bits of precision in image data */ - - int num_components; /* # of color components in JPEG image */ - J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ - - jpeg_component_info * comp_info; - /* comp_info[i] describes component that appears i'th in SOF */ - - JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; - /* ptrs to coefficient quantization tables, or NULL if not defined */ - - JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; - JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; - /* ptrs to Huffman coding tables, or NULL if not defined */ - - UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ - UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ - UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ - - int num_scans; /* # of entries in scan_info array */ - const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */ - /* The default value of scan_info is NULL, which causes a single-scan - * sequential JPEG file to be emitted. To create a multi-scan file, - * set num_scans and scan_info to point to an array of scan definitions. - */ - - boolean raw_data_in; /* TRUE=caller supplies downsampled data */ - boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ - boolean optimize_coding; /* TRUE=optimize entropy encoding parms */ - boolean CCIR601_sampling; /* TRUE=first samples are cosited */ - int smoothing_factor; /* 1..100, or 0 for no input smoothing */ - J_DCT_METHOD dct_method; /* DCT algorithm selector */ - - /* The restart interval can be specified in absolute MCUs by setting - * restart_interval, or in MCU rows by setting restart_in_rows - * (in which case the correct restart_interval will be figured - * for each scan). - */ - unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */ - int restart_in_rows; /* if > 0, MCU rows per restart interval */ - - /* Parameters controlling emission of special markers. */ - - boolean write_JFIF_header; /* should a JFIF marker be written? */ - UINT8 JFIF_major_version; /* What to write for the JFIF version number */ - UINT8 JFIF_minor_version; - /* These three values are not used by the JPEG code, merely copied */ - /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */ - /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */ - /* ratio is defined by X_density/Y_density even when density_unit=0. */ - UINT8 density_unit; /* JFIF code for pixel size units */ - UINT16 X_density; /* Horizontal pixel density */ - UINT16 Y_density; /* Vertical pixel density */ - boolean write_Adobe_marker; /* should an Adobe marker be written? */ - - /* State variable: index of next scanline to be written to - * jpeg_write_scanlines(). Application may use this to control its - * processing loop, e.g., "while (next_scanline < image_height)". - */ - - JDIMENSION next_scanline; /* 0 .. image_height-1 */ - - /* Remaining fields are known throughout compressor, but generally - * should not be touched by a surrounding application. - */ - - /* - * These fields are computed during compression startup - */ - boolean progressive_mode; /* TRUE if scan script uses progressive mode */ - int max_h_samp_factor; /* largest h_samp_factor */ - int max_v_samp_factor; /* largest v_samp_factor */ - - JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */ - /* The coefficient controller receives data in units of MCU rows as defined - * for fully interleaved scans (whether the JPEG file is interleaved or not). - * There are v_samp_factor * DCTSIZE sample rows of each component in an - * "iMCU" (interleaved MCU) row. - */ - - /* - * These fields are valid during any one scan. - * They describe the components and MCUs actually appearing in the scan. - */ - int comps_in_scan; /* # of JPEG components in this scan */ - jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; - /* *cur_comp_info[i] describes component that appears i'th in SOS */ - - JDIMENSION MCUs_per_row; /* # of MCUs across the image */ - JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ - - int blocks_in_MCU; /* # of DCT blocks per MCU */ - int MCU_membership[C_MAX_BLOCKS_IN_MCU]; - /* MCU_membership[i] is index in cur_comp_info of component owning */ - /* i'th block in an MCU */ - - int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ - - /* - * Links to compression subobjects (methods and private variables of modules) - */ - struct jpeg_comp_master * master; - struct jpeg_c_main_controller * main; - struct jpeg_c_prep_controller * prep; - struct jpeg_c_coef_controller * coef; - struct jpeg_marker_writer * marker; - struct jpeg_color_converter * cconvert; - struct jpeg_downsampler * downsample; - struct jpeg_forward_dct * fdct; - struct jpeg_entropy_encoder * entropy; - jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */ - int script_space_size; -}; - - -/* Master record for a decompression instance */ - -struct jpeg_decompress_struct { - jpeg_common_fields; /* Fields shared with jpeg_compress_struct */ - - /* Source of compressed data */ - struct jpeg_source_mgr * src; - - /* Basic description of image --- filled in by jpeg_read_header(). */ - /* Application may inspect these values to decide how to process image. */ - - JDIMENSION image_width; /* nominal image width (from SOF marker) */ - JDIMENSION image_height; /* nominal image height */ - int num_components; /* # of color components in JPEG image */ - J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ - - /* Decompression processing parameters --- these fields must be set before - * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes - * them to default values. - */ - - J_COLOR_SPACE out_color_space; /* colorspace for output */ - - unsigned int scale_num, scale_denom; /* fraction by which to scale image */ - - double output_gamma; /* image gamma wanted in output */ - - boolean buffered_image; /* TRUE=multiple output passes */ - boolean raw_data_out; /* TRUE=downsampled data wanted */ - - J_DCT_METHOD dct_method; /* IDCT algorithm selector */ - boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */ - boolean do_block_smoothing; /* TRUE=apply interblock smoothing */ - - boolean quantize_colors; /* TRUE=colormapped output wanted */ - /* the following are ignored if not quantize_colors: */ - J_DITHER_MODE dither_mode; /* type of color dithering to use */ - boolean two_pass_quantize; /* TRUE=use two-pass color quantization */ - int desired_number_of_colors; /* max # colors to use in created colormap */ - /* these are significant only in buffered-image mode: */ - boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */ - boolean enable_external_quant;/* enable future use of external colormap */ - boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */ - - /* Description of actual output image that will be returned to application. - * These fields are computed by jpeg_start_decompress(). - * You can also use jpeg_calc_output_dimensions() to determine these values - * in advance of calling jpeg_start_decompress(). - */ - - JDIMENSION output_width; /* scaled image width */ - JDIMENSION output_height; /* scaled image height */ - int out_color_components; /* # of color components in out_color_space */ - int output_components; /* # of color components returned */ - /* output_components is 1 (a colormap index) when quantizing colors; - * otherwise it equals out_color_components. - */ - int rec_outbuf_height; /* min recommended height of scanline buffer */ - /* If the buffer passed to jpeg_read_scanlines() is less than this many rows - * high, space and time will be wasted due to unnecessary data copying. - * Usually rec_outbuf_height will be 1 or 2, at most 4. - */ - - /* When quantizing colors, the output colormap is described by these fields. - * The application can supply a colormap by setting colormap non-NULL before - * calling jpeg_start_decompress; otherwise a colormap is created during - * jpeg_start_decompress or jpeg_start_output. - * The map has out_color_components rows and actual_number_of_colors columns. - */ - int actual_number_of_colors; /* number of entries in use */ - JSAMPARRAY colormap; /* The color map as a 2-D pixel array */ - - /* State variables: these variables indicate the progress of decompression. - * The application may examine these but must not modify them. - */ - - /* Row index of next scanline to be read from jpeg_read_scanlines(). - * Application may use this to control its processing loop, e.g., - * "while (output_scanline < output_height)". - */ - JDIMENSION output_scanline; /* 0 .. output_height-1 */ - - /* Current input scan number and number of iMCU rows completed in scan. - * These indicate the progress of the decompressor input side. - */ - int input_scan_number; /* Number of SOS markers seen so far */ - JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */ - - /* The "output scan number" is the notional scan being displayed by the - * output side. The decompressor will not allow output scan/row number - * to get ahead of input scan/row, but it can fall arbitrarily far behind. - */ - int output_scan_number; /* Nominal scan number being displayed */ - JDIMENSION output_iMCU_row; /* Number of iMCU rows read */ - - /* Current progression status. coef_bits[c][i] indicates the precision - * with which component c's DCT coefficient i (in zigzag order) is known. - * It is -1 when no data has yet been received, otherwise it is the point - * transform (shift) value for the most recent scan of the coefficient - * (thus, 0 at completion of the progression). - * This pointer is NULL when reading a non-progressive file. - */ - int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */ - - /* Internal JPEG parameters --- the application usually need not look at - * these fields. Note that the decompressor output side may not use - * any parameters that can change between scans. - */ - - /* Quantization and Huffman tables are carried forward across input - * datastreams when processing abbreviated JPEG datastreams. - */ - - JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; - /* ptrs to coefficient quantization tables, or NULL if not defined */ - - JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; - JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; - /* ptrs to Huffman coding tables, or NULL if not defined */ - - /* These parameters are never carried across datastreams, since they - * are given in SOF/SOS markers or defined to be reset by SOI. - */ - - int data_precision; /* bits of precision in image data */ - - jpeg_component_info * comp_info; - /* comp_info[i] describes component that appears i'th in SOF */ - - boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */ - boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ - - UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ - UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ - UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ - - unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */ - - /* These fields record data obtained from optional markers recognized by - * the JPEG library. - */ - boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */ - /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */ - UINT8 JFIF_major_version; /* JFIF version number */ - UINT8 JFIF_minor_version; - UINT8 density_unit; /* JFIF code for pixel size units */ - UINT16 X_density; /* Horizontal pixel density */ - UINT16 Y_density; /* Vertical pixel density */ - boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */ - UINT8 Adobe_transform; /* Color transform code from Adobe marker */ - - boolean CCIR601_sampling; /* TRUE=first samples are cosited */ - - /* Aside from the specific data retained from APPn markers known to the - * library, the uninterpreted contents of any or all APPn and COM markers - * can be saved in a list for examination by the application. - */ - jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */ - - /* Remaining fields are known throughout decompressor, but generally - * should not be touched by a surrounding application. - */ - - /* - * These fields are computed during decompression startup - */ - int max_h_samp_factor; /* largest h_samp_factor */ - int max_v_samp_factor; /* largest v_samp_factor */ - - int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */ - - JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */ - /* The coefficient controller's input and output progress is measured in - * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows - * in fully interleaved JPEG scans, but are used whether the scan is - * interleaved or not. We define an iMCU row as v_samp_factor DCT block - * rows of each component. Therefore, the IDCT output contains - * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row. - */ - - JSAMPLE * sample_range_limit; /* table for fast range-limiting */ - - /* - * These fields are valid during any one scan. - * They describe the components and MCUs actually appearing in the scan. - * Note that the decompressor output side must not use these fields. - */ - int comps_in_scan; /* # of JPEG components in this scan */ - jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; - /* *cur_comp_info[i] describes component that appears i'th in SOS */ - - JDIMENSION MCUs_per_row; /* # of MCUs across the image */ - JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ - - int blocks_in_MCU; /* # of DCT blocks per MCU */ - int MCU_membership[D_MAX_BLOCKS_IN_MCU]; - /* MCU_membership[i] is index in cur_comp_info of component owning */ - /* i'th block in an MCU */ - - int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ - - /* This field is shared between entropy decoder and marker parser. - * It is either zero or the code of a JPEG marker that has been - * read from the data source, but has not yet been processed. - */ - int unread_marker; - - /* - * Links to decompression subobjects (methods, private variables of modules) - */ - struct jpeg_decomp_master * master; - struct jpeg_d_main_controller * main; - struct jpeg_d_coef_controller * coef; - struct jpeg_d_post_controller * post; - struct jpeg_input_controller * inputctl; - struct jpeg_marker_reader * marker; - struct jpeg_entropy_decoder * entropy; - struct jpeg_inverse_dct * idct; - struct jpeg_upsampler * upsample; - struct jpeg_color_deconverter * cconvert; - struct jpeg_color_quantizer * cquantize; -}; - - -/* "Object" declarations for JPEG modules that may be supplied or called - * directly by the surrounding application. - * As with all objects in the JPEG library, these structs only define the - * publicly visible methods and state variables of a module. Additional - * private fields may exist after the public ones. - */ - - -/* Error handler object */ - -struct jpeg_error_mgr { - /* Error exit handler: does not return to caller */ - JMETHOD(void, error_exit, (j_common_ptr cinfo)); - /* Conditionally emit a trace or warning message */ - JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level)); - /* Routine that actually outputs a trace or error message */ - JMETHOD(void, output_message, (j_common_ptr cinfo)); - /* Format a message string for the most recent JPEG error or message */ - JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer)); -#define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */ - /* Reset error state variables at start of a new image */ - JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo)); - - /* The message ID code and any parameters are saved here. - * A message can have one string parameter or up to 8 int parameters. - */ - int msg_code; -#define JMSG_STR_PARM_MAX 80 - union { - int i[8]; - char s[JMSG_STR_PARM_MAX]; - } msg_parm; - - /* Standard state variables for error facility */ - - int trace_level; /* max msg_level that will be displayed */ - - /* For recoverable corrupt-data errors, we emit a warning message, - * but keep going unless emit_message chooses to abort. emit_message - * should count warnings in num_warnings. The surrounding application - * can check for bad data by seeing if num_warnings is nonzero at the - * end of processing. - */ - long num_warnings; /* number of corrupt-data warnings */ - - /* These fields point to the table(s) of error message strings. - * An application can change the table pointer to switch to a different - * message list (typically, to change the language in which errors are - * reported). Some applications may wish to add additional error codes - * that will be handled by the JPEG library error mechanism; the second - * table pointer is used for this purpose. - * - * First table includes all errors generated by JPEG library itself. - * Error code 0 is reserved for a "no such error string" message. - */ - const char * const * jpeg_message_table; /* Library errors */ - int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */ - /* Second table can be added by application (see cjpeg/djpeg for example). - * It contains strings numbered first_addon_message..last_addon_message. - */ - const char * const * addon_message_table; /* Non-library errors */ - int first_addon_message; /* code for first string in addon table */ - int last_addon_message; /* code for last string in addon table */ -}; - - -/* Progress monitor object */ - -struct jpeg_progress_mgr { - JMETHOD(void, progress_monitor, (j_common_ptr cinfo)); - - long pass_counter; /* work units completed in this pass */ - long pass_limit; /* total number of work units in this pass */ - int completed_passes; /* passes completed so far */ - int total_passes; /* total number of passes expected */ -}; - - -/* Data destination object for compression */ - -struct jpeg_destination_mgr { - JOCTET * next_output_byte; /* => next byte to write in buffer */ - size_t free_in_buffer; /* # of byte spaces remaining in buffer */ - - JMETHOD(void, init_destination, (j_compress_ptr cinfo)); - JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo)); - JMETHOD(void, term_destination, (j_compress_ptr cinfo)); -}; - - -/* Data source object for decompression */ - -struct jpeg_source_mgr { - const JOCTET * next_input_byte; /* => next byte to read from buffer */ - size_t bytes_in_buffer; /* # of bytes remaining in buffer */ - - JMETHOD(void, init_source, (j_decompress_ptr cinfo)); - JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo)); - JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes)); - JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired)); - JMETHOD(void, term_source, (j_decompress_ptr cinfo)); -}; - - -/* Memory manager object. - * Allocates "small" objects (a few K total), "large" objects (tens of K), - * and "really big" objects (virtual arrays with backing store if needed). - * The memory manager does not allow individual objects to be freed; rather, - * each created object is assigned to a pool, and whole pools can be freed - * at once. This is faster and more convenient than remembering exactly what - * to free, especially where malloc()/free() are not too speedy. - * NB: alloc routines never return NULL. They exit to error_exit if not - * successful. - */ - -#define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */ -#define JPOOL_IMAGE 1 /* lasts until done with image/datastream */ -#define JPOOL_NUMPOOLS 2 - -typedef struct jvirt_sarray_control * jvirt_sarray_ptr; -typedef struct jvirt_barray_control * jvirt_barray_ptr; - - -struct jpeg_memory_mgr { - /* Method pointers */ - JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id, - size_t sizeofobject)); - JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id, - size_t sizeofobject)); - JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id, - JDIMENSION samplesperrow, - JDIMENSION numrows)); - JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id, - JDIMENSION blocksperrow, - JDIMENSION numrows)); - JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo, - int pool_id, - boolean pre_zero, - JDIMENSION samplesperrow, - JDIMENSION numrows, - JDIMENSION maxaccess)); - JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo, - int pool_id, - boolean pre_zero, - JDIMENSION blocksperrow, - JDIMENSION numrows, - JDIMENSION maxaccess)); - JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo)); - JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo, - jvirt_sarray_ptr ptr, - JDIMENSION start_row, - JDIMENSION num_rows, - boolean writable)); - JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo, - jvirt_barray_ptr ptr, - JDIMENSION start_row, - JDIMENSION num_rows, - boolean writable)); - JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id)); - JMETHOD(void, self_destruct, (j_common_ptr cinfo)); - - /* Limit on memory allocation for this JPEG object. (Note that this is - * merely advisory, not a guaranteed maximum; it only affects the space - * used for virtual-array buffers.) May be changed by outer application - * after creating the JPEG object. - */ - long max_memory_to_use; - - /* Maximum allocation request accepted by alloc_large. */ - long max_alloc_chunk; -}; - - -/* Routine signature for application-supplied marker processing methods. - * Need not pass marker code since it is stored in cinfo->unread_marker. - */ -typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo)); - - -/* Declarations for routines called by application. - * The JPP macro hides prototype parameters from compilers that can't cope. - * Note JPP requires double parentheses. - */ - -#ifdef HAVE_PROTOTYPES -#define JPP(arglist) arglist -#else -#define JPP(arglist) () -#endif - - -/* Short forms of external names for systems with brain-damaged linkers. - * We shorten external names to be unique in the first six letters, which - * is good enough for all known systems. - * (If your compiler itself needs names to be unique in less than 15 - * characters, you are out of luck. Get a better compiler.) - */ - -#ifdef NEED_SHORT_EXTERNAL_NAMES -#define jpeg_std_error jStdError -#define jpeg_CreateCompress jCreaCompress -#define jpeg_CreateDecompress jCreaDecompress -#define jpeg_destroy_compress jDestCompress -#define jpeg_destroy_decompress jDestDecompress -#define jpeg_stdio_dest jStdDest -#define jpeg_stdio_src jStdSrc -#define jpeg_set_defaults jSetDefaults -#define jpeg_set_colorspace jSetColorspace -#define jpeg_default_colorspace jDefColorspace -#define jpeg_set_quality jSetQuality -#define jpeg_set_linear_quality jSetLQuality -#define jpeg_add_quant_table jAddQuantTable -#define jpeg_quality_scaling jQualityScaling -#define jpeg_simple_progression jSimProgress -#define jpeg_suppress_tables jSuppressTables -#define jpeg_alloc_quant_table jAlcQTable -#define jpeg_alloc_huff_table jAlcHTable -#define jpeg_start_compress jStrtCompress -#define jpeg_write_scanlines jWrtScanlines -#define jpeg_finish_compress jFinCompress -#define jpeg_write_raw_data jWrtRawData -#define jpeg_write_marker jWrtMarker -#define jpeg_write_m_header jWrtMHeader -#define jpeg_write_m_byte jWrtMByte -#define jpeg_write_tables jWrtTables -#define jpeg_read_header jReadHeader -#define jpeg_start_decompress jStrtDecompress -#define jpeg_read_scanlines jReadScanlines -#define jpeg_finish_decompress jFinDecompress -#define jpeg_read_raw_data jReadRawData -#define jpeg_has_multiple_scans jHasMultScn -#define jpeg_start_output jStrtOutput -#define jpeg_finish_output jFinOutput -#define jpeg_input_complete jInComplete -#define jpeg_new_colormap jNewCMap -#define jpeg_consume_input jConsumeInput -#define jpeg_calc_output_dimensions jCalcDimensions -#define jpeg_save_markers jSaveMarkers -#define jpeg_set_marker_processor jSetMarker -#define jpeg_read_coefficients jReadCoefs -#define jpeg_write_coefficients jWrtCoefs -#define jpeg_copy_critical_parameters jCopyCrit -#define jpeg_abort_compress jAbrtCompress -#define jpeg_abort_decompress jAbrtDecompress -#define jpeg_abort jAbort -#define jpeg_destroy jDestroy -#define jpeg_resync_to_restart jResyncRestart -#endif /* NEED_SHORT_EXTERNAL_NAMES */ - - -/* Default error-management setup */ -EXTERN(struct jpeg_error_mgr *) jpeg_std_error - JPP((struct jpeg_error_mgr * err)); - -/* Initialization of JPEG compression objects. - * jpeg_create_compress() and jpeg_create_decompress() are the exported - * names that applications should call. These expand to calls on - * jpeg_CreateCompress and jpeg_CreateDecompress with additional information - * passed for version mismatch checking. - * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx. - */ -#define jpeg_create_compress(cinfo) \ - jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \ - (size_t) sizeof(struct jpeg_compress_struct)) -#define jpeg_create_decompress(cinfo) \ - jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \ - (size_t) sizeof(struct jpeg_decompress_struct)) -EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo, - int version, size_t structsize)); -EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo, - int version, size_t structsize)); -/* Destruction of JPEG compression objects */ -EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo)); -EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo)); - -/* Standard data source and destination managers: stdio streams. */ -/* Caller is responsible for opening the file before and closing after. */ -EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile)); -EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile)); - -/* Default parameter setup for compression */ -EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); -/* Compression parameter setup aids */ -EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo, - J_COLOR_SPACE colorspace)); -EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo)); -EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality, - boolean force_baseline)); -EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo, - int scale_factor, - boolean force_baseline)); -EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl, - const unsigned int *basic_table, - int scale_factor, - boolean force_baseline)); -EXTERN(int) jpeg_quality_scaling JPP((int quality)); -EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo)); -EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo, - boolean suppress)); -EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo)); -EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo)); - -/* Main entry points for compression */ -EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, - boolean write_all_tables)); -EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo, - JSAMPARRAY scanlines, - JDIMENSION num_lines)); -EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo)); - -/* Replaces jpeg_write_scanlines when writing raw downsampled data. */ -EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo, - JSAMPIMAGE data, - JDIMENSION num_lines)); - -/* Write a special marker. See libjpeg.doc concerning safe usage. */ -EXTERN(void) jpeg_write_marker - JPP((j_compress_ptr cinfo, int marker, - const JOCTET * dataptr, unsigned int datalen)); -/* Same, but piecemeal. */ -EXTERN(void) jpeg_write_m_header - JPP((j_compress_ptr cinfo, int marker, unsigned int datalen)); -EXTERN(void) jpeg_write_m_byte - JPP((j_compress_ptr cinfo, int val)); - -/* Alternate compression function: just write an abbreviated table file */ -EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo)); - -/* Decompression startup: read start of JPEG datastream to see what's there */ -EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo, - boolean require_image)); -/* Return value is one of: */ -#define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */ -#define JPEG_HEADER_OK 1 /* Found valid image datastream */ -#define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */ -/* If you pass require_image = TRUE (normal case), you need not check for - * a TABLES_ONLY return code; an abbreviated file will cause an error exit. - * JPEG_SUSPENDED is only possible if you use a data source module that can - * give a suspension return (the stdio source module doesn't). - */ - -/* Main entry points for decompression */ -EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo)); -EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo, - JSAMPARRAY scanlines, - JDIMENSION max_lines)); -EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo)); - -/* Replaces jpeg_read_scanlines when reading raw downsampled data. */ -EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo, - JSAMPIMAGE data, - JDIMENSION max_lines)); - -/* Additional entry points for buffered-image mode. */ -EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo)); -EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo, - int scan_number)); -EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo)); -EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo)); -EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo)); -EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo)); -/* Return value is one of: */ -/* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ -#define JPEG_REACHED_SOS 1 /* Reached start of new scan */ -#define JPEG_REACHED_EOI 2 /* Reached end of image */ -#define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */ -#define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */ - -/* Precalculate output dimensions for current decompression parameters. */ -EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo)); - -/* Control saving of COM and APPn markers into marker_list. */ -EXTERN(void) jpeg_save_markers - JPP((j_decompress_ptr cinfo, int marker_code, - unsigned int length_limit)); - -/* Install a special processing method for COM or APPn markers. */ -EXTERN(void) jpeg_set_marker_processor - JPP((j_decompress_ptr cinfo, int marker_code, - jpeg_marker_parser_method routine)); - -/* Read or write raw DCT coefficients --- useful for lossless transcoding. */ -EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo)); -EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo, - jvirt_barray_ptr * coef_arrays)); -EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo, - j_compress_ptr dstinfo)); - -/* If you choose to abort compression or decompression before completing - * jpeg_finish_(de)compress, then you need to clean up to release memory, - * temporary files, etc. You can just call jpeg_destroy_(de)compress - * if you're done with the JPEG object, but if you want to clean it up and - * reuse it, call this: - */ -EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo)); -EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo)); - -/* Generic versions of jpeg_abort and jpeg_destroy that work on either - * flavor of JPEG object. These may be more convenient in some places. - */ -EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo)); -EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo)); - -/* Default restart-marker-resync procedure for use by data source modules */ -EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo, - int desired)); - - -/* These marker codes are exported since applications and data source modules - * are likely to want to use them. - */ - -#define JPEG_RST0 0xD0 /* RST0 marker code */ -#define JPEG_EOI 0xD9 /* EOI marker code */ -#define JPEG_APP0 0xE0 /* APP0 marker code */ -#define JPEG_COM 0xFE /* COM marker code */ - - -/* If we have a brain-damaged compiler that emits warnings (or worse, errors) - * for structure definitions that are never filled in, keep it quiet by - * supplying dummy definitions for the various substructures. - */ - -#ifdef INCOMPLETE_TYPES_BROKEN -#ifndef JPEG_INTERNALS /* will be defined in jpegint.h */ -struct jvirt_sarray_control { long dummy; }; -struct jvirt_barray_control { long dummy; }; -struct jpeg_comp_master { long dummy; }; -struct jpeg_c_main_controller { long dummy; }; -struct jpeg_c_prep_controller { long dummy; }; -struct jpeg_c_coef_controller { long dummy; }; -struct jpeg_marker_writer { long dummy; }; -struct jpeg_color_converter { long dummy; }; -struct jpeg_downsampler { long dummy; }; -struct jpeg_forward_dct { long dummy; }; -struct jpeg_entropy_encoder { long dummy; }; -struct jpeg_decomp_master { long dummy; }; -struct jpeg_d_main_controller { long dummy; }; -struct jpeg_d_coef_controller { long dummy; }; -struct jpeg_d_post_controller { long dummy; }; -struct jpeg_input_controller { long dummy; }; -struct jpeg_marker_reader { long dummy; }; -struct jpeg_entropy_decoder { long dummy; }; -struct jpeg_inverse_dct { long dummy; }; -struct jpeg_upsampler { long dummy; }; -struct jpeg_color_deconverter { long dummy; }; -struct jpeg_color_quantizer { long dummy; }; -#endif /* JPEG_INTERNALS */ -#endif /* INCOMPLETE_TYPES_BROKEN */ - - -/* - * The JPEG library modules define JPEG_INTERNALS before including this file. - * The internal structure declarations are read only when that is true. - * Applications using the library should not include jpegint.h, but may wish - * to include jerror.h. - */ - -#ifdef JPEG_INTERNALS -#include "jpegint.h" /* fetch private declarations */ -#include "jerror.h" /* fetch error codes too */ -#endif - -#endif /* JPEGLIB_H */ diff --git a/MechoSoma/Terra/non_rotate_scan_min_full.cpp b/MechoSoma/Terra/non_rotate_scan_min_full.cpp index 1939e929..68a60c07 100644 --- a/MechoSoma/Terra/non_rotate_scan_min_full.cpp +++ b/MechoSoma/Terra/non_rotate_scan_min_full.cpp @@ -8,7 +8,7 @@ z_buffer_type zBuffer[MAXX*MAXY]; #else -#include "terra.h" +#include "TERRA.H" //#include "common.h" //#include "vmap.h" //#include "world.h" diff --git a/MechoSoma/Terra/sur_scr.cpp b/MechoSoma/Terra/sur_scr.cpp index 9233ca9e..e0babcad 100644 --- a/MechoSoma/Terra/sur_scr.cpp +++ b/MechoSoma/Terra/sur_scr.cpp @@ -1,13 +1,20 @@ #include "StdAfx.h" #ifdef _MECHOSOMA_ -#include "Mechosoma.h" +#include "mechosoma.h" #endif -#include "terra.h" +#include "TERRA.H" #include "sur_scr.h" +#ifndef _WIN32 +char *itoa(int number, char *dest, size_t dest_size) +{ + return nullptr; +} +#endif + s_sur_scr sur_scr; int get_lex(char*& buf, char* world) @@ -36,7 +43,7 @@ int get_line(XStream& f, char* buf, int maxL){ char b; if (maxL==0) return 0; int len=0; - f.read(&b,1);// Ïðîïóñê ñëóæåáíûõ ñèìâîëîâ â íà÷àëå ñòðîêè + f.read(&b,1);// ������� ��������� �������� � ������ ������ while(isspace(b)) {f.read(&b,1);} do { *buf=b; @@ -93,11 +100,11 @@ int s_sur_scr::load_scr(char* fname) char* buf,*buft,*world; buft=buf=new char[256]; world=new char[256]; char b; - //ÎÏÎÇÍÀÍÈÅ ñêðèïòà è âåðñèè + //��������� ������� � ������ f.read(buf,7); buf[7]=0; if(strcmp(buf,"SUR_SCR")!=0) { delete world; delete buft; f.close(); return 0;} f >=version; - //Îïðåäåëåíèå òèïà ÿ÷åéêè (îáû÷íàÿ èëè íàïðàâëåííàÿ) + //����������� ���� ������ (������� ��� ������������) get_line(f,buf=buft,255); type=CELL_NOT_CLEAR; if(get_lex(buf,world)) @@ -120,23 +127,23 @@ int s_sur_scr::load_scr(char* fname) } if(type==CELL_NOT_CLEAR) return 0; - // Ïîèñê ñêðèïòà { script } + // ����� ������� { script } f.seek(7, XS_BEG); struct { int begin,end; } script={0,0}; - while( !f.eof()){ //Ïîèñê íà÷àëà ñêðèïòà + while( !f.eof()){ //����� ������ ������� f.read(&b,1); if(b=='{') { script.begin=f.tell(); break; } } - while( !f.eof()){ //Ïîèñê êîíöà ñêðèïòà + while( !f.eof()){ //����� ����� ������� f.read(&b,1); if(b=='}') { script.end=f.tell(); break; } } - if(script.end <= script.begin) {delete world; delete buft; f.close(); return 0;} //Âûõîä åñëè íåò ñêðèïòà + if(script.end <= script.begin) {delete world; delete buft; f.close(); return 0;} //����� ���� ��� ������� f.seek(script.begin+1, XS_BEG); while(f.tell() < script.end){ //f.getline(buf,255); @@ -175,7 +182,7 @@ void s_sur_scr::load_data() int t_int; double t_double; - while( !f.eof()) { f.read(&b,1); if(b=='}') break; }//Ïîèñê êîíöà ñêðèïòà + while( !f.eof()) { f.read(&b,1); if(b=='}') break; }//����� ����� ������� int x,y,a,i; while( !f.eof()){ @@ -219,7 +226,7 @@ void s_sur_scr::save_data_release() double t_double; char* t_char; - while( !fi.eof() ) { fi.read(&b,1); fo.write(&b,1); if(b=='}') break; } //Ïîèñê êîíöà ñêðèïòà + while( !fi.eof() ) { fi.read(&b,1); fo.write(&b,1); if(b=='}') break; } //����� ����� ������� for( j=0; j=ver_up; - if(ver_up <= version ) ErrH.Abort("Ñòàðàÿ âåðñèÿ Updata ñêðèïòà"); + if(ver_up <= version ) ErrH.Abort("������ ������ Updata �������"); XStream fout(0); if(!fout.open(name_scr,XS_OUT)) return 0; fout < "SUR_SCR " <=ver_up < "\n"; - //Îïðåäåëåíèå òèïà ÿ÷åéêè (îáû÷íàÿ èëè íàïðàâëåííàÿ) + //����������� ���� ������ (������� ��� ������������) get_line(f,buf=buft,255); int newtype; newtype=CELL_NOT_CLEAR; @@ -418,23 +425,23 @@ int s_sur_scr::convert(char* name_scr, char* name_update_scr) } if(newtype==CELL_NOT_CLEAR) return 0; - // Ïîèñê ñêðèïòà { script } + // ����� ������� { script } f.seek(10, XS_BEG); struct { int begin,end; } script={0,0}; - while( !f.eof()){ //Ïîèñê íà÷àëà ñêðèïòà + while( !f.eof()){ //����� ������ ������� f.read(&b,1); if(b=='{') { script.begin=f.tell(); break; } } - while( !f.eof()){ //Ïîèñê êîíöà ñêðèïòà + while( !f.eof()){ //����� ����� ������� f.read(&b,1); if(b=='}') { script.end=f.tell(); break; } } - if(script.end <= script.begin) {delete world; delete buft; f.close(); return 0;} //Âûõîä åñëè íåò ñêðèïòà + if(script.end <= script.begin) {delete world; delete buft; f.close(); return 0;} //����� ���� ��� ������� f.seek(script.begin+1, XS_BEG); beg_num_rows=numbers_rows; fout < "{\n"; @@ -445,7 +452,7 @@ int s_sur_scr::convert(char* name_scr, char* name_update_scr) } fout < "}\n"; -// Çàïèñü äàííûõ â ôàéë +// ������ ������ � ���� int j,i,t_int; double t_double; char* t_char; @@ -455,7 +462,7 @@ int s_sur_scr::convert(char* name_scr, char* name_update_scr) row[i].get_el(j,t_int); fout< "\n" <=t_int; } - else ErrH.Abort("Ôèãíÿ çàìåñòî X,Y"); + else ErrH.Abort("����� ������� X,Y"); } if(newtype==CELL_DIRECTED){ if(type==CELL_DIRECTED) row[i].get_el(j,t_int); @@ -482,14 +489,14 @@ int s_sur_scr::convert(char* name_scr, char* name_update_scr) // delete world; fout < "\n"; fout.close(); -// Êîíåö çàïèñè â ôàéë +// ����� ������ � ���� // strcpy(name_scr,fname); delete world; delete buft; f.close(); return 1; // - return 0;//Îøèáêà + return 0;//������ return 1; } diff --git a/MechoSoma/Terra/sur_scr.h b/MechoSoma/Terra/sur_scr.h index 95d7c642..9bc080e8 100644 --- a/MechoSoma/Terra/sur_scr.h +++ b/MechoSoma/Terra/sur_scr.h @@ -2,7 +2,7 @@ #define __SUR_SCR_H__ #include -#include "_xtool.h" +#include "xtool.h" #ifdef _SURMAP_ #include "color.h" diff --git a/MechoSoma/Terra/tools.cpp b/MechoSoma/Terra/tools.cpp index 389616ef..260db404 100644 --- a/MechoSoma/Terra/tools.cpp +++ b/MechoSoma/Terra/tools.cpp @@ -11,7 +11,7 @@ #include "tools.h" //#include "sqexp.h" -#include "terra.h" +#include "TERRA.H" #include "sur_scr.h" //#include "vmap.h" //#include "world.h" @@ -20,6 +20,13 @@ //#include "moveland.h" //#include "all.h" +#ifndef _WIN32 +char *itoa(int number, char *dest, size_t dest_size) +{ + return nullptr; +} +#endif + /* ----------------------------- EXTERN SECTION ---------------------------- */ //extern int LayerStatus; //extern int TunnelHeight; @@ -105,7 +112,7 @@ void BitMap::convert(void) { unsigned char* pb = palette; unsigned char* p = data; - register int i,j; + int i,j; int v,max = 0; for(i = 0;i < sz;i++,p++){ v = *p*3; @@ -163,7 +170,7 @@ void BitMap::place(char* name,int x,int y,int _force,int _mode,int _border,int _ // vMap -> increase(y,y + sy - 1); - register int i,j; + int i,j; int v,xx,yy,vv; for(j = 0;j < sy;j++){ //pv0 = pv = &(vMap -> VxBuf[0][yy = YCYCL(y + j)][0]); @@ -216,7 +223,7 @@ void BitMap::place(char* name,int x,int y,int _force,int _mode,int _border,int _ int xt,yt; int xpp=0,ypp=0; - register int i,j; + int i,j; int v,xx,yy,vv; for(j = 0;j < sy;j++){ xt=xbeg; yt=ybeg; @@ -357,7 +364,7 @@ void S3Dload(char* name,int x, int y) void S3Danalyze(void) { - //Ïðîâåðêà íà ïîäîçðèòåëüíûé ýêñöåïøèí + //�������� �� �������������� ��������� if((upper_buffer==0)||(lower_buffer==0)) ErrH.Abort("Shape Buf is NULL"); //unsigned char** lt = vMap -> lineT; int x = shape_x; @@ -370,7 +377,7 @@ void S3Danalyze(void) if(!S3Dside) surface = upper_buffer, empty = 0; else surface = lower_buffer, empty = MAX_VX_HEIGHT; - register int i,j; + int i,j; for(j = 0;j < xysize;j++){ p = surface + (j << shape_shift); // pa0 = lt[yy = YCYCL(y + j)]; diff --git a/MechoSoma/Terra/tools.h b/MechoSoma/Terra/tools.h index 9ca4f691..7f2028e3 100644 --- a/MechoSoma/Terra/tools.h +++ b/MechoSoma/Terra/tools.h @@ -1,6 +1,6 @@ #ifndef __TOOLS_H__ #define __TOOLS_H__ -#include "terra.h" +#include "TERRA.H" extern int MosaicTypes[8]; diff --git a/MechoSoma/ThirdParty/aci_Parser/aci_parser.cpp b/MechoSoma/ThirdParty/aci_Parser/aci_parser.cpp new file mode 100644 index 00000000..c610d0c1 --- /dev/null +++ b/MechoSoma/ThirdParty/aci_Parser/aci_parser.cpp @@ -0,0 +1,366 @@ +#include "aci_parser.h" + +#include + +int** scrStringData = NULL; + +char* scrOutputDIR = ""; +char* scrOutputFILE = NULL; +char* scrInputDIR = ""; + +scrDataBlock* scrRoot; +int scrVerboseFlag = 1; +int scrSavePacked = 1; + +int scrVersion = 1; + +scrDataBlock::scrDataBlock(int tp) +{ + ID = 0; + flags = 0; + dataSize = 1; + dataType = tp; + + name = NULL; + owner = NULL; + + list = NULL; + next = NULL; + prev = NULL; +} + +scrDataBlock::scrDataBlock(void) +{ + ID = 0; + flags = 0; + dataSize = 0; + dataType = 0; + + dataSize0 = -1; + name = NULL; + + owner = NULL; + nextLevel = NULL; + + list = NULL; + next = NULL; + prev = NULL; +} + +scrDataBlock::~scrDataBlock(void) +{ + freeData(); + + if(nextLevel) + delete nextLevel; + + if(name) + delete name; +} + +void scrDataBlock::saveInfo(XStream& fh) +{ + int sz = 0; + + fh < ID < dataSize < dataType < dataSize0; + if(name) sz = strlen(name); + + fh < sz; + if(name) fh < name; + + if(nextLevel){ + fh < (int)1; + scrDataBlock* p = nextLevel -> first(); + while(p){ + p -> saveInfo(fh); + p = p -> next; + } + } + else { + fh < (int)0; + } +} + +void scrDataBlock::saveData(XStream& fh) +{ + if(dataSize){ + switch(dataType){ + case SCR_INT_DATA: + fh.write((char*)i_dataPtr,dataSize * sizeof(int)); + break; + case SCR_DOUBLE_DATA: + fh.write((char*)d_dataPtr,dataSize * sizeof(double)); + break; + case SCR_CHAR_DATA: + fh.write(c_dataPtr,dataSize); + break; + } + } + if(nextLevel){ + scrDataBlock* p = nextLevel -> first(); + while(p){ + p -> saveInfo(fh); + p = p -> next; + } + } +} + +void scrDataBlock::loadInfo(XStream& fh) +{ + int i,sz = 0; + scrDataBlock* p; + + fh > ID > dataSize > dataType > sz; + + if(scrVersion >= 2) + fh > dataSize0; + + if(sz){ + name = new char[sz + 1]; + fh.read(name,sz); + name[sz] = 0; + } + fh > sz; + + allocData(); + + if(sz){ + for(i = 0; i < sz; i ++){ + p = new scrDataBlock; + p -> loadInfo(fh); + add(p); + } + } +} + +void scrDataBlock::loadData(XStream& fh) +{ + if(dataSize){ + switch(dataType){ + case SCR_INT_DATA: + fh.read((char*)i_dataPtr,dataSize * sizeof(int)); + break; + case SCR_DOUBLE_DATA: + fh.read((char*)d_dataPtr,dataSize * sizeof(double)); + break; + case SCR_CHAR_DATA: + fh.read(c_dataPtr,dataSize); + break; + } + } + if(nextLevel){ + scrDataBlock* p = nextLevel -> first(); + while(p){ + p -> loadData(fh); + p = p -> next; + } + } +} + +void scrDataBlock::loadInfo(XBuffer& xb) +{ + int i,sz = 0; + scrDataBlock* p; + + xb > ID > dataSize > dataType; + + if(scrVersion >= 2) + xb > dataSize0; + + xb > sz; + + if(sz){ + name = new char[sz + 1]; + xb.read(name,sz); + name[sz] = 0; + } + xb > sz; + + allocData(); + + if(sz){ + for(i = 0; i < sz; i ++){ + p = new scrDataBlock; + p -> loadInfo(xb); + add(p); + } + } +} + +void scrDataBlock::loadData(XBuffer& xb) +{ + if(dataSize){ + switch(dataType){ + case SCR_INT_DATA: + xb.read((char*)i_dataPtr,dataSize * sizeof(int)); + break; + case SCR_DOUBLE_DATA: + xb.read((char*)d_dataPtr,dataSize * sizeof(double)); + break; + case SCR_CHAR_DATA: + xb.read(c_dataPtr,dataSize); + break; + } + } + if(nextLevel){ + scrDataBlock* p = nextLevel -> first(); + while(p){ + p -> loadData(xb); + p = p -> next; + } + } +} + +void scrDataBlock::alloc(int tp,int sz) +{ + dataType = tp; + dataSize = sz; + + allocData(); +} + +void scrDataBlock::allocData(void) +{ + freeData(); + switch(dataType){ + case SCR_INT_DATA: + i_dataPtr = new int[dataSize]; + break; + case SCR_DOUBLE_DATA: + d_dataPtr = new double[dataSize]; + break; + case SCR_CHAR_DATA: + c_dataPtr = new char[dataSize]; + break; + } + flags |= SCR_ALLOC_DATA; +} + +void scrDataBlock::freeData(void) +{ + if(flags & SCR_ALLOC_DATA){ + switch(dataType){ + case SCR_INT_DATA: + delete i_dataPtr; + break; + case SCR_DOUBLE_DATA: + delete d_dataPtr; + break; + case SCR_CHAR_DATA: + delete c_dataPtr; + break; + } + flags ^= SCR_ALLOC_DATA; + } +} + +void scrDataBlock::add(scrDataBlock* p) +{ + if(nextLevel == NULL) + { + allocList(); + } + + nextLevel->append(p); + p -> owner = this; +} + +void scrSetVerbose(int v) +{ + scrVerboseFlag = v; +} + +void scrSetInputDir(char* p) +{ + scrInputDIR = strdup(p); +} + +void scrSetOutputDir(char* p) +{ + scrOutputDIR = strdup(p); +} + +void scrSetOutputFile(char* p) +{ + scrOutputFILE = strdup(p); +} + +scrDataBlock* loadScript(const std::filesystem::path &path) +{ + XStream fh(path.c_str(),XS_IN); + return loadScript(fh); +} + +scrDataBlock* loadScript(XStream& fh) +{ + int sz0,sz1,type; + char* p0,*p1; + + scrDataBlock* p = new scrDataBlock; + + fh > type; + + scrVersion = type; + + if(!type){ + fh.seek(0,XS_BEG); + sz1 = fh.size(); + p1 = new char[sz1]; + fh.read(p1,sz1); + } + else { + sz0 = fh.size() - sizeof(int); + p0 = new char[sz0]; + fh.read(p0,sz0); + + sz1 = ZIP_GetExpandedSize(p0); + p1 = new char[sz1]; + ZIP_expand(p1,sz1,p0,sz0); + + delete p0; + } + + XBuffer buf(p1,sz1); + + p -> loadInfo(buf); + p -> loadData(buf); + + fh.close(); + delete p1; + + return p; +} + +scrDataBlock* parseScript(char* fname,char *set_name) +{ + return NULL; +} + +void saveScript(char* fname,scrDataBlock* p) +{ + int sz0,sz1,type = 2; + char* p0,*p1; + + XStream fh(fname,XS_OUT); + p -> saveInfo(fh); + p -> saveData(fh); + fh.close(); + + if(scrSavePacked){ + fh.open(fname,XS_IN); + sz0 = fh.size(); + p0 = new char[sz0]; + fh.read(p0,sz0); + fh.close(); + + p1 = new char[sz0]; + sz1 = ZIP_compress(p1,sz0,p0,sz0); + fh.open(fname,XS_OUT); + fh < type; + fh.write(p1,sz1); + fh.close(); + + delete p0; + delete p1; + } +} diff --git a/MechoSoma/ThirdParty/aci_Parser/aci_parser.h b/MechoSoma/ThirdParty/aci_Parser/aci_parser.h new file mode 100644 index 00000000..2f03ef16 --- /dev/null +++ b/MechoSoma/ThirdParty/aci_Parser/aci_parser.h @@ -0,0 +1,84 @@ + +#ifndef __ACI_PARSER_H__ +#define __ACI_PARSER_H__ + +#include + +#include "xtool.h" + +// scrDataBlock flags... +#define SCR_ALLOC_DATA 0x01 + +// Data types... +enum scrDataTypes { + SCR_VOID_DATA = 0, + SCR_INT_DATA, + SCR_DOUBLE_DATA, + SCR_CHAR_DATA, + + SCR_MAX_DATA_ID +}; + +struct scrDataBlock +{ + int ID; + int flags; + int dataSize; + int dataType; + + int dataSize0; + char* name; + + union { + int* i_dataPtr; + double* d_dataPtr; + char* c_dataPtr; + }; + + scrDataBlock* owner; + xtList* nextLevel; + + void* list; + scrDataBlock* prev; + scrDataBlock* next; + + void saveInfo(XStream& fh); + void saveData(XStream& fh); + void loadInfo(XStream& fh); + void loadData(XStream& fh); + + void loadInfo(XBuffer& fh); + void loadData(XBuffer& fh); + + void initName(char* p); + void allocList(void){ nextLevel = new xtList; } + + void alloc(int tp,int sz); + void allocData(void); + void freeData(void); + + void add(scrDataBlock* p); + void dump(XStream& fh,int idx,int mode = 0); + void get_keys(void); + + scrDataBlock* find(int id){ if(nextLevel) return nextLevel -> search(id); return NULL; } + + scrDataBlock(int tp); + scrDataBlock(void); + ~scrDataBlock(void); +}; + +void scrSetVerbose(int v = 1); + +void scrSetInputDir(char* p); +void scrSetOutputDir(char* p); +void scrSetOutputFile(char* p); + +scrDataBlock* loadScript(const std::filesystem::path &path); +scrDataBlock* loadScript(XStream& fh); +scrDataBlock* parseScript(char* fname,char *set_name); +void saveScript(char* fname,scrDataBlock* p); +void dumpScript(char* fname,scrDataBlock* p); +void dumpScriptKeywords(char* fname,scrDataBlock* p); + +#endif /* __ACI_PARSER_H__ */ diff --git a/MechoSoma/ThirdParty/iniparser/CMakeLists.txt b/MechoSoma/ThirdParty/iniparser/CMakeLists.txt new file mode 100644 index 00000000..6b9ed135 --- /dev/null +++ b/MechoSoma/ThirdParty/iniparser/CMakeLists.txt @@ -0,0 +1,8 @@ +project(iniparser C) + +add_library(iniparser + src/dictionary.c + src/iniparser.c +) + +target_include_directories(iniparser PUBLIC include) diff --git a/MechoSoma/ThirdParty/iniparser/include/dictionary.h b/MechoSoma/ThirdParty/iniparser/include/dictionary.h new file mode 100644 index 00000000..f0fd5402 --- /dev/null +++ b/MechoSoma/ThirdParty/iniparser/include/dictionary.h @@ -0,0 +1,173 @@ + +/*-------------------------------------------------------------------------*/ +/** + @file dictionary.h + @author N. Devillard + @brief Implements a dictionary for string variables. + + This module implements a simple dictionary object, i.e. a list + of string/string associations. This object is useful to store e.g. + informations retrieved from a configuration file (ini files). +*/ +/*--------------------------------------------------------------------------*/ + +#ifndef _DICTIONARY_H_ +#define _DICTIONARY_H_ + +/*--------------------------------------------------------------------------- + Includes + ---------------------------------------------------------------------------*/ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*--------------------------------------------------------------------------- + New types + ---------------------------------------------------------------------------*/ + + +/*-------------------------------------------------------------------------*/ +/** + @brief Dictionary object + + This object contains a list of string/string associations. Each + association is identified by a unique string key. Looking up values + in the dictionary is speeded up by the use of a (hopefully collision-free) + hash function. + */ +/*-------------------------------------------------------------------------*/ +typedef struct _dictionary_ { + int n ; /** Number of entries in dictionary */ + ssize_t size ; /** Storage size */ + char ** val ; /** List of string values */ + char ** key ; /** List of string keys */ + unsigned * hash ; /** List of hash values for keys */ +} dictionary ; + + +/*--------------------------------------------------------------------------- + Function prototypes + ---------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------*/ +/** + @brief Compute the hash key for a string. + @param key Character string to use for key. + @return 1 unsigned int on at least 32 bits. + + This hash function has been taken from an Article in Dr Dobbs Journal. + This is normally a collision-free function, distributing keys evenly. + The key is stored anyway in the struct so that collision can be avoided + by comparing the key itself in last resort. + */ +/*--------------------------------------------------------------------------*/ +unsigned dictionary_hash(const char * key); + +/*-------------------------------------------------------------------------*/ +/** + @brief Create a new dictionary object. + @param size Optional initial size of the dictionary. + @return 1 newly allocated dictionary object. + + This function allocates a new dictionary object of given size and returns + it. If you do not know in advance (roughly) the number of entries in the + dictionary, give size=0. + */ +/*--------------------------------------------------------------------------*/ +dictionary * dictionary_new(size_t size); + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete a dictionary object + @param d dictionary object to deallocate. + @return void + + Deallocate a dictionary object and all memory associated to it. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_del(dictionary * vd); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get a value from a dictionary. + @param d dictionary object to search. + @param key Key to look for in the dictionary. + @param def Default value to return if key not found. + @return 1 pointer to internally allocated character string. + + This function locates a key in a dictionary and returns a pointer to its + value, or the passed 'def' pointer if no such key can be found in + dictionary. The returned character pointer points to data internal to the + dictionary object, you should not try to free it or modify it. + */ +/*--------------------------------------------------------------------------*/ +const char * dictionary_get(const dictionary * d, const char * key, const char * def); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Set a value in a dictionary. + @param d dictionary object to modify. + @param key Key to modify or add. + @param val Value to add. + @return int 0 if Ok, anything else otherwise + + If the given key is found in the dictionary, the associated value is + replaced by the provided one. If the key cannot be found in the + dictionary, it is added to it. + + It is Ok to provide a NULL value for val, but NULL values for the dictionary + or the key are considered as errors: the function will return immediately + in such a case. + + Notice that if you dictionary_set a variable to NULL, a call to + dictionary_get will return a NULL value: the variable will be found, and + its value (NULL) is returned. In other words, setting the variable + content to NULL is equivalent to deleting the variable from the + dictionary. It is not possible (in this implementation) to have a key in + the dictionary without value. + + This function returns non-zero in case of failure. + */ +/*--------------------------------------------------------------------------*/ +int dictionary_set(dictionary * vd, const char * key, const char * val); + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete a key in a dictionary + @param d dictionary object to modify. + @param key Key to remove. + @return void + + This function deletes a key in a dictionary. Nothing is done if the + key cannot be found. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_unset(dictionary * d, const char * key); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Dump a dictionary to an opened file pointer. + @param d Dictionary to dump + @param f Opened file pointer. + @return void + + Dumps a dictionary onto an opened file pointer. Key pairs are printed out + as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as + output file pointers. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_dump(const dictionary * d, FILE * out); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/MechoSoma/ThirdParty/iniparser/include/iniparser.h b/MechoSoma/ThirdParty/iniparser/include/iniparser.h new file mode 100644 index 00000000..37ff7b71 --- /dev/null +++ b/MechoSoma/ThirdParty/iniparser/include/iniparser.h @@ -0,0 +1,358 @@ + +/*-------------------------------------------------------------------------*/ +/** + @file iniparser.h + @author N. Devillard + @brief Parser for ini files. +*/ +/*--------------------------------------------------------------------------*/ + +#ifndef _INIPARSER_H_ +#define _INIPARSER_H_ + +/*--------------------------------------------------------------------------- + Includes + ---------------------------------------------------------------------------*/ + +#include +#include +#include + +/* + * The following #include is necessary on many Unixes but not Linux. + * It is not needed for Windows platforms. + * Uncomment it if needed. + */ +/* #include */ + +#include "dictionary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*-------------------------------------------------------------------------*/ +/** + @brief Configure a function to receive the error messages. + @param errback Function to call. + + By default, the error will be printed on stderr. If a null pointer is passed + as errback the error callback will be switched back to default. + */ +/*--------------------------------------------------------------------------*/ + +void iniparser_set_error_callback(int (*errback)(const char *, ...)); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get number of sections in a dictionary + @param d Dictionary to examine + @return int Number of sections found in dictionary + + This function returns the number of sections found in a dictionary. + The test to recognize sections is done on the string stored in the + dictionary: a section name is given as "section" whereas a key is + stored as "section:key", thus the test looks for entries that do not + contain a colon. + + This clearly fails in the case a section name contains a colon, but + this should simply be avoided. + + This function returns -1 in case of error. + */ +/*--------------------------------------------------------------------------*/ + +int iniparser_getnsec(const dictionary * d); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Get name for section n in a dictionary. + @param d Dictionary to examine + @param n Section number (from 0 to nsec-1). + @return Pointer to char string + + This function locates the n-th section in a dictionary and returns + its name as a pointer to a string statically allocated inside the + dictionary. Do not free or modify the returned string! + + This function returns NULL in case of error. + */ +/*--------------------------------------------------------------------------*/ + +const char * iniparser_getsecname(const dictionary * d, int n); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Save a dictionary to a loadable ini file + @param d Dictionary to dump + @param f Opened file pointer to dump to + @return void + + This function dumps a given dictionary into a loadable ini file. + It is Ok to specify @c stderr or @c stdout as output files. + */ +/*--------------------------------------------------------------------------*/ + +void iniparser_dump_ini(const dictionary * d, FILE * f); + +/*-------------------------------------------------------------------------*/ +/** + @brief Save a dictionary section to a loadable ini file + @param d Dictionary to dump + @param s Section name of dictionary to dump + @param f Opened file pointer to dump to + @return void + + This function dumps a given section of a given dictionary into a loadable ini + file. It is Ok to specify @c stderr or @c stdout as output files. + */ +/*--------------------------------------------------------------------------*/ + +void iniparser_dumpsection_ini(const dictionary * d, const char * s, FILE * f); + +/*-------------------------------------------------------------------------*/ +/** + @brief Dump a dictionary to an opened file pointer. + @param d Dictionary to dump. + @param f Opened file pointer to dump to. + @return void + + This function prints out the contents of a dictionary, one element by + line, onto the provided file pointer. It is OK to specify @c stderr + or @c stdout as output files. This function is meant for debugging + purposes mostly. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_dump(const dictionary * d, FILE * f); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the number of keys in a section of a dictionary. + @param d Dictionary to examine + @param s Section name of dictionary to examine + @return Number of keys in section + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getsecnkeys(const dictionary * d, const char * s); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the number of keys in a section of a dictionary. + @param d Dictionary to examine + @param s Section name of dictionary to examine + @param keys Already allocated array to store the keys in + @return The pointer passed as `keys` argument or NULL in case of error + + This function queries a dictionary and finds all keys in a given section. + The keys argument should be an array of pointers which size has been + determined by calling `iniparser_getsecnkeys` function prior to this one. + + Each pointer in the returned char pointer-to-pointer is pointing to + a string allocated in the dictionary; do not free or modify them. + */ +/*--------------------------------------------------------------------------*/ +const char ** iniparser_getseckeys(const dictionary * d, const char * s, const char ** keys); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key + @param d Dictionary to search + @param key Key string to look for + @param def Default value to return if key not found. + @return pointer to statically allocated character string + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the pointer passed as 'def' is returned. + The returned char pointer is pointing to a string allocated in + the dictionary, do not free or modify it. + */ +/*--------------------------------------------------------------------------*/ +const char * iniparser_getstring(const dictionary * d, const char * key, const char * def); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to an int + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + Supported values for integers include the usual C notation + so decimal, octal (starting with 0) and hexadecimal (starting with 0x) + are supported. Examples: + + - "42" -> 42 + - "042" -> 34 (octal -> decimal) + - "0x42" -> 66 (hexa -> decimal) + + Warning: the conversion may overflow in various ways. Conversion is + totally outsourced to strtol(), see the associated man page for overflow + handling. + + Credits: Thanks to A. Becker for suggesting strtol() + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getint(const dictionary * d, const char * key, int notfound); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to an long int + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + Supported values for integers include the usual C notation + so decimal, octal (starting with 0) and hexadecimal (starting with 0x) + are supported. Examples: + + - "42" -> 42 + - "042" -> 34 (octal -> decimal) + - "0x42" -> 66 (hexa -> decimal) + + Warning: the conversion may overflow in various ways. Conversion is + totally outsourced to strtol(), see the associated man page for overflow + handling. + */ +/*--------------------------------------------------------------------------*/ +long int iniparser_getlongint(const dictionary * d, const char * key, long int notfound); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a double + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return double + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + */ +/*--------------------------------------------------------------------------*/ +double iniparser_getdouble(const dictionary * d, const char * key, double notfound); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a boolean + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + A true boolean is found if one of the following is matched: + + - A string starting with 'y' + - A string starting with 'Y' + - A string starting with 't' + - A string starting with 'T' + - A string starting with '1' + + A false boolean is found if one of the following is matched: + + - A string starting with 'n' + - A string starting with 'N' + - A string starting with 'f' + - A string starting with 'F' + - A string starting with '0' + + The notfound value returned if no boolean is identified, does not + necessarily have to be 0 or 1. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getboolean(const dictionary * d, const char * key, int notfound); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Set an entry in a dictionary. + @param ini Dictionary to modify. + @param entry Entry to modify (entry name) + @param val New value to associate to the entry. + @return int 0 if Ok, -1 otherwise. + + If the given entry can be found in the dictionary, it is modified to + contain the provided value. If it cannot be found, the entry is created. + It is Ok to set val to NULL. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_set(dictionary * ini, const char * entry, const char * val); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete an entry in a dictionary + @param ini Dictionary to modify + @param entry Entry to delete (entry name) + @return void + + If the given entry can be found, it is deleted from the dictionary. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_unset(dictionary * ini, const char * entry); + +/*-------------------------------------------------------------------------*/ +/** + @brief Finds out if a given entry exists in a dictionary + @param ini Dictionary to search + @param entry Name of the entry to look for + @return integer 1 if entry exists, 0 otherwise + + Finds out if a given entry exists in the dictionary. Since sections + are stored as keys with NULL associated values, this is the only way + of querying for the presence of sections in a dictionary. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_find_entry(const dictionary * ini, const char * entry) ; + +/*-------------------------------------------------------------------------*/ +/** + @brief Parse an ini file and return an allocated dictionary object + @param ininame Name of the ini file to read. + @return Pointer to newly allocated dictionary + + This is the parser for ini files. This function is called, providing + the name of the file to be read. It returns a dictionary object that + should not be accessed directly, but through accessor functions + instead. + + The returned dictionary must be freed using iniparser_freedict(). + */ +/*--------------------------------------------------------------------------*/ +dictionary * iniparser_load(const char * ininame); + +/*-------------------------------------------------------------------------*/ +/** + @brief Free all memory associated to an ini dictionary + @param d Dictionary to free + @return void + + Free all memory associated to an ini dictionary. + It is mandatory to call this function before the dictionary object + gets out of the current context. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_freedict(dictionary * d); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/MechoSoma/ThirdParty/iniparser/src/dictionary.c b/MechoSoma/ThirdParty/iniparser/src/dictionary.c new file mode 100644 index 00000000..aa3d232e --- /dev/null +++ b/MechoSoma/ThirdParty/iniparser/src/dictionary.c @@ -0,0 +1,380 @@ +/*-------------------------------------------------------------------------*/ +/** + @file dictionary.c + @author N. Devillard + @brief Implements a dictionary for string variables. + + This module implements a simple dictionary object, i.e. a list + of string/string associations. This object is useful to store e.g. + informations retrieved from a configuration file (ini files). +*/ +/*--------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------- + Includes + ---------------------------------------------------------------------------*/ +#include "dictionary.h" + +#include +#include +#include +#include + +/** Maximum value size for integers and doubles. */ +#define MAXVALSZ 1024 + +/** Minimal allocated number of entries in a dictionary */ +#define DICTMINSZ 128 + +/** Invalid key token */ +#define DICT_INVALID_KEY ((char*)-1) + +/*--------------------------------------------------------------------------- + Private functions + ---------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------*/ +/** + @brief Duplicate a string + @param s String to duplicate + @return Pointer to a newly allocated string, to be freed with free() + + This is a replacement for strdup(). This implementation is provided + for systems that do not have it. + */ +/*--------------------------------------------------------------------------*/ +static char * xstrdup(const char * s) +{ + char * t ; + size_t len ; + if (!s) + return NULL ; + + len = strlen(s) + 1 ; + t = (char*) malloc(len) ; + if (t) { + memcpy(t, s, len) ; + } + return t ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Double the size of the dictionary + @param d Dictionary to grow + @return This function returns non-zero in case of failure + */ +/*--------------------------------------------------------------------------*/ +static int dictionary_grow(dictionary * d) +{ + char ** new_val ; + char ** new_key ; + unsigned * new_hash ; + + new_val = (char**) calloc(d->size * 2, sizeof *d->val); + new_key = (char**) calloc(d->size * 2, sizeof *d->key); + new_hash = (unsigned*) calloc(d->size * 2, sizeof *d->hash); + if (!new_val || !new_key || !new_hash) { + /* An allocation failed, leave the dictionary unchanged */ + if (new_val) + free(new_val); + if (new_key) + free(new_key); + if (new_hash) + free(new_hash); + return -1 ; + } + /* Initialize the newly allocated space */ + memcpy(new_val, d->val, d->size * sizeof(char *)); + memcpy(new_key, d->key, d->size * sizeof(char *)); + memcpy(new_hash, d->hash, d->size * sizeof(unsigned)); + /* Delete previous data */ + free(d->val); + free(d->key); + free(d->hash); + /* Actually update the dictionary */ + d->size *= 2 ; + d->val = new_val; + d->key = new_key; + d->hash = new_hash; + return 0 ; +} + +/*--------------------------------------------------------------------------- + Function codes + ---------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------------*/ +/** + @brief Compute the hash key for a string. + @param key Character string to use for key. + @return 1 unsigned int on at least 32 bits. + + This hash function has been taken from an Article in Dr Dobbs Journal. + This is normally a collision-free function, distributing keys evenly. + The key is stored anyway in the struct so that collision can be avoided + by comparing the key itself in last resort. + */ +/*--------------------------------------------------------------------------*/ +unsigned dictionary_hash(const char * key) +{ + size_t len ; + unsigned hash ; + size_t i ; + + if (!key) + return 0 ; + + len = strlen(key); + for (hash=0, i=0 ; i>6) ; + } + hash += (hash <<3); + hash ^= (hash >>11); + hash += (hash <<15); + return hash ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Create a new dictionary object. + @param size Optional initial size of the dictionary. + @return 1 newly allocated dictionary object. + + This function allocates a new dictionary object of given size and returns + it. If you do not know in advance (roughly) the number of entries in the + dictionary, give size=0. + */ +/*-------------------------------------------------------------------------*/ +dictionary * dictionary_new(size_t size) +{ + dictionary * d ; + + /* If no size was specified, allocate space for DICTMINSZ */ + if (sizesize = size ; + d->val = (char**) calloc(size, sizeof *d->val); + d->key = (char**) calloc(size, sizeof *d->key); + d->hash = (unsigned*) calloc(size, sizeof *d->hash); + } + return d ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete a dictionary object + @param d dictionary object to deallocate. + @return void + + Deallocate a dictionary object and all memory associated to it. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_del(dictionary * d) +{ + ssize_t i ; + + if (d==NULL) return ; + for (i=0 ; isize ; i++) { + if (d->key[i]!=NULL) + free(d->key[i]); + if (d->val[i]!=NULL) + free(d->val[i]); + } + free(d->val); + free(d->key); + free(d->hash); + free(d); + return ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get a value from a dictionary. + @param d dictionary object to search. + @param key Key to look for in the dictionary. + @param def Default value to return if key not found. + @return 1 pointer to internally allocated character string. + + This function locates a key in a dictionary and returns a pointer to its + value, or the passed 'def' pointer if no such key can be found in + dictionary. The returned character pointer points to data internal to the + dictionary object, you should not try to free it or modify it. + */ +/*--------------------------------------------------------------------------*/ +const char * dictionary_get(const dictionary * d, const char * key, const char * def) +{ + unsigned hash ; + ssize_t i ; + + hash = dictionary_hash(key); + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + /* Compare hash */ + if (hash==d->hash[i]) { + /* Compare string, to avoid hash collisions */ + if (!strcmp(key, d->key[i])) { + return d->val[i] ; + } + } + } + return def ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Set a value in a dictionary. + @param d dictionary object to modify. + @param key Key to modify or add. + @param val Value to add. + @return int 0 if Ok, anything else otherwise + + If the given key is found in the dictionary, the associated value is + replaced by the provided one. If the key cannot be found in the + dictionary, it is added to it. + + It is Ok to provide a NULL value for val, but NULL values for the dictionary + or the key are considered as errors: the function will return immediately + in such a case. + + Notice that if you dictionary_set a variable to NULL, a call to + dictionary_get will return a NULL value: the variable will be found, and + its value (NULL) is returned. In other words, setting the variable + content to NULL is equivalent to deleting the variable from the + dictionary. It is not possible (in this implementation) to have a key in + the dictionary without value. + + This function returns non-zero in case of failure. + */ +/*--------------------------------------------------------------------------*/ +int dictionary_set(dictionary * d, const char * key, const char * val) +{ + ssize_t i ; + unsigned hash ; + + if (d==NULL || key==NULL) return -1 ; + + /* Compute hash for this key */ + hash = dictionary_hash(key) ; + /* Find if value is already in dictionary */ + if (d->n>0) { + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + if (hash==d->hash[i]) { /* Same hash value */ + if (!strcmp(key, d->key[i])) { /* Same key */ + /* Found a value: modify and return */ + if (d->val[i]!=NULL) + free(d->val[i]); + d->val[i] = (val ? xstrdup(val) : NULL); + /* Value has been modified: return */ + return 0 ; + } + } + } + } + /* Add a new value */ + /* See if dictionary needs to grow */ + if (d->n==d->size) { + /* Reached maximum size: reallocate dictionary */ + if (dictionary_grow(d) != 0) + return -1; + } + + /* Insert key in the first empty slot. Start at d->n and wrap at + d->size. Because d->n < d->size this will necessarily + terminate. */ + for (i=d->n ; d->key[i] ; ) { + if(++i == d->size) i = 0; + } + /* Copy key */ + d->key[i] = xstrdup(key); + d->val[i] = (val ? xstrdup(val) : NULL) ; + d->hash[i] = hash; + d->n ++ ; + return 0 ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete a key in a dictionary + @param d dictionary object to modify. + @param key Key to remove. + @return void + + This function deletes a key in a dictionary. Nothing is done if the + key cannot be found. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_unset(dictionary * d, const char * key) +{ + unsigned hash ; + ssize_t i ; + + if (key == NULL || d == NULL) { + return; + } + + hash = dictionary_hash(key); + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + /* Compare hash */ + if (hash==d->hash[i]) { + /* Compare string, to avoid hash collisions */ + if (!strcmp(key, d->key[i])) { + /* Found key */ + break ; + } + } + } + if (i>=d->size) + /* Key not found */ + return ; + + free(d->key[i]); + d->key[i] = NULL ; + if (d->val[i]!=NULL) { + free(d->val[i]); + d->val[i] = NULL ; + } + d->hash[i] = 0 ; + d->n -- ; + return ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Dump a dictionary to an opened file pointer. + @param d Dictionary to dump + @param f Opened file pointer. + @return void + + Dumps a dictionary onto an opened file pointer. Key pairs are printed out + as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as + output file pointers. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_dump(const dictionary * d, FILE * out) +{ + ssize_t i ; + + if (d==NULL || out==NULL) return ; + if (d->n<1) { + fprintf(out, "empty dictionary\n"); + return ; + } + for (i=0 ; isize ; i++) { + if (d->key[i]) { + fprintf(out, "%20s\t[%s]\n", + d->key[i], + d->val[i] ? d->val[i] : "UNDEF"); + } + } + return ; +} diff --git a/MechoSoma/ThirdParty/iniparser/src/iniparser.c b/MechoSoma/ThirdParty/iniparser/src/iniparser.c new file mode 100644 index 00000000..f1d16589 --- /dev/null +++ b/MechoSoma/ThirdParty/iniparser/src/iniparser.c @@ -0,0 +1,836 @@ + +/*-------------------------------------------------------------------------*/ +/** + @file iniparser.c + @author N. Devillard + @brief Parser for ini files. +*/ +/*--------------------------------------------------------------------------*/ +/*---------------------------- Includes ------------------------------------*/ +#include +#include +#include "iniparser.h" + +/*---------------------------- Defines -------------------------------------*/ +#define ASCIILINESZ (1024) +#define INI_INVALID_KEY ((char*)-1) + +/*--------------------------------------------------------------------------- + Private to this module + ---------------------------------------------------------------------------*/ +/** + * This enum stores the status for each parsed line (internal use only). + */ +typedef enum _line_status_ { + LINE_UNPROCESSED, + LINE_ERROR, + LINE_EMPTY, + LINE_COMMENT, + LINE_SECTION, + LINE_VALUE +} line_status ; + +/*-------------------------------------------------------------------------*/ +/** + @brief Convert a string to lowercase. + @param in String to convert. + @param out Output buffer. + @param len Size of the out buffer. + @return ptr to the out buffer or NULL if an error occured. + + This function convert a string into lowercase. + At most len - 1 elements of the input string will be converted. + */ +/*--------------------------------------------------------------------------*/ +static const char * strlwc(const char * in, char *out, unsigned len) +{ + unsigned i ; + + if (in==NULL || out == NULL || len==0) return NULL ; + i=0 ; + while (in[i] != '\0' && i < len-1) { + out[i] = (char)tolower((int)in[i]); + i++ ; + } + out[i] = '\0'; + return out ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Duplicate a string + @param s String to duplicate + @return Pointer to a newly allocated string, to be freed with free() + + This is a replacement for strdup(). This implementation is provided + for systems that do not have it. + */ +/*--------------------------------------------------------------------------*/ +static char * xstrdup(const char * s) +{ + char * t ; + size_t len ; + if (!s) + return NULL ; + + len = strlen(s) + 1 ; + t = (char*) malloc(len) ; + if (t) { + memcpy(t, s, len) ; + } + return t ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Remove blanks at the beginning and the end of a string. + @param str String to parse and alter. + @return unsigned New size of the string. + */ +/*--------------------------------------------------------------------------*/ +static unsigned strstrip(char * s) +{ + char *last = NULL ; + char *dest = s; + + if (s==NULL) return 0; + + last = s + strlen(s); + while (isspace((int)*s) && *s) s++; + while (last > s) { + if (!isspace((int)*(last-1))) + break ; + last -- ; + } + *last = (char)0; + + memmove(dest,s,last - s + 1); + return last - s; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Default error callback for iniparser: wraps `fprintf(stderr, ...)`. + */ +/*--------------------------------------------------------------------------*/ +static int default_error_callback(const char *format, ...) +{ + int ret; + va_list argptr; + va_start(argptr, format); + ret = vfprintf(stderr, format, argptr); + va_end(argptr); + return ret; +} + +static int (*iniparser_error_callback)(const char*, ...) = default_error_callback; + +/*-------------------------------------------------------------------------*/ +/** + @brief Configure a function to receive the error messages. + @param errback Function to call. + + By default, the error will be printed on stderr. If a null pointer is passed + as errback the error callback will be switched back to default. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_set_error_callback(int (*errback)(const char *, ...)) +{ + if (errback) { + iniparser_error_callback = errback; + } else { + iniparser_error_callback = default_error_callback; + } +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get number of sections in a dictionary + @param d Dictionary to examine + @return int Number of sections found in dictionary + + This function returns the number of sections found in a dictionary. + The test to recognize sections is done on the string stored in the + dictionary: a section name is given as "section" whereas a key is + stored as "section:key", thus the test looks for entries that do not + contain a colon. + + This clearly fails in the case a section name contains a colon, but + this should simply be avoided. + + This function returns -1 in case of error. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getnsec(const dictionary * d) +{ + int i ; + int nsec ; + + if (d==NULL) return -1 ; + nsec=0 ; + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + if (strchr(d->key[i], ':')==NULL) { + nsec ++ ; + } + } + return nsec ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get name for section n in a dictionary. + @param d Dictionary to examine + @param n Section number (from 0 to nsec-1). + @return Pointer to char string + + This function locates the n-th section in a dictionary and returns + its name as a pointer to a string statically allocated inside the + dictionary. Do not free or modify the returned string! + + This function returns NULL in case of error. + */ +/*--------------------------------------------------------------------------*/ +const char * iniparser_getsecname(const dictionary * d, int n) +{ + int i ; + int foundsec ; + + if (d==NULL || n<0) return NULL ; + foundsec=0 ; + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + if (strchr(d->key[i], ':')==NULL) { + foundsec++ ; + if (foundsec>n) + break ; + } + } + if (foundsec<=n) { + return NULL ; + } + return d->key[i] ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Dump a dictionary to an opened file pointer. + @param d Dictionary to dump. + @param f Opened file pointer to dump to. + @return void + + This function prints out the contents of a dictionary, one element by + line, onto the provided file pointer. It is OK to specify @c stderr + or @c stdout as output files. This function is meant for debugging + purposes mostly. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_dump(const dictionary * d, FILE * f) +{ + int i ; + + if (d==NULL || f==NULL) return ; + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + if (d->val[i]!=NULL) { + fprintf(f, "[%s]=[%s]\n", d->key[i], d->val[i]); + } else { + fprintf(f, "[%s]=UNDEF\n", d->key[i]); + } + } + return ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Save a dictionary to a loadable ini file + @param d Dictionary to dump + @param f Opened file pointer to dump to + @return void + + This function dumps a given dictionary into a loadable ini file. + It is Ok to specify @c stderr or @c stdout as output files. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_dump_ini(const dictionary * d, FILE * f) +{ + int i ; + int nsec ; + const char * secname ; + + if (d==NULL || f==NULL) return ; + + nsec = iniparser_getnsec(d); + if (nsec<1) { + /* No section in file: dump all keys as they are */ + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + fprintf(f, "%s = %s\n", d->key[i], d->val[i]); + } + return ; + } + for (i=0 ; isize ; j++) { + if (d->key[j]==NULL) + continue ; + if (!strncmp(d->key[j], keym, seclen+1)) { + fprintf(f, + "%-30s = %s\n", + d->key[j]+seclen+1, + d->val[j] ? d->val[j] : ""); + } + } + fprintf(f, "\n"); + return ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the number of keys in a section of a dictionary. + @param d Dictionary to examine + @param s Section name of dictionary to examine + @return Number of keys in section + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getsecnkeys(const dictionary * d, const char * s) +{ + int seclen, nkeys ; + char keym[ASCIILINESZ+1]; + int j ; + + nkeys = 0; + + if (d==NULL) return nkeys; + if (! iniparser_find_entry(d, s)) return nkeys; + + seclen = (int)strlen(s); + strlwc(s, keym, sizeof(keym)); + keym[seclen] = ':'; + + for (j=0 ; jsize ; j++) { + if (d->key[j]==NULL) + continue ; + if (!strncmp(d->key[j], keym, seclen+1)) + nkeys++; + } + + return nkeys; + +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the number of keys in a section of a dictionary. + @param d Dictionary to examine + @param s Section name of dictionary to examine + @param keys Already allocated array to store the keys in + @return The pointer passed as `keys` argument or NULL in case of error + + This function queries a dictionary and finds all keys in a given section. + The keys argument should be an array of pointers which size has been + determined by calling `iniparser_getsecnkeys` function prior to this one. + + Each pointer in the returned char pointer-to-pointer is pointing to + a string allocated in the dictionary; do not free or modify them. + */ +/*--------------------------------------------------------------------------*/ +const char ** iniparser_getseckeys(const dictionary * d, const char * s, const char ** keys) +{ + int i, j, seclen ; + char keym[ASCIILINESZ+1]; + + if (d==NULL || keys==NULL) return NULL; + if (! iniparser_find_entry(d, s)) return NULL; + + seclen = (int)strlen(s); + strlwc(s, keym, sizeof(keym)); + keym[seclen] = ':'; + + i = 0; + + for (j=0 ; jsize ; j++) { + if (d->key[j]==NULL) + continue ; + if (!strncmp(d->key[j], keym, seclen+1)) { + keys[i] = d->key[j]; + i++; + } + } + + return keys; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key + @param d Dictionary to search + @param key Key string to look for + @param def Default value to return if key not found. + @return pointer to statically allocated character string + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the pointer passed as 'def' is returned. + The returned char pointer is pointing to a string allocated in + the dictionary, do not free or modify it. + */ +/*--------------------------------------------------------------------------*/ +const char * iniparser_getstring(const dictionary * d, const char * key, const char * def) +{ + const char * lc_key ; + const char * sval ; + char tmp_str[ASCIILINESZ+1]; + + if (d==NULL || key==NULL) + return def ; + + lc_key = strlwc(key, tmp_str, sizeof(tmp_str)); + sval = dictionary_get(d, lc_key, def); + return sval ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to an long int + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return long integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + Supported values for integers include the usual C notation + so decimal, octal (starting with 0) and hexadecimal (starting with 0x) + are supported. Examples: + + "42" -> 42 + "042" -> 34 (octal -> decimal) + "0x42" -> 66 (hexa -> decimal) + + Warning: the conversion may overflow in various ways. Conversion is + totally outsourced to strtol(), see the associated man page for overflow + handling. + + Credits: Thanks to A. Becker for suggesting strtol() + */ +/*--------------------------------------------------------------------------*/ +long int iniparser_getlongint(const dictionary * d, const char * key, long int notfound) +{ + const char * str ; + + str = iniparser_getstring(d, key, INI_INVALID_KEY); + if (str==INI_INVALID_KEY) return notfound ; + return strtol(str, NULL, 0); +} + + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to an int + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + Supported values for integers include the usual C notation + so decimal, octal (starting with 0) and hexadecimal (starting with 0x) + are supported. Examples: + + "42" -> 42 + "042" -> 34 (octal -> decimal) + "0x42" -> 66 (hexa -> decimal) + + Warning: the conversion may overflow in various ways. Conversion is + totally outsourced to strtol(), see the associated man page for overflow + handling. + + Credits: Thanks to A. Becker for suggesting strtol() + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getint(const dictionary * d, const char * key, int notfound) +{ + return (int)iniparser_getlongint(d, key, notfound); +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a double + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return double + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + */ +/*--------------------------------------------------------------------------*/ +double iniparser_getdouble(const dictionary * d, const char * key, double notfound) +{ + const char * str ; + + str = iniparser_getstring(d, key, INI_INVALID_KEY); + if (str==INI_INVALID_KEY) return notfound ; + return atof(str); +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a boolean + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + A true boolean is found if one of the following is matched: + + - A string starting with 'y' + - A string starting with 'Y' + - A string starting with 't' + - A string starting with 'T' + - A string starting with '1' + + A false boolean is found if one of the following is matched: + + - A string starting with 'n' + - A string starting with 'N' + - A string starting with 'f' + - A string starting with 'F' + - A string starting with '0' + + The notfound value returned if no boolean is identified, does not + necessarily have to be 0 or 1. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getboolean(const dictionary * d, const char * key, int notfound) +{ + int ret ; + const char * c ; + + c = iniparser_getstring(d, key, INI_INVALID_KEY); + if (c==INI_INVALID_KEY) return notfound ; + if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') { + ret = 1 ; + } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') { + ret = 0 ; + } else { + ret = notfound ; + } + return ret; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Finds out if a given entry exists in a dictionary + @param ini Dictionary to search + @param entry Name of the entry to look for + @return integer 1 if entry exists, 0 otherwise + + Finds out if a given entry exists in the dictionary. Since sections + are stored as keys with NULL associated values, this is the only way + of querying for the presence of sections in a dictionary. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_find_entry(const dictionary * ini, const char * entry) +{ + int found=0 ; + if (iniparser_getstring(ini, entry, INI_INVALID_KEY)!=INI_INVALID_KEY) { + found = 1 ; + } + return found ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Set an entry in a dictionary. + @param ini Dictionary to modify. + @param entry Entry to modify (entry name) + @param val New value to associate to the entry. + @return int 0 if Ok, -1 otherwise. + + If the given entry can be found in the dictionary, it is modified to + contain the provided value. If it cannot be found, the entry is created. + It is Ok to set val to NULL. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_set(dictionary * ini, const char * entry, const char * val) +{ + char tmp_str[ASCIILINESZ+1]; + return dictionary_set(ini, strlwc(entry, tmp_str, sizeof(tmp_str)), val) ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete an entry in a dictionary + @param ini Dictionary to modify + @param entry Entry to delete (entry name) + @return void + + If the given entry can be found, it is deleted from the dictionary. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_unset(dictionary * ini, const char * entry) +{ + char tmp_str[ASCIILINESZ+1]; + dictionary_unset(ini, strlwc(entry, tmp_str, sizeof(tmp_str))); +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Load a single line from an INI file + @param input_line Input line, may be concatenated multi-line input + @param section Output space to store section + @param key Output space to store key + @param value Output space to store value + @return line_status value + */ +/*--------------------------------------------------------------------------*/ +static line_status iniparser_line( + const char * input_line, + char * section, + char * key, + char * value) +{ + line_status sta ; + char * line = NULL; + size_t len ; + + line = xstrdup(input_line); + len = strstrip(line); + + sta = LINE_UNPROCESSED ; + if (len<1) { + /* Empty line */ + sta = LINE_EMPTY ; + } else if (line[0]=='#' || line[0]==';') { + /* Comment line */ + sta = LINE_COMMENT ; + } else if (line[0]=='[' && line[len-1]==']') { + /* Section name */ + sscanf(line, "[%[^]]", section); + strstrip(section); + strlwc(section, section, len); + sta = LINE_SECTION ; + } else if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2 + || sscanf (line, "%[^=] = '%[^\']'", key, value) == 2) { + /* Usual key=value with quotes, with or without comments */ + strstrip(key); + strlwc(key, key, len); + /* Don't strip spaces from values surrounded with quotes */ + sta = LINE_VALUE ; + } else if (sscanf (line, "%[^=] = %[^;#]", key, value) == 2) { + /* Usual key=value without quotes, with or without comments */ + strstrip(key); + strlwc(key, key, len); + strstrip(value); + /* + * sscanf cannot handle '' or "" as empty values + * this is done here + */ + if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) { + value[0]=0 ; + } + sta = LINE_VALUE ; + } else if (sscanf(line, "%[^=] = %[;#]", key, value)==2 + || sscanf(line, "%[^=] %[=]", key, value) == 2) { + /* + * Special cases: + * key= + * key=; + * key=# + */ + strstrip(key); + strlwc(key, key, len); + value[0]=0 ; + sta = LINE_VALUE ; + } else { + /* Generate syntax error */ + sta = LINE_ERROR ; + } + + free(line); + return sta ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Parse an ini file and return an allocated dictionary object + @param ininame Name of the ini file to read. + @return Pointer to newly allocated dictionary + + This is the parser for ini files. This function is called, providing + the name of the file to be read. It returns a dictionary object that + should not be accessed directly, but through accessor functions + instead. + + The returned dictionary must be freed using iniparser_freedict(). + */ +/*--------------------------------------------------------------------------*/ +dictionary * iniparser_load(const char * ininame) +{ + FILE * in ; + + char line [ASCIILINESZ+1] ; + char section [ASCIILINESZ+1] ; + char key [ASCIILINESZ+1] ; + char tmp [(ASCIILINESZ * 2) + 2] ; + char val [ASCIILINESZ+1] ; + + int last=0 ; + int len ; + int lineno=0 ; + int errs=0; + int mem_err=0; + + dictionary * dict ; + + if ((in=fopen(ininame, "r"))==NULL) { + iniparser_error_callback("iniparser: cannot open %s\n", ininame); + return NULL ; + } + + dict = dictionary_new(0) ; + if (!dict) { + fclose(in); + return NULL ; + } + + memset(line, 0, ASCIILINESZ); + memset(section, 0, ASCIILINESZ); + memset(key, 0, ASCIILINESZ); + memset(val, 0, ASCIILINESZ); + last=0 ; + + while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) { + lineno++ ; + len = (int)strlen(line)-1; + if (len<=0) + continue; + /* Safety check against buffer overflows */ + if (line[len]!='\n' && !feof(in)) { + iniparser_error_callback( + "iniparser: input line too long in %s (%d)\n", + ininame, + lineno); + dictionary_del(dict); + fclose(in); + return NULL ; + } + /* Get rid of \n and spaces at end of line */ + while ((len>=0) && + ((line[len]=='\n') || (isspace(line[len])))) { + line[len]=0 ; + len-- ; + } + if (len < 0) { /* Line was entirely \n and/or spaces */ + len = 0; + } + /* Detect multi-line */ + if (line[len]=='\\') { + /* Multi-line value */ + last=len ; + continue ; + } else { + last=0 ; + } + switch (iniparser_line(line, section, key, val)) { + case LINE_EMPTY: + case LINE_COMMENT: + break ; + + case LINE_SECTION: + mem_err = dictionary_set(dict, section, NULL); + break ; + + case LINE_VALUE: + sprintf(tmp, "%s:%s", section, key); + mem_err = dictionary_set(dict, tmp, val); + break ; + + case LINE_ERROR: + iniparser_error_callback( + "iniparser: syntax error in %s (%d):\n-> %s\n", + ininame, + lineno, + line); + errs++ ; + break; + + default: + break ; + } + memset(line, 0, ASCIILINESZ); + last=0; + if (mem_err<0) { + iniparser_error_callback("iniparser: memory allocation failure\n"); + break ; + } + } + if (errs) { + dictionary_del(dict); + dict = NULL ; + } + fclose(in); + return dict ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Free all memory associated to an ini dictionary + @param d Dictionary to free + @return void + + Free all memory associated to an ini dictionary. + It is mandatory to call this function before the dictionary object + gets out of the current context. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_freedict(dictionary * d) +{ + dictionary_del(d); +} diff --git a/MechoSoma/VisGeneric/AnimChannelNode.cpp b/MechoSoma/VisGeneric/AnimChannelNode.cpp index 32f6639b..41693570 100644 --- a/MechoSoma/VisGeneric/AnimChannelNode.cpp +++ b/MechoSoma/VisGeneric/AnimChannelNode.cpp @@ -1,4 +1,4 @@ -#include "umath.h" +#include "UMATH.H" #include "BaseClass.h" #include "cString.h" #define VISASSERT assert @@ -7,7 +7,7 @@ #include "float.h" ////////////////////////////////////////////////////////////////////////////////////////// -// ðåàëèçàöèÿ cAnimChainNode +// ���������� cAnimChainNode ////////////////////////////////////////////////////////////////////////////////////////// void QuatSlerp(QuatF &from,QuatF &to,float t,QuatF &res) { @@ -59,7 +59,7 @@ void cAnimChainNode::GetMatrix(float phase,int &visible,MatXf &Matrix) { Identity(Matrix); float CurrentTime=phase*Time; - { // àíèìàöèÿ ïîçèöèè + { // �������� ������� sKey3f *a=0,*b=0; int i; for(i=0;iv+(b->v-a->v)*((CurrentTime-a->time)/(b->time-a->time)); } - { // àíèìàöèÿ âðàùåíèÿ + { // �������� �������� sKey4f *a=0,*b=0; int i; for(i=0;iv+(b->v-a->v)*((CurrentTime-a->time)/(b->time-a->time))); } - { // àíèìàöèÿ âèäèìîñòè + { // �������� ��������� sKeyVisible *a=0; for(int i=GetNumberVisible()-1;i>=0;i--) if(GetVisible(i).time<=CurrentTime) @@ -118,10 +118,12 @@ void cAnimChainNode::GetMatrix(float phase,int &visible,MatXf &Matrix) VISASSERT(a); visible=a->visible; } +#ifdef _WIN32 VISASSERT(_finite(Matrix.rot()(1,1))&&_finite(Matrix.trans().x)); +#endif } ////////////////////////////////////////////////////////////////////////////////////////// -// ðåàëèçàöèÿ cAnimChannelNode +// ���������� cAnimChannelNode ////////////////////////////////////////////////////////////////////////////////////////// cAnimChannelNode::cAnimChannelNode(int number) { diff --git a/MechoSoma/VisGeneric/Base.h b/MechoSoma/VisGeneric/Base.h index 62ca16f4..5fc2f262 100644 --- a/MechoSoma/VisGeneric/Base.h +++ b/MechoSoma/VisGeneric/Base.h @@ -2,7 +2,7 @@ #define __BASE_H__ // Òèïû îáúåêòîâ -#include "m3d_id.h" +#include "M3d_id.h" // Òèï îáúåêòà #define M3D_TYPE(type) ((unsigned)(type) & 0xffff) diff --git a/MechoSoma/VisGeneric/BaseClass.h b/MechoSoma/VisGeneric/BaseClass.h index 9ad8146c..d5442550 100644 --- a/MechoSoma/VisGeneric/BaseClass.h +++ b/MechoSoma/VisGeneric/BaseClass.h @@ -8,7 +8,7 @@ #define __BASE_LIST__ template class cBaseList -{ // äâóñâÿçàííûé ñïèñîê +{ // ������������ ������ // friend class cBase; public: cBase *Base; @@ -51,19 +51,20 @@ template class cBaseLibrary ~cBaseLibrary() { } inline cBaseList* Attach(cBase *Base) - { // ïðèñîåäèíèå îáúåêòà ê ñïèñêó + { // ����������� ������� � ������ if(BaseList==0) return BaseList=new cBaseList(Base); return BaseList->Attach(new cBaseList(Base)); } inline cBaseList* AttachEnd(cBase *Base) - { // ïðèñîåäèíèå îáúåêòà ê ñïèñêó + { // ����������� ������� � ������ if(BaseList==0) return BaseList=new cBaseList(Base); - for(cBaseList *start=BaseList; start->next; start=start->next); + cBaseList *start = nullptr; + for(start=BaseList; start->next; start=start->next); cBaseList *List=new cBaseList(Base); return List->Attach(start); } inline void Detach(cBase *Base) - { // îòñîåäèíåíèå îáúåêòà îò ñïèñêà + { // ������������ ������� �� ������ cBaseList *start=BaseList; for(start; start; start=start->next) if(start->Base==Base) break; @@ -79,7 +80,7 @@ template class cBaseLibrary if(List==BaseList) BaseList=BaseList->next; delete List; } - inline void Delete(cBase *Base) // óäàëåíèå îáúåêòà â ñïèñêå + inline void Delete(cBase *Base) // �������� ������� � ������ { Detach(Base); if(Base) delete Base; @@ -95,11 +96,17 @@ template class cBaseLibrary template class cBaseDispatcher : public cBaseLibrary { public: - unsigned int NumberID; // ID ïîñëåäíåãî îáúåêòà = NumberID + unsigned int NumberID; // ID ���������� ������� = NumberID cBaseDispatcher() { NumberID=0; } - ~cBaseDispatcher() { assert(BaseList==0); } - inline cBase* FindID(unsigned int ID) { for(cBaseList *start=BaseList; start; start=start->next) if(start->Base->ID==ID) return start->Base; return 0; } + ~cBaseDispatcher() { assert(this->BaseList==0); } + inline cBase* FindID(unsigned int ID) + { + cBaseList *start = nullptr; + for(start=this->BaseList; start; start=start->next); + if(start->Base->ID==ID) return start->Base; + return 0; + } }; #endif //__BASE_DISPATCHER__ @@ -115,12 +122,12 @@ template class cBaseStack cBaseStack() { BaseList=0; } ~cBaseStack() { assert(BaseList==0); } - inline cBaseList* Push(cBase *Base) // ïðèñîåäèíèå îáúåêòà ê ñïèñêó + inline cBaseList* Push(cBase *Base) // ����������� ������� � ������ { if(BaseList==0) return BaseList=new cBaseList(Base); return BaseList->Attach(new cBaseList(Base)); } - inline void Pop() // óäàëåíèå îáúåêòà â ñïèñêå + inline void Pop() // �������� ������� � ������ { cBaseList *tmp=BaseList; if(tmp) @@ -139,22 +146,23 @@ template class cBaseStack template class cBaseQueue { public: - cBaseList *BaseList; // ïåðâûé ýëåìåíò - NULL îáúåêò + cBaseList *BaseList; // ������ ������� - NULL ������ cBaseList *Window; cBaseQueue() { BaseList=0; First(); } ~cBaseQueue() { assert(BaseList==0); } - inline cBaseList* Attach(cBase *Base) // ïðèñîåäèíèå îáúåêòà ê ñïèñêó + inline cBaseList* Attach(cBase *Base) // ����������� ������� � ������ { if(BaseList==0) return BaseList=new cBaseList(Base); return BaseList->Attach(new cBaseList(Base)); } - inline void Delete(cBase *Base=0) // óäàëåíèå îáúåêòà â ñïèñêå + inline void Delete(cBase *Base=0) // �������� ������� � ������ { if(Base==0) { - for(cBaseList *start=BaseList; start->next; start=start->next) + cBaseList *start = nullptr; + for(start=BaseList; start->next; start=start->next) if(start==0) return; if(start==Window) Window=start->next; if(start->Base) delete start->Base; @@ -163,13 +171,14 @@ template class cBaseQueue Detach(Base); delete Base; } - inline void Detach(cBase *Base) // îòñîåäèíåíèå îáúåêòà îò ñïèñêà + inline void Detach(cBase *Base) // ������������ ������� �� ������ { - for(cBaseList *start=BaseList; start; start=start->next) + cBaseList *start = nullptr; + for(start=BaseList; start; start=start->next) if(start->Base==Base) break; if(start) { if(start==Window) Window=start->next; delete start; } } - inline cBase* First() { if(Window=BaseList) return Window->Base; return 0; } + inline cBase* First() { if((Window=BaseList)) return Window->Base; return 0; } inline cBase* Prev() { if((Window)&&(Window=Window->prev)) return Window->Base; return 0; } inline cBase* Next() { if((Window)&&(Window=Window->next)) return Window->Base; return 0; } }; @@ -341,24 +350,24 @@ template class cBaseArrayManager : public cBaseArrayPointer (MaxLength,AddSize) { } - ~cBaseArrayManager() { assert(length()==0); } + ~cBaseArrayManager() { assert(this->length()==0); } inline int Attach(cBase *base) { - for(int i=0;ilength();i++) + if(this->Base[i]==0) { - Base[i]=base; + this->Base[i]=base; return i; } cBaseArrayPointer::Attach(base); - return length()-1; + return this->length()-1; } inline void Detach(cBase *base) { - for(int i=0;ilength();i++) + if(this->Base[i]==base) { - Base[i]=0; + this->Base[i]=0; break; } } @@ -469,12 +478,12 @@ template class cBaseDynArrayPointer return 0; } inline void Attach(cBase *base) - { // äîáàâëÿåò óêàçàòåëü â êîíåö ñïèñêà + { // ��������� ��������� � ����� ������ Resize(length()+BASEDYNARRAY_DSIZE); Base[length()-1]=base; } inline void Detach(cBase *base) - { // èùåò óêàçàòåëü ýëåìåíò Base â ñïèñêå è óäàëÿåò åãî èç ñïèñêà + { // ���� ��������� ������� Base � ������ � ������� ��� �� ������ int number; for(number=0;number class cBaseDynArrayPointer Resize(length()-1); } inline void Delete(int number) - { // óäàëÿåò èç ñïèñêà ýëåìåíò ñ íîìåðîì number, è óäàëÿåò ñàì ýåëåìåíò ñ íîìåðîì + { // ������� �� ������ ������� � ������� number, � ������� ��� �������� � ������� if(Base[number]) { delete Base[number]; Base[number]=0; } memcpy(&Base[number],&Base[number+1],(length()-number-1)*sizeof(cBase*)); Resize(length()-1); diff --git a/MechoSoma/VisGeneric/BaseDefine.h b/MechoSoma/VisGeneric/BaseDefine.h index 97c429f5..9a7c12e0 100644 --- a/MechoSoma/VisGeneric/BaseDefine.h +++ b/MechoSoma/VisGeneric/BaseDefine.h @@ -2,7 +2,7 @@ #define __BASEDEFINE_H__ #include "assert.h" -#include "malloc.h" +#include "stdlib.h" #include "string.h" #include "BaseClass.h" @@ -16,7 +16,7 @@ namespace KDWIN using namespace KDWIN; */ -#include "_xtool.h" +#include "xtool.h" inline void ErrAbort(char *message) { diff --git a/MechoSoma/VisGeneric/BaseLight.h b/MechoSoma/VisGeneric/BaseLight.h index cc5d6189..7f07b4f1 100644 --- a/MechoSoma/VisGeneric/BaseLight.h +++ b/MechoSoma/VisGeneric/BaseLight.h @@ -8,7 +8,7 @@ class cBaseLight : public cBaseObject, public cBaseVolumeObject { public: - int id; // íîìåð èñòî÷íèêà ñâåòà + int id; // ����� ��������� ����� sColor4f Ambient; sColor4f Diffuse; sColor4f Illumination; @@ -26,4 +26,4 @@ class cOmniLight : public cBaseLight extern void BaseObject_OmniLight(Vect3f &pos,sColor4f &diffuse,sColor4f &illumination); -#endif __BASELIGHT_H__ \ No newline at end of file +#endif // __BASELIGHT_H__ \ No newline at end of file diff --git a/MechoSoma/VisGeneric/BaseObject.h b/MechoSoma/VisGeneric/BaseObject.h index 503a8c67..5cc107f4 100644 --- a/MechoSoma/VisGeneric/BaseObject.h +++ b/MechoSoma/VisGeneric/BaseObject.h @@ -2,8 +2,8 @@ #define __BASEOBJECT_H__ #include "BaseClass.h" -#include "material.h" -#include "object.h" +#include "Material.h" +#include "Object.h" #ifndef msqrt #define msqrt(a) sqrt(a) @@ -201,4 +201,4 @@ inline int cBaseVolumeObject::isVolume(const Vect3f &pos,float &f) return 0; } -#endif __BASEOBJECT_H__ \ No newline at end of file +#endif // __BASEOBJECT_H__ \ No newline at end of file diff --git a/MechoSoma/VisGeneric/BasePolyGrid.h b/MechoSoma/VisGeneric/BasePolyGrid.h index 7f5c6369..53874bdc 100644 --- a/MechoSoma/VisGeneric/BasePolyGrid.h +++ b/MechoSoma/VisGeneric/BasePolyGrid.h @@ -10,21 +10,45 @@ struct sBaseColor4c unsigned char r,g,b,a; inline void Set(int rc,int gc,int bc) { r=rc; g=gc; b=bc; } inline void Set(int rc,int gc,int bc,int ac) { r=rc; g=gc; b=bc; a=ac; } - inline sBaseColor4c operator + (sBaseColor4c &p) { sBaseColor4c tmp={r+p.r,g+p.g,b+p.b,a+p.a}; return tmp; } + inline sBaseColor4c operator + (sBaseColor4c &p) + { + sBaseColor4c tmp{ + static_cast(r+p.r), + static_cast(g+p.g), + static_cast(b+p.b), + static_cast(a+p.a) + }; + return tmp; + } inline sBaseColor4c& operator += (sBaseColor4c &p) { r+=p.r; g+=p.g; b+=p.b; a+=p.a; return *this; } }; struct sBasePoint3c { char x,y,z; inline void Set(int xw,int yw,int zw) { x=xw; y=yw; z=zw; } - inline sBasePoint3c operator + (sBasePoint3c &p) { sBasePoint3c tmp={x+p.x,y+p.y,z+p.z}; return tmp; } + inline sBasePoint3c operator + (sBasePoint3c &p) + { + sBasePoint3c tmp{ + static_cast(x+p.x), + static_cast(y+p.y), + static_cast(z+p.z) + }; + return tmp; + } inline sBasePoint3c& operator += (sBasePoint3c &p) { x+=p.x; y+=p.y; z+=p.z; return *this; } }; struct sBasePoint2c { char x,y; inline void Set(int xw,int yw) { x=xw; y=yw; } - inline sBasePoint2c operator + (sBasePoint2c &p) { sBasePoint2c tmp={x+p.x,y+p.y}; return tmp; } + inline sBasePoint2c operator + (sBasePoint2c &p) + { + sBasePoint2c tmp{ + static_cast(x+p.x), + static_cast(y+p.y) + }; + return tmp; + } inline sBasePoint2c& operator += (sBasePoint2c &p) { x+=p.x; y+=p.y; return *this; } }; // ñòðóêòóðû îïèñûâàþùèå âîçìóùåíèå @@ -124,4 +148,4 @@ class cBaseWaveProcess : public cBaseObject extern void* BaseObject_BaseWaveProcess_Create(float x,float y,float z,float TimeLife=1.f,float dPhase=0.3f); -#endif __BASEPOLYGRID_H__ \ No newline at end of file +#endif // __BASEPOLYGRID_H__ \ No newline at end of file diff --git a/MechoSoma/VisGeneric/BaseReflection.h b/MechoSoma/VisGeneric/BaseReflection.h index 2c68a63a..1e218fd3 100644 --- a/MechoSoma/VisGeneric/BaseReflection.h +++ b/MechoSoma/VisGeneric/BaseReflection.h @@ -25,4 +25,4 @@ class cSurfaceReflectionMultiMaterial : public cSurfaceReflection unsigned int kind=BASEOBJECT_KIND_DRAW_REFLECTION) : cSurfaceReflection(type,kind) { BaseDrawObject()->SetAttribute(BASEOBJECT_ATTRIBUTE_DRAW_CYCL|BASEOBJECT_ATTRIBUTE_DRAW_POLYGONCW|BASEOBJECT_ATTRIBUTE_DRAW_COLOR|BASEOBJECT_ATTRIBUTE_DRAW_XYZWARP|BASEOBJECT_ATTRIBUTE_DRAW_MULTIMATERIAL|BASEOBJECT_ATTRIBUTE_DRAW_WAVEWARP); xMaterial=yMaterial=WarpWavePlane=0; PeriodWave=0; dPeriodWave=0.5f; } }; -#endif __BASEREFLECTION_H__ \ No newline at end of file +#endif // __BASEREFLECTION_H__ \ No newline at end of file diff --git a/MechoSoma/VisGeneric/BaseTrail.h b/MechoSoma/VisGeneric/BaseTrail.h index 232946e6..0a5dddf8 100644 --- a/MechoSoma/VisGeneric/BaseTrail.h +++ b/MechoSoma/VisGeneric/BaseTrail.h @@ -10,16 +10,16 @@ class cTileMap; class cBaseTrail : public cBaseObject, public cBaseDrawObject { public: - Vect3f Point[4]; // 4-òî÷êè òåêñòóðû - Vect3f Pos; // ìåñòî ïîëîæåíèå öåíòðà - sColor4f Diffuse1; // îñâåùåííîñòü îáúåêòà â íà÷àëå - sColor4f Diffuse2; // îñâåùåííîñòü îáúåêòà â êîíöå + Vect3f Point[4]; // 4-����� �������� + Vect3f Pos; // ����� ��������� ������ + sColor4f Diffuse1; // ������������ ������� � ������ + sColor4f Diffuse2; // ������������ ������� � ����� MeasurementTimer Timer; float Duration; -// float CurrentTime; // òåêóùåå âðåìÿ, CurrentTime+StartTime==GlobalTime -// float StartTime; // âðåìÿ íà÷àëà æèçíè -// float FinishTime; // âðåìÿ æèçíè - float AnimTime; // âðåìÿ àíèìàöèè +// float CurrentTime; // ������� �����, CurrentTime+StartTime==GlobalTime +// float StartTime; // ����� ������ ����� +// float FinishTime; // ����� ����� + float AnimTime; // ����� �������� cBaseTrail(unsigned int type,unsigned int kind) : cBaseObject(type,kind) { /*StartTime=0;*/ } }; @@ -54,4 +54,4 @@ enum TrailType { TrailTypeMax }; -#endif __BASETRAIL_H__ \ No newline at end of file +#endif // __BASETRAIL_H__ \ No newline at end of file diff --git a/MechoSoma/VisGeneric/BoundingBox.h b/MechoSoma/VisGeneric/BoundingBox.h index 9deadc43..0d0c4c7b 100644 --- a/MechoSoma/VisGeneric/BoundingBox.h +++ b/MechoSoma/VisGeneric/BoundingBox.h @@ -2,7 +2,7 @@ #define __BOUNDING_BOX_H__ #include -#include "umath.h" +#include "UMATH.H" class cBoundingBox { diff --git a/MechoSoma/VisGeneric/Camera.h b/MechoSoma/VisGeneric/Camera.h index a011b244..507f2974 100644 --- a/MechoSoma/VisGeneric/Camera.h +++ b/MechoSoma/VisGeneric/Camera.h @@ -5,9 +5,13 @@ #include "VisGenericDefine.h" #include "Math3d.h" #include "memory.h" -#include "umath.h" +#include "UMATH.H" #include "float.h" +#ifdef __APPLE__ +#define __forceinline inline +#endif + #define FLOAT_CONST_PREC 1.f class cRenderDevice; @@ -256,7 +260,7 @@ inline void WorldShareMapping(Vect3f &pos,cCamera *Camera) int d=GlobalWorldRadius-sqrt(desc); pos.x=CameraPos.x+xr; pos.y=CameraPos.y+yr; pos.z-=2*GlobalWorldRadius-d; -/* + float k=(float)GlobalWorldRadius/sqrt(l); xr=round(xr*k); yr=round(yr*k); l=xr*xr+yr*yr; diff --git a/MechoSoma/VisGeneric/Dispatcher.cpp b/MechoSoma/VisGeneric/Dispatcher.cpp index 0d68f4c2..70b2a9a1 100644 --- a/MechoSoma/VisGeneric/Dispatcher.cpp +++ b/MechoSoma/VisGeneric/Dispatcher.cpp @@ -4,14 +4,14 @@ #include #include "File3ds.h" #include "Dispatcher.h" -#include "base.h" +#include "Base.h" #include "TileMap.h" #include "BaseObject.h" #include "BaseDefine.h" #include "TexMgr.h" #include "Scene.h" -#include "SceneMesh.h" // äëÿ ÷òåíèÿ èìïîðòèðîâàííûõ ôàéëîâ +#include "scenemesh.h" // ��� ������ ��������������� ������ #include "Frame.h" #ifdef _MECHOSOMA_ @@ -21,6 +21,13 @@ extern MemoryHeap MemoryHeapDynamicShade; #endif +#ifndef _WIN32 +char *_strlwr(char *str) +{ + return str; +} +#endif + cAnimChain *AnimChain=0; cMesh *tmpMesh; float TmpPivot[3]; @@ -96,7 +103,7 @@ cMesh* cMeshLibrary::Get(char *fname,char *TexturePath,unsigned int Type,float S cMesh* cMeshLibrary::Find(char *fname) { for(cList *start=MeshList->next; start; start=start->next) - if(start->Mesh->GetFileName()==fname) return start->Mesh; + if(start->Mesh->GetFileName()==static_cast(fname)) return start->Mesh; return 0; } cMesh* cMeshLibrary::Find(unsigned int Type) @@ -114,7 +121,7 @@ cMesh* cMeshLibrary::CopyObject(cMesh *Mesh,unsigned int Type) } inline sObjectMesh *GetObjectByName(sLodObject *LodObject,char *name) -{ // ôóíêöèÿ èùåò â LOD'å îáúåêò ïîèìåíè è âðåìåíè àíèìàöèè +{ // ������� ���� � LOD'� ������ ������� � ������� �������� for(int nNodeObject=0;nNodeObjectNodeObjectLibrary.length();nNodeObject++) { sNodeObject *NodeObject=LodObject->NodeObjectLibrary[nNodeObject]; @@ -122,7 +129,7 @@ inline sObjectMesh *GetObjectByName(sLodObject *LodObject,char *name) { case NODEOBJECT_MESH: sObjectMesh *ObjectMesh=(sObjectMesh*)NodeObject; - if(ObjectMesh->name==name) + if(ObjectMesh->name==static_cast(name)) return ObjectMesh; break; } @@ -134,8 +141,8 @@ void GetMatrix(cMatrix &Matrix,sNodeObject *StartNodeObject,sLodObject *LodObjec { for(sNodeObject *NodeObject=StartNodeObject;NodeObject;NodeObject=LodObject->NodeObjectLibrary.Get((char*)NodeObject->parent)) { - cMatrix AnimationMatrix; // ìàòðèöà ïîëîæåíèÿ îáúåêòà îòíîñèòåëüíîãî ðîäèòåëÿ - AnimationMatrix.NewMatrix(); // óñòàíîâêà ìàòðèöû àíèìàöèè + cMatrix AnimationMatrix; // ������� ��������� ������� �������������� �������� + AnimationMatrix.NewMatrix(); // ��������� ������� �������� sAnimationPosition &AnimationPosition=NodeObject->AnimationPosition; sAnimationRotation &AnimationRotation=NodeObject->AnimationRotation; sAnimationScale &AnimationScale=NodeObject->AnimationScale; @@ -193,19 +200,19 @@ sTile* ReadAnimationMesh(char *fname,sLodObject *LodObject,sObjectMesh *ObjectMe Tile->GetName()=ObjectMesh->name; sVertexMesh &Vertex=AnimationMesh->Vertex; sFaceMesh &Face=AnimationMesh->Face; - assert(Face.length()); // òåñò íà ëèêâèäíîñòü ìîäåëè + assert(Face.length()); // ���� �� ����������� ������ assert(Vertex.length()); assert(Face[0][3]MaterialLibrary.length()); int nMapping=AnimationMesh->ChannelMappingLibrary.length(); sChannelMapping *ChannelMapping=0; if(nMapping) ChannelMapping=AnimationMesh->ChannelMappingLibrary[0]; - if((nMapping==0)||(ChannelMapping->ChannelNumber==0)) // îáúåêò íå ñîäåðæèò òåêñòóðíûõ êîîðäèíàò (íåò òåêñòóðû) + if((nMapping==0)||(ChannelMapping->ChannelNumber==0)) // ������ �� �������� ���������� ��������� (��� ��������) if(IsStatic) Tile->NewTri(Face.length(),Vertex.length(),0,0); else ((sObjTri*)Tile)->NewTri(Vertex.length(),0); // Tile->NewTri(Face.length(),Vertex.length(),0,0); else - { // èìïîðò òåêñòóðíûõ êîîðäèíàò + { // ������ ���������� ��������� sTexFaceMesh &TexFace=ChannelMapping->TexFace; sTexVertexMesh &TexVertex=ChannelMapping->TexVertex; assert(TexFace.length()==Face.length()); @@ -235,7 +242,7 @@ sTile* ReadAnimationMesh(char *fname,sLodObject *LodObject,sObjectMesh *ObjectMe for(k=0;kGetNumberPolygon();k++) pPolygon[k].set(Face[k][0],Face[k][1],Face[k][2]); } - // èìïîðò ñâîéñòâ ìàòåðèàëà îáúåêòà + // ������ ������� ��������� ������� if((LodObject->MaterialLibrary.length()==0)||(Face[0][3]<0)) { XBuffer buf; buf<"Error: ReadAnimationMesh()\r\nNot found material by object <"name<"> in file <"\r\n"; ErrH.Abort(buf.address()); } sMaterialObject *Material=LodObject->MaterialLibrary[Face[0][3]]; @@ -243,7 +250,7 @@ sTile* ReadAnimationMesh(char *fname,sLodObject *LodObject,sObjectMesh *ObjectMe int dt=0x0FFFFFFF; for(int nAnimationMaterial=0;nAnimationMaterialAnimationMaterialLibrary.length();nAnimationMaterial++) if(abs(Material->AnimationMaterialLibrary[nAnimationMaterial]->time-time)AnimationMaterialLibrary[nAnimationMaterial]; dt=abs(Material->AnimationMaterialLibrary[nAnimationMaterial]->time-time); } @@ -266,7 +273,7 @@ sTile* ReadAnimationMesh(char *fname,sLodObject *LodObject,sObjectMesh *ObjectMe default: assert(0); } - switch(round(ShinStrength*100)) + switch(int(round(ShinStrength*100))) { case 100: Tile->GetMaterial()->SetAttribute(ATTRMAT_MASK); break; default: @@ -274,15 +281,15 @@ sTile* ReadAnimationMesh(char *fname,sLodObject *LodObject,sObjectMesh *ObjectMe break; } Tile->GetMaterial()->SetTexture(Texture,Opacity); - // èìïîðò àíèìàöèè êîðíåâîãî îáúåêòà .. + // ������ �������� ��������� ������� .. - // .. ïîêà íå ðåàëèçîâàíî - // !!! è åùå íóæíî äîáàâèòü êâàòåðíèîí SCALEAXIS êàê â ASCII !!! + // .. ���� �� ����������� + // !!! � ��� ����� �������� ���������� SCALEAXIS ��� � ASCII !!! cMatrix Matrix; Matrix.NewMatrix(); for(sNodeObject *NodeObject=ObjectMesh;NodeObject;NodeObject=LodObject->NodeObjectLibrary.Get((char*)NodeObject->parent)) { - cMatrix AnimationMatrix; // ìàòðèöà ïîëîæåíèÿ îáúåêòà îòíîñèòåëüíîãî ðîäèòåëÿ - AnimationMatrix.NewMatrix(); // óñòàíîâêà ìàòðèöû àíèìàöèè + cMatrix AnimationMatrix; // ������� ��������� ������� �������������� �������� + AnimationMatrix.NewMatrix(); // ��������� ������� �������� sAnimationPosition &AnimationPosition=NodeObject->AnimationPosition; sAnimationRotation &AnimationRotation=NodeObject->AnimationRotation; sAnimationScale &AnimationScale=NodeObject->AnimationScale; @@ -424,7 +431,7 @@ inline int IsAnimate(cMaterialObjectLibrary &MaterialLibrary,sObjectMesh *Object cMesh* cMeshLibrary::Loadm3d(char *fname,char *TexturePath,unsigned int Type,float SizeObject) { cMeshScene MeshScene; - // çàãðóçêà MeshScene ñöåíû èç ôàéëà + // �������� MeshScene ����� �� ����� cMeshFile f; int size=0; void *buf=0; @@ -433,11 +440,11 @@ cMesh* cMeshLibrary::Loadm3d(char *fname,char *TexturePath,unsigned int Type,flo f.ReadHeaderFile(); MeshScene.Read(f); f.Close(); - // ñîçäàíèå îáúåêòà ïî îïèñàííèþ â ñöåíå + // �������� ������� �� ��������� � ����� cMesh *tmpMesh=0,*BaseMesh=0,*Bound=0; int UseAnimation=0; cFrame *Frame=new cFrame; - // ïîèñê è óñòàíîâêà ïåðâûì êàíàëà àíèìàöèè ñ èìåíåì "main" + // ����� � ��������� ������ ������ �������� � ������ "main" int nChannelMain=-1; int nChannel; for(nChannel=0;nChannelAddAnimChain(); float FirstFrame=Channel->FirstFrame*Channel->TicksPerFrame; AnimChain->GetName()=_strlwr(Channel->name); AnimChain->SetTimeChain((Channel->LastFrame-Channel->FirstFrame)*Channel->TicksPerFrame); for(int LevelDetail=0;LevelDetailLodLibrary.length();LevelDetail++) - { // èìïîðò óðîâíÿ äåòàëèçàöèè + { // ������ ������ ����������� sLodObject *LodObject=Channel->LodLibrary[LevelDetail]; for(int nNodeObject=0;nNodeObjectNodeObjectLibrary.length();nNodeObject++) - { // èìïîðò êîðíåâîãî îáúåêòà + { // ������ ��������� ������� sNodeObject *NodeObject=LodObject->NodeObjectLibrary[nNodeObject]; char NameMesh[256],NameParent[256]; strcpy(NameMesh,NodeObject->name); @@ -468,12 +475,12 @@ cMesh* cMeshLibrary::Loadm3d(char *fname,char *TexturePath,unsigned int Type,flo switch(NodeObject->type) { case NODEOBJECT_MESH: - { // èìïîðò 3d-îáúåêòà + { // ������ 3d-������� sObjectMesh *ObjectMesh=(sObjectMesh*)NodeObject; if((ObjectMesh->name)&&(TestFirstName(ObjectMesh->name,"Bip"))) - continue; // ïðîïóñòèòü "Bip" èç CharacterStudio + continue; // ���������� "Bip" �� CharacterStudio if(nChannel==0) - { // èìïîðò ñòàòè÷åñêîãî îáúåêòà + { // ������ ������������ ������� sColor4f Diffuse,Specular; void *Pointer=0; float Shininess=0; @@ -482,13 +489,13 @@ cMesh* cMeshLibrary::Loadm3d(char *fname,char *TexturePath,unsigned int Type,flo sTile *Tile=ReadAnimationMesh(fname,LodObject,ObjectMesh,ObjectMesh->AnimationMeshLibrary[0],FirstFrame,TexturePath,1); Tile->GetID()=gb_TileID++; if(strcmp(NameMesh,M3D_BOUND_STRING)==0) - { // îáúåêò ÿâëÿåòñÿ ãðàíèöåé + { // ������ �������� �������� Bound=new cMesh(); Bound->SetName(NameMesh); Bound->AddTile(Tile); } else if((BaseMesh==0)||((tmpMesh=BaseMesh->FindMesh(NameParent))==0)) - { // îáúåêò ãëàâíûé ðîäèòåëü + { // ������ ������� �������� if(BaseMesh==0) { BaseMesh=tmpMesh=AddMesh(NameMesh); @@ -498,11 +505,11 @@ cMesh* cMeshLibrary::Loadm3d(char *fname,char *TexturePath,unsigned int Type,flo } BaseMesh->AddTile(Tile); } - else // îáúåêò - íåïîäâèæíàÿ ÷àñòü + else // ������ - ����������� ����� tmpMesh->AddTile(Tile); } // if((ObjectMesh->AnimationMeshLibrary.length()>1)||(MeshScene.ChannelLibrary.length()>1)) - { // èìïîðò ìîðôèíãà îáúåêòà + { // ������ �������� ������� UseAnimation=1; for(int nFrame=0;nFrameNumberFrame;nFrame++) { @@ -555,24 +562,24 @@ cMesh* cMeshLibrary::Loadm3d(char *fname,char *TexturePath,unsigned int Type,flo } } for(nChannel=0;nChannelLodLibrary.length();LevelDetail++) - { // èìïîðò óðîâíÿ äåòàëèçàöèè + { // ������ ������ ����������� sLodObject *LodObject=Channel->LodLibrary[LevelDetail]; for(int nNodeObject=0;nNodeObjectNodeObjectLibrary.length();nNodeObject++) - { // èìïîðò êîðíåâîãî îáúåêòà + { // ������ ��������� ������� sNodeObject *NodeObject=LodObject->NodeObjectLibrary[nNodeObject]; switch(NodeObject->type) { case NODEOBJECT_MESH: break; case NODEOBJECT_HELPER: - if(nChannel==0) // èìïîðò òîëüêî ñòàòè÷åñêèõ âñïîìîãàòåëüíûõ îáúåêòîâ - { // èìïîðò âñïîìîãàòåëüíîãî-îáúåêòà + if(nChannel==0) // ������ ������ ����������� ��������������� �������� + { // ������ ����������������-������� sHelperObject *HelperObject=(sHelperObject*)NodeObject; if(stricmp(HelperObject->HelperName,"Dummy")==0) - { // èìïîðò âñïîìîãàòåëüíîãî îáúåêòà - äàììè + { // ������ ���������������� ������� - ����� Vect3f v(gb_sign.x*HelperObject->matrix[9], gb_sign.y*HelperObject->matrix[10], gb_sign.z*HelperObject->matrix[11]); @@ -616,7 +623,7 @@ cMesh* cMeshLibrary::Load3ds(char *fname,char *TexturePath,unsigned int Type,flo if(f.Open(fname)==0) return 0; char TextureName[17],NameMesh[22],Shading,OpacityName[17]; int NumberObject3ds=f.OpenBaseMesh(),nPoint,nPolygon; - if(SizeObject!=0) f.MaxSizeMesh(NumberObject3ds,SizeObject); // º¸ªðýþòúð ü𸰪ðñð ÷ðó¨ºöðõüþóþ þñ·õúªð + if(SizeObject!=0) f.MaxSizeMesh(NumberObject3ds,SizeObject); // ��������� �𸰪��� ���������� ������ int NumberKeyFrame=f.OpenBaseKeyFrame(); cMesh *tmpMesh=0,*BaseMesh=0,*Bound=0; int i; @@ -636,7 +643,7 @@ cMesh* cMeshLibrary::Load3ds(char *fname,char *TexturePath,unsigned int Type,flo if(Tile->GetDiffuse().a<0) Tile->GetDiffuse().a=0; else if(Tile->GetDiffuse().a>1) Tile->GetDiffuse().a=1; if(Shading==4) Tile->GetMaterial()->SetAttribute(ATTRMAT_METAL); - switch(round(ShinStrength*100)) + switch(int(round(ShinStrength*100))) { case 100: Tile->GetMaterial()->SetAttribute(ATTRMAT_MASK); break; default: @@ -659,7 +666,7 @@ cMesh* cMeshLibrary::Load3ds(char *fname,char *TexturePath,unsigned int Type,flo for(k=0;kGetPolygon(); @@ -684,13 +691,13 @@ cMesh* cMeshLibrary::Load3ds(char *fname,char *TexturePath,unsigned int Type,flo pPoint[k].pos-=vPivot; if(strcmp(NameMesh,M3D_BOUND_STRING)==0) - { // øýø¡øðûø÷ð¡ø  ¨ð÷üõ¨þò + { // ������������ �������� Bound=new cMesh(); Bound->SetName(NameMesh); Bound->AddTile(Tile); } else if((BaseMesh==0)||((tmpMesh=BaseMesh->FindMesh(NameParent))==0)) - { // øýø¡øðûø÷ð¡ø  ñð÷þòþóþ ¨þôøªõû  + { // ������������ �������� �������� if(BaseMesh==0) { BaseMesh=tmpMesh=AddMesh(NameMesh); @@ -701,10 +708,10 @@ cMesh* cMeshLibrary::Load3ds(char *fname,char *TexturePath,unsigned int Type,flo BaseMesh->AddTile(Tile); } else if((NumberPos<=1)&&(NumberRot<=1)&&(NumberScale<=1)&&!strstr(NameMesh, "#")) - // ôþñðòûõýøõ ÿð¸¸øòýþóþ ÿþªþüúð + // ���������� �������� ������� tmpMesh->AddTile(Tile); else - { // ¸þ÷ôðýøõ ø ÿ¨ø¸þõôøýõýøõ ðúªøòýþóþ ÿþªþüúð + { // �������� � ������������� ��������� ������� cMesh *ParentMesh=BaseMesh->FindMesh(NameParent); tmpMesh=new cMesh(); tmpMesh->SetName(NameMesh); @@ -761,7 +768,7 @@ cMesh* cMeshLibrary::Load3ds(char *fname,char *TexturePath,unsigned int Type,flo int FindTile(cMesh *Mesh,char *name) { for(int i=0;iGetNumberTile();i++) - if(Mesh->GetTile(i)->GetName()==name) return i; + if(Mesh->GetTile(i)->GetName()==static_cast(name)) return i; return -1; } cMesh* cMeshLibrary::LoadMorph(unsigned int Type,int NumberMorph,float *time,char **name3dsMorph,char *FilePath,char *TexturePath) @@ -785,7 +792,7 @@ cMesh* cMeshLibrary::LoadMorph(unsigned int Type,int NumberMorph,float *time,cha XBuffer buf; bufnext; start; start=start->next) - if((start->Mesh->Type==Morph[0]->Type)&&(start->Mesh->GetFileName()==buf.address())) + if((start->Mesh->Type==Morph[0]->Type)&&(start->Mesh->GetFileName()==static_cast(buf.address()))) { mesh=start->Mesh; break; } if(mesh==0) { @@ -864,7 +871,7 @@ void cMeshLibrary::Release(unsigned int Type) } #include "aci_parser.h" -#include "m3dsetup.h" +#include "M3DSETUP.H" cMesh* cM3D::CreateObject(unsigned int *vType,int number) { @@ -893,7 +900,7 @@ cMesh* cM3D::RebuildObject(cMesh *Mesh,unsigned int OldType,unsigned int NewType cMesh *OldMesh=Mesh->FindMesh(OldType),*tmp; if(OldMesh==0) { XBuffer buf; buf<"Error: cM3D::RebuildObject()\r\nMesh not found type = "<=OldType; ErrAbort(buf.address()); } - OldMesh->Type=0; // î÷èñòêà îáúåêòà + OldMesh->Type=0; // ������� ������� while((tmp=OldMesh->FindMesh(OldType))!=0) { tmp->DetachChild(); delete tmp; } if(OldMesh->Frame) { delete OldMesh->Frame; OldMesh->Frame=0; } @@ -967,7 +974,7 @@ void cM3D::TraceStaticObjectMechos(cUnknownClass *UCameraList) #endif void cM3D::Animate(cUnknownClass *UCameraList,int CurrentTime,int PreviousTime) -{ // âûñòàâëåíèå àíèìàöèè ñ ïåðåñ÷åòîì ìàòðèöû +{ // ����������� �������� � ���������� ������� float dTime=CurrentTime-PreviousTime; for(cList *start=MeshList->next;start;start=start->next) start->Mesh->Animate(dTime); @@ -986,25 +993,25 @@ void cM3D::TestVisible(cUnknownClass *UCameraList) { assert(UCameraList->GetKind(KIND_ARRAYCAMERA)); for(cList *start=MeshList->next;start;start=start->next) - { // òåñò íà âèäèìîñòü îáúåêòà + { // ���� �� ��������� ������� cMesh &Mesh=*start->Mesh; if(Mesh.isVisibleTotal(UCameraList)&CONST_VISIBLE_SHOW) Mesh.TestVisible(UCameraList); } } void cM3D::Draw(cUnknownClass *UScene) -{ // îòðèñîâêà çàêýøèðîâàííûõ îáúåêòîâ +{ // ��������� �������������� �������� assert(UScene->GetKind(KIND_SCENE)); cScene *Scene=(cScene*)UScene; cUnknownClass *UCameraList=Scene->GetCameraList(); assert(UCameraList->GetKind(KIND_ARRAYCAMERA)); - // îòðèñîâêà âñåõ íå ïðîçðà÷íûõ îáúåêòîâ + // ��������� ���� �� ���������� �������� cList *start; for(start=MeshList->next;start;start=start->next) if(start->Mesh->GetAttribute(MESH_USE_OPACITY|MESH_NOT_WRITEZBUFFER)==0) if(start->Mesh->isVisibleTotal(UCameraList)&CONST_VISIBLE_FRUSTUM) start->Mesh->Draw(UScene,UCameraList); - // îòðèñîâêà âñåõ ïðîçðà÷íûõ îáúåêòîâ + // ��������� ���� ���������� �������� for(start=MeshList->next;start;start=start->next) if(start->Mesh->GetAttribute(MESH_USE_OPACITY|MESH_NOT_WRITEZBUFFER)) if(start->Mesh->isVisibleTotal(UCameraList)&CONST_VISIBLE_FRUSTUM) @@ -1114,7 +1121,7 @@ cMesh* cM3D::CreateObject(unsigned int Type,float x,float y,float z,float ax,flo SetPosition(Mesh,x,y,z,ax,ay,az); return Mesh; } -void cM3D::LoadLib(char *fname) +void cM3D::LoadLib(const std::filesystem::path &path) { // allocation_tracking("Begin Load Lib"); int kind, type, eff_id; @@ -1126,7 +1133,7 @@ void cM3D::LoadLib(char *fname) cMesh* mesh; scrDataBlock* p,*p1,*root,*ap; - root = loadScript(fname); + root = loadScript(path); p3ds0 = NULL; pbmp0 = NULL; @@ -1517,8 +1524,8 @@ void cM3D::SaveMap(char *fname,char Version) #endif float AnimatePeriod=0,AnimatePhase=0,finish; Mesh->GetAnimation(AnimatePeriod,AnimatePhase,finish); - if(!_finite(AnimatePeriod)) AnimatePeriod=0; - if(!_finite(AnimatePhase)) AnimatePhase=0; + if(!isfinite(AnimatePeriod)) AnimatePeriod=0; + if(!isfinite(AnimatePhase)) AnimatePhase=0; f.write(&AnimatePeriod,sizeof(AnimatePeriod)); f.write(&AnimatePhase,sizeof(AnimatePhase)); break; } @@ -1552,8 +1559,8 @@ void cM3D::SaveMap(char *fname,char Version) #endif float AnimatePeriod=0,AnimatePhase=0,finish; Mesh->GetAnimation(AnimatePeriod,AnimatePhase,finish); - if(!_finite(AnimatePeriod)) AnimatePeriod=0; - if(!_finite(AnimatePhase)) AnimatePhase=0; + if(!isfinite(AnimatePeriod)) AnimatePeriod=0; + if(!isfinite(AnimatePhase)) AnimatePhase=0; f.write(&AnimatePeriod,sizeof(AnimatePeriod)); f.write(&AnimatePhase,sizeof(AnimatePhase)); int MeshAttribute=0; @@ -1593,8 +1600,8 @@ void cM3D::SaveMap(char *fname,char Version) #endif float AnimatePeriod=0,AnimatePhase=0,finish; Mesh->GetAnimation(AnimatePeriod,AnimatePhase,finish); - if(!_finite(AnimatePeriod)) AnimatePeriod=0; - if(!_finite(AnimatePhase)) AnimatePhase=0; + if(!isfinite(AnimatePeriod)) AnimatePeriod=0; + if(!isfinite(AnimatePhase)) AnimatePhase=0; f.write(&AnimatePeriod,sizeof(AnimatePeriod)); f.write(&AnimatePhase,sizeof(AnimatePhase)); int MeshAttribute=0; @@ -1655,8 +1662,8 @@ void cM3D::SaveMap(char *fname,char Version) #endif float AnimatePeriod=0,AnimatePhase=0,finish; Mesh->GetAnimation(AnimatePeriod,AnimatePhase,finish); - if(!_finite(AnimatePeriod)) AnimatePeriod=0; - if(!_finite(AnimatePhase)) AnimatePhase=0; + if(!isfinite(AnimatePeriod)) AnimatePeriod=0; + if(!isfinite(AnimatePhase)) AnimatePhase=0; f<=AnimatePeriod<" "<=AnimatePhase<"\r\n"; break; } case 'o': { @@ -1677,8 +1684,8 @@ void cM3D::SaveMap(char *fname,char Version) #endif float AnimatePeriod=0,AnimatePhase=0,finish; Mesh->GetAnimation(AnimatePeriod,AnimatePhase,finish); - if(!_finite(AnimatePeriod)) AnimatePeriod=0; - if(!_finite(AnimatePhase)) AnimatePhase=0; + if(!isfinite(AnimatePeriod)) AnimatePeriod=0; + if(!isfinite(AnimatePhase)) AnimatePhase=0; f<=AnimatePeriod<" "<=AnimatePhase<"\r\n"; int MeshAttribute=0; if(Mesh->GetAttribute(MESH_CAMERAEFFECT)) MeshAttribute=1<<0; @@ -1705,8 +1712,8 @@ void cM3D::SaveMap(char *fname,char Version) #endif float AnimatePeriod=0,AnimatePhase=0,finish; Mesh->GetAnimation(AnimatePeriod,AnimatePhase,finish); - if(!_finite(AnimatePeriod)) AnimatePeriod=0; - if(!_finite(AnimatePhase)) AnimatePhase=0; + if(!isfinite(AnimatePeriod)) AnimatePeriod=0; + if(!isfinite(AnimatePhase)) AnimatePhase=0; f<=AnimatePeriod<" "<=AnimatePhase<"\r\n"; int MeshAttribute=0; if(Mesh->GetAttribute(MESH_CAMERAEFFECT)) MeshAttribute=1<<0; @@ -2151,7 +2158,7 @@ void cM3D::DrawCircleDynamic(Vect3f &pos,sColor4f &color,float radius) void DrawShadeDynamicToColor16(short *shade,int xShade,int yShade,Vect3f &PosShade) { // if(RenderMode==XGRAPH_HICOLOR) return; - int xSh=TERRA_XCYCL(round(PosShade.x)),ySh=TERRA_YCYCL(round(PosShade.y)),zSh=round(PosShade.z); + int xSh=TERRA_XCYCL(int(round(PosShade.x))),ySh=TERRA_YCYCL(int(round(PosShade.y))),zSh=round(PosShade.z); short *shadeBuf=shade; int dzx=(1<<16)/CONST_DYNAMIC_SHADE_MESH; #ifdef _USE_TILEMAP_ diff --git a/MechoSoma/VisGeneric/Dispatcher.h b/MechoSoma/VisGeneric/Dispatcher.h index f9cc58cd..a8728e37 100644 --- a/MechoSoma/VisGeneric/Dispatcher.h +++ b/MechoSoma/VisGeneric/Dispatcher.h @@ -1,6 +1,8 @@ #ifndef __DISPATCHER_H__ #define __DISPATCHER_H__ +#include + #include "Math3d.h" #include "Object.h" #include "Object3d.h" @@ -56,14 +58,14 @@ class cM3D : cShadeDispatcher unsigned int NumberID; cM3D() { MeshList=new cList(); NumberID=0; Window=0; prev_global_time = 0; } ~cM3D() { Release(0); } - // çàãðóçêà - void LoadLib(char *fname); + // �������� + void LoadLib(const std::filesystem::path &path); void LoadMap(char *fname,int LoadNumberTrack=0xFFFFFFFF); void SaveMap(char *fname,char Version='O'); - // âûâîä + // ����� void TestVisible(cUnknownClass *UCameraList); void Draw(cUnknownClass *UCameraList); - // ñîçäàíèå îáúåêòîâ è ò.ä. + // �������� �������� � �.�. cMesh* CreateObject(unsigned int *vType,int number); // Constructor objects cMesh* CreateObject(char *fname,char *TexturePath,unsigned int Type=0,float SizeObject=MAX_SIZE_OBJECT); cMesh* CreateObject(unsigned int Type,float x,float y,float z,float ax,float ay,float az); @@ -85,10 +87,10 @@ class cM3D : cShadeDispatcher cMesh* FindUnique(unsigned int unique); cList* AttachEnd(cMesh *Mesh); - cList* Attach(cMesh *Mesh); // ïðèñîåäèíèå îáúåêòà ê ñïèñêó - void Detach(cMesh *Mesh); // îòñîåäèíåíèå îáúåêòà îò ñïèñêà - void Delete(cMesh *Mesh); // óäàëåíèå îáúåêòà â ñïèñêå - void Release(unsigned int Type=M3D_STATIC); // óäàëåíèå îáúåêòîâ èç ñïèñêà ïî òèïó + cList* Attach(cMesh *Mesh); // ����������� ������� � ������ + void Detach(cMesh *Mesh); // ������������ ������� �� ������ + void Delete(cMesh *Mesh); // �������� ������� � ������ + void Release(unsigned int Type=M3D_STATIC); // �������� �������� �� ������ �� ���� #ifdef _MECHOSOMA_ void SetArcane(void (*FunctionSetArcane)(mchArcaneData*)); #endif diff --git a/MechoSoma/VisGeneric/DrawPolygonShade.h b/MechoSoma/VisGeneric/DrawPolygonShade.h index f4736802..35fd9b59 100644 --- a/MechoSoma/VisGeneric/DrawPolygonShade.h +++ b/MechoSoma/VisGeneric/DrawPolygonShade.h @@ -1,7 +1,7 @@ #ifndef __DRAWPOLYGONSHADE_H__ #define __DRAWPOLYGONSHADE_H__ -#include "umath.h" +#include "UMATH.H" #include "Material.h" #include "IGraph3d.h" diff --git a/MechoSoma/VisGeneric/Dummy.cpp b/MechoSoma/VisGeneric/Dummy.cpp index ae98aef1..1636f2cc 100644 --- a/MechoSoma/VisGeneric/Dummy.cpp +++ b/MechoSoma/VisGeneric/Dummy.cpp @@ -1,18 +1,21 @@ -#include "_xtool.h" +#include "xtool.h" #include "Base.h" #include "Dummy.h" #include "HashStringGroup.h" -#include "my_STL.h" + +#ifndef _WIN32 +#include "port.h" +#endif ////////////////////////////////////////////////////////////////////////// -// Hash-table äëÿ îïðåäåëåíèÿ òèïîâ äàììè +// Hash-table ��� ����������� ����� ����� ////////////////////////////////////////////////////////////////////////// struct DummyNameMap : HashStringGroup { DummyNameMap() { add("engine", M3D_ENGINE); - add("back", M3D_ENGINE); // ÷òîáû íå ïåðåèìåíîâûâàòü çàäíèå êîëåñà + add("back", M3D_ENGINE); // ����� �� ��������������� ������ ������ add("front", M3D_FRONT); add("lf_wheel", M3D_LF_WHEEL); diff --git a/MechoSoma/VisGeneric/Dummy.h b/MechoSoma/VisGeneric/Dummy.h index 1e70f277..d4346c23 100644 --- a/MechoSoma/VisGeneric/Dummy.h +++ b/MechoSoma/VisGeneric/Dummy.h @@ -4,6 +4,11 @@ #include #include "xmath.h" +#ifndef FOR_EACH +#define FOR_EACH(list, iterator) \ + for((iterator) = (list).begin(); (iterator) != (list).end(); ++(iterator)) +#endif + using namespace std; unsigned int CalcType(char* NameMesh); diff --git a/MechoSoma/VisGeneric/File3ds.cpp b/MechoSoma/VisGeneric/File3ds.cpp index 321c172f..6e6668de 100644 --- a/MechoSoma/VisGeneric/File3ds.cpp +++ b/MechoSoma/VisGeneric/File3ds.cpp @@ -1,8 +1,7 @@ -#include "stdlib.h" -#include "windows.h" +#include #include "File3ds.h" -#include "math.h" -#include "math3d.h" +#include +#include "Math3d.h" #include "BaseDefine.h" #ifdef _MECHOSOMA_ diff --git a/MechoSoma/VisGeneric/Frame.cpp b/MechoSoma/VisGeneric/Frame.cpp index 91eb680d..dc9fab38 100644 --- a/MechoSoma/VisGeneric/Frame.cpp +++ b/MechoSoma/VisGeneric/Frame.cpp @@ -90,7 +90,7 @@ void cAnimChain::GetTile(cTile *Tile,float phase) if(a->GetNumberPoint()!=tmp->GetNumberPoint()) ErrAbort("Error:cAnimChain::GetTri()"); if((b)&&(ia!=ib)) - { // ìîðôèíã + { // ������� float aTime=GetTri(ia)->Time,bTime=GetTri(ib)->Time; assert(aTime!=bTime); if(a->GetNumberPoint()!=b->GetNumberPoint()) @@ -122,7 +122,7 @@ void cAnimChain::GetTile(cTile *Tile,float phase) } } } - else // íåò ìîðôèðîâàíèÿ + else // ��� ������������ { tmp->MulCol=a->MulCol; tmp->AddCol=a->AddCol; @@ -148,7 +148,7 @@ inline float QuadraticInterpolate(float x1,float x2,float y1,float y2,float ky1, return y1+((y2-y1)/dx-(3*ky1+ky2)*0.125*dx)*dt+(ky1*dt*dt+(ky2-ky1)*ts)*0.5f; } inline void SlerpInterpolate(float w1,float x1,float y1,float z1,float w2,float x2,float y2,float z2,float *w,float *x,float *y,float *z,float t) -{ // Slerp(q1,q2,t) = (sin((1-t)*¿)/sin(¿))*q1+(sin(t*¿)/sin(¿))*q2 +{ // Slerp(q1,q2,t) = (sin((1-t)*�)/sin(�))*q1+(sin(t*�)/sin(�))*q2 float scale0,scale1,cosom=x1*x2+y1*y2+z1*z2+w1*w2; if((1+cosom)>0.0001) { @@ -579,12 +579,12 @@ int cFrame::SetCurrentChain(char *NameChain) { assert(NameChain); for(int i=0;iGetName()==NameChain) + if(GetAnimChain(i)->GetName()==static_cast(NameChain)) return SetCurrentChain(i); return -1; } int cFrame::SetCurrentChain(char *NameChainMask,int number) -{ // âîçâðàùàåò ÷èñëî öåïî÷åê èìåþùèõ â èìåíè ñòðîêó NameChainMask +{ // ���������� ����� ������� ������� � ����� ������ NameChainMask if(GetNumberAnimChain()<=0) return -1; if(NameChainMask==0) return GetNumberAnimChain(); int count=0; @@ -594,7 +594,7 @@ int cFrame::SetCurrentChain(char *NameChainMask,int number) return -1; } int cFrame::GetChain(char *NameChainMask) -{ // âîçâðàùàåò ÷èñëî öåïî÷åê èìåþùèõ â èìåíè ñòðîêó NameChainMask +{ // ���������� ����� ������� ������� � ����� ������ NameChainMask if(NameChainMask==0) return GetNumberAnimChain(); int count=0; for(int i=0;iSetViewport(&vp); +#endif return 0; } int cGraph3dDirect3D::GetClipRect(int *xmin,int *ymin,int *xmax,int *ymax) @@ -263,7 +269,7 @@ int cGraph3dDirect3D::SetTexture(int hTexture) int cGraph3dDirect3D::LockTexture(int hTexture,void **TextureBuffer,int *BytePerLine) { assert(hTexture); - return d3dLockTexture((int)hTexture,TextureBuffer,(unsigned long*)BytePerLine)!=MD3D_OK; + return d3dLockTexture((DWORD)hTexture,TextureBuffer,(DWORD *)BytePerLine)!=MD3D_OK; } int cGraph3dDirect3D::UnlockTexture(int hTexture) { @@ -272,7 +278,7 @@ int cGraph3dDirect3D::UnlockTexture(int hTexture) } int cGraph3dDirect3D::CreateTexture(int x,int y,eTextureFormat TextureFormat) { - unsigned long hTexture; + DWORD hTexture; int TexFormat3d; switch(TextureFormat) { @@ -411,7 +417,7 @@ int cGraph3dDirect3D::DrawPixel(int x1,int y1,int r,int g,int b,int a) int cGraph3dDirect3D::SetMaterial(eMaterialMode material) { if(MaterialMode==material) return 0; - // âîññòàíîâëåíèå ìàòåðèàëîâ + // �������������� ���������� if(MaterialMode&(MAT_ALPHA_MOD_TEXTURE1|MAT_ALPHA_MASK_TEXTURE1)) { d3dSetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,FALSE); @@ -426,7 +432,7 @@ int cGraph3dDirect3D::SetMaterial(eMaterialMode material) d3dSetRenderState(D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA); d3dSetRenderState(D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA); } - // óñòàíîâêà ìàòåðèàëîâ + // ��������� ���������� MaterialMode=material; if(MaterialMode&(MAT_ALPHA_MOD_TEXTURE1|MAT_ALPHA_MOD_DIFFUSE)) d3dSetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE); @@ -557,15 +563,15 @@ int cGraph3dDirect3D::GetTextureFormatData(sTextureFormatData &TexFmtData) d3dTexFmt.dwRBitShift,d3dTexFmt.dwGBitShift,d3dTexFmt.dwBBitShift,d3dTexFmt.dwAlphaBitShift); return error!=MD3D_OK; } -////////////////////////// íà÷àëî ïðî÷èå ôóíêöèè ////////////////////////// +////////////////////////// ������ ������ ������� ////////////////////////// int cGraph3dDirect3D::CreateSprite(DWORD dwWidth,DWORD dwHeight,DWORD dwFormat,DWORD dwFlags,DWORD* lpdwHandle ) { - return d3dCreateSprite(dwWidth,dwHeight,dwFormat,dwFlags,(unsigned long*)lpdwHandle); + return d3dCreateSprite(dwWidth,dwHeight,dwFormat,dwFlags,(DWORD*)lpdwHandle); } int cGraph3dDirect3D::CreateChildSprite(DWORD dwParentHandle,DWORD dwLeft,DWORD dwTop, DWORD dwWidth,DWORD dwHeight,DWORD* lpdwHandle) { - return d3dCreateChildSprite(dwParentHandle,dwLeft,dwTop,dwWidth,dwHeight,(unsigned long*)lpdwHandle); + return d3dCreateChildSprite(dwParentHandle,dwLeft,dwTop,dwWidth,dwHeight,(DWORD*)lpdwHandle); } int cGraph3dDirect3D::DeleteSprite(DWORD dwHandle) { @@ -573,7 +579,7 @@ int cGraph3dDirect3D::DeleteSprite(DWORD dwHandle) } int cGraph3dDirect3D::LockSprite(DWORD dwHandle,void **lplpSprite,DWORD *lplpPitch) { - return d3dLockSprite(dwHandle,lplpSprite,(unsigned long*)lplpPitch); + return d3dLockSprite(dwHandle,lplpSprite,(DWORD*)lplpPitch); } int cGraph3dDirect3D::UnlockSprite(DWORD dwHandle) { @@ -713,6 +719,7 @@ int cGraph3dDirect3D::DrawRectangle(int x,int y,int dx,int dy,int r,int g,int b, } int cGraph3dDirect3D::OutText(int x,int y,char *string,int r,int g,int b,int a) { +#ifdef _WIN32 HDC hdc; RECT rect = { x, y, xScr, yScr}; GetBackBufferDC(&hdc); @@ -721,6 +728,7 @@ int cGraph3dDirect3D::OutText(int x,int y,char *string,int r,int g,int b,int a) DrawText(hdc, string, strlen(string), &rect, DT_EXPANDTABS); SelectObject(hdc, hold_font); ReleaseBackBufferDC(hdc); +#endif return 1; } ////////////////////////// PRIVATE ////////////////////////// @@ -729,18 +737,18 @@ void cGraph3dDirect3D::InitRenderState() d3dSetProjectionMatrixToIdentity(); d3dSetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0); - d3dSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // õèíò D3DTSS_COLORARG1==D3DTA_TEXTURE, èíà÷å ìîæåò íå ðàáîòàòü + d3dSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // ���� D3DTSS_COLORARG1==D3DTA_TEXTURE, ����� ����� �� �������� d3dSetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); d3dSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); - d3dSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); // õèíò D3DTSS_COLORARG1==D3DTA_TEXTURE, èíà÷å ìîæåò íå ðàáîòàòü + d3dSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); // ���� D3DTSS_COLORARG1==D3DTA_TEXTURE, ����� ����� �� �������� d3dSetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); d3dSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); d3dSetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1); - d3dSetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // õèíò D3DTSS_COLORARG1==D3DTA_TEXTURE, èíà÷å ìîæåò íå ðàáîòàòü + d3dSetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // ���� D3DTSS_COLORARG1==D3DTA_TEXTURE, ����� ����� �� �������� d3dSetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); d3dSetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); - d3dSetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); // õèíò D3DTSS_COLORARG1==D3DTA_TEXTURE, èíà÷å ìîæåò íå ðàáîòàòü + d3dSetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); // ���� D3DTSS_COLORARG1==D3DTA_TEXTURE, ����� ����� �� �������� d3dSetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); d3dSetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); diff --git a/MechoSoma/VisGeneric/Graph3d/IGraph3d.cpp b/MechoSoma/VisGeneric/Graph3d/IGraph3d.cpp index 355a6eba..333dfa41 100644 --- a/MechoSoma/VisGeneric/Graph3d/IGraph3d.cpp +++ b/MechoSoma/VisGeneric/Graph3d/IGraph3d.cpp @@ -1,6 +1,8 @@ #include "assert.h" #include "IGraph3d.h" +#ifdef _WIN32 #include "Graph3d_Software.h" +#endif #include "Graph3d_Direct3d.h" cInterfaceGraph3d::cInterfaceGraph3d() @@ -14,8 +16,10 @@ cInterfaceGraph3d* CreateIGraph3D(int InterfaceGraph3d) { switch(InterfaceGraph3d) { +#ifdef _WIN32 case GRAPH3D_SOFTWARE: return new cGraph3dSoftware; +#endif case GRAPH3D_DIRECT3D: return new cGraph3dDirect3D; } diff --git a/MechoSoma/VisGeneric/Graph3d/IGraph3d.h b/MechoSoma/VisGeneric/Graph3d/IGraph3d.h index 5964c3bd..7d8206a7 100644 --- a/MechoSoma/VisGeneric/Graph3d/IGraph3d.h +++ b/MechoSoma/VisGeneric/Graph3d/IGraph3d.h @@ -1,9 +1,13 @@ #ifndef __IGRAPH3D_H__ #define __IGRAPH3D_H__ +#ifdef _WIN32 #include #include -#include +#else +#define NULL 0 +#endif +#include #define GET_INT_RGBA(r,g,b,a) (((a)<<24)|((r)<<16)|((g)<<8)|(b)) @@ -17,15 +21,15 @@ enum eInterfaceGraph3d enum eModeGraph3d { GRAPH3D_MODE_NULL = 0<<0, - GRAPH3D_MODE_DEBUG = 1<<1, // îòëàäî÷íûé çàïóñê - GRAPH3D_MODE_WINDOW = 1<<2, // âûâîä â îêíî + GRAPH3D_MODE_DEBUG = 1<<1, // ���������� ������ + GRAPH3D_MODE_WINDOW = 1<<2, // ����� � ���� - GRAPH3D_MODE_RGB16 = 1<<10, // 16 áèòíûé öâåò - GRAPH3D_MODE_RGB32 = 1<<11, // 32 áèòíûé öâåò - GRAPH3D_MODE_Z16 = 1<<12, // 16 áèòíûé z-áóôôåð - GRAPH3D_MODE_Z32 = 1<<13, // 32 áèòíûé z-áóôôåð - GRAPH3D_MODE_T16 = 1<<14, // 16 áèòíûå òåêñòóðû - GRAPH3D_MODE_T32 = 1<<15 // 32 áèòíûå òåêñòóðû + GRAPH3D_MODE_RGB16 = 1<<10, // 16 ������ ���� + GRAPH3D_MODE_RGB32 = 1<<11, // 32 ������ ���� + GRAPH3D_MODE_Z16 = 1<<12, // 16 ������ z-������ + GRAPH3D_MODE_Z32 = 1<<13, // 32 ������ z-������ + GRAPH3D_MODE_T16 = 1<<14, // 16 ������ �������� + GRAPH3D_MODE_T32 = 1<<15 // 32 ������ �������� }; enum eTextureFormat @@ -70,18 +74,18 @@ enum eMaterialMode MAT_ALPHA_MOD_TEXTURE1 = 1<<6, // alpha*=Texture1 MAT_ALPHA_MASK_TEXTURE1 = 1<<7, // alpha*=Texture1 MAT_COLOR_ADD_DIFFUSE = 1<<8, - // ñìåøàííûå ìàòåðèàëû Diffuse & Texture1 & Specular + // ��������� ��������� Diffuse & Texture1 & Specular MAT_COLOR_MOD_DIFFUSE_TEXTURE1 = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1, // color=Texture1*Diffuse MAT_COLOR_MOD_DIFFUSE_ADD_SPECULAR = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_ADD_SPECULAR, // color=Diffuse+Specular MAT_COLOR_MOD_DIFFUSE_TEXTURE1_ADD_SPECULAR = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1 | MAT_COLOR_ADD_SPECULAR, // color=Texture1*Diffuse+Specular - // ñìåøàííûå ìàòåðèàëû Diffuse & Texture1 & Alpha + // ��������� ��������� Diffuse & Texture1 & Alpha MAT_COLOR_MOD_DIFFUSE_ALPHA_MOD_DIFFUSE = MAT_COLOR_MOD_DIFFUSE | MAT_ALPHA_MOD_DIFFUSE, // color=Diffuse, a=aDiffuse, MAT_COLOR_MOD_DIFFUSE_TEXTURE1_ALPHA_MOD_DIFFUSE = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1 | MAT_ALPHA_MOD_DIFFUSE, // color=Texture1*Diffuse, a=aDiffuse, MAT_COLOR_MOD_DIFFUSE_TEXTURE1_ALPHA_MOD_TEXTURE1 = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1 | MAT_ALPHA_MOD_TEXTURE1, // color=Texture1*Diffuse, a=aTexture1, MAT_COLOR_MOD_DIFFUSE_TEXTURE1_ALPHA_MOD_DIFFUSE_TEXTURE1 = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1 | MAT_ALPHA_MOD_DIFFUSE | MAT_ALPHA_MOD_TEXTURE1, // color=Texture*Diffuse, a=aTexture*aDiffuse, MAT_COLOR_MOD_DIFFUSE_TEXTURE1_ALPHA_MASK_TEXTURE1 = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1 | MAT_ALPHA_MASK_TEXTURE1, // color=Texture1*Diffuse, a=aTexture1, MAT_COLOR_MOD_DIFFUSE_TEXTURE1_ALPHA_MOD_DIFFUSE_MASK_TEXTURE1 = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1 | MAT_ALPHA_MOD_DIFFUSE | MAT_ALPHA_MASK_TEXTURE1, // color=Texture*Diffuse, a=aTexture*aDiffuse, - // ñìåøàííûå ìàòåðèàëû Diffuse & Texture1 & Specular & Alpha + // ��������� ��������� Diffuse & Texture1 & Specular & Alpha MAT_COLOR_MOD_DIFFUSE_ADD_SPECULAR_ALPHA_MOD_DIFFUSE = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_ADD_SPECULAR | MAT_COLOR_ADD_SPECULAR | MAT_ALPHA_MOD_DIFFUSE, // color=Diffuse+Specular, a=aDiffuse, MAT_COLOR_MOD_DIFFUSE_TEXTURE1_ADD_SPECULAR_ALPHA_MOD_DIFFUSE = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1 | MAT_COLOR_ADD_SPECULAR | MAT_ALPHA_MOD_DIFFUSE, // color=Texture1*Diffuse+Specular, a=aDiffuse, MAT_COLOR_MOD_DIFFUSE_TEXTURE1_ADD_SPECULAR_ALPHA_MOD_TEXTURE1 = MAT_COLOR_MOD_DIFFUSE | MAT_COLOR_MOD_TEXTURE1 | MAT_COLOR_ADD_SPECULAR | MAT_ALPHA_MOD_TEXTURE1, // color=Texture1*Diffuse+Specular, a=aTexture1, @@ -113,7 +117,7 @@ enum eRenderStateOption RENDERSTATE_TEXTUREADDRESS = 18, RENDERSTATE_TEXTUREPOINT = 19, RENDERSTATE_TEXTURELINEAR = 20, -// âðåìåííî íå èñïîëüçóþòñÿ +// �������� �� ������������ RENDERSTATE_MIPMAP, }; @@ -152,7 +156,7 @@ enum eBlendMode }; struct sVertexFix -{ // äèôôóçíûé öâåò - drgba, ñïåêóëÿðíûé öâåò - srgba, 3 ïàðû òåêñòóðíûõ êîîðäèíàò - uv[3][2] +{ // ��������� ���� - drgba, ����������� ���� - srgba, 3 ���� ���������� ��������� - uv[3][2] float xe,ye,z,w; unsigned char drgba[4]; unsigned char srgba[4]; @@ -178,7 +182,7 @@ struct sVertexFix class Vect2f; class Vect3f; struct sVertexD3D -{ // äèôôóçíûé öâåò - drgba, ñïåêóëÿðíûé öâåò - srgba, 3 ïàðû òåêñòóðíûõ êîîðäèíàò - uv[3][2] +{ // ��������� ���� - drgba, ����������� ���� - srgba, 3 ���� ���������� ��������� - uv[3][2] float x,y,z; unsigned char drgba[4]; unsigned char srgba[4]; @@ -249,8 +253,8 @@ class cInterfaceGraph3d virtual int CreateTexture(int x,int y,eTextureFormat TextureFormat)=0; virtual int DeleteTexture(int hTexture)=0; - // íà÷àëî ïðî÷èå ôóíêöèè - // ñïðàéòû + // ������ ������ ������� + // ������� virtual int CreateSprite(DWORD dwWidth,DWORD dwHeight,DWORD dwFormat, DWORD dwFlags,DWORD* lpdwHandle )=0; virtual int CreateChildSprite(DWORD dwParentHandle,DWORD dwLeft,DWORD dwTop, @@ -286,9 +290,9 @@ class cInterfaceGraph3d virtual int SetViewColor(int r,int g,int b,int alfa)=0; virtual int GetWindowHandle( HWND *hWnd )=0; virtual int ScreenShot(VOID *lpBuffer,DWORD dwSize)=0; - // êîíåö ïðî÷èå ôóíêöèè + // ����� ������ ������� - // âñïîìîãàòåëüíûå ôóíêöèè, ìîãóò áûòü íå ðåàëèçîàâàíû + // ��������������� �������, ����� ���� �� ������������ virtual int GetSizeX() { return 0; } virtual int GetSizeY() { return 0; } virtual void* GetZBuffer() { return 0; } diff --git a/MechoSoma/VisGeneric/HashStringGroup.h b/MechoSoma/VisGeneric/HashStringGroup.h index f4943b29..2b4f92ea 100644 --- a/MechoSoma/VisGeneric/HashStringGroup.h +++ b/MechoSoma/VisGeneric/HashStringGroup.h @@ -6,16 +6,11 @@ #ifndef __HASH_STRING_GROUP__ #define __HASH_STRING_GROUP__ -#include "hash_map.h" +#include #include -struct eqstr -{ -bool operator()(const char* s1, const char* s2)const{ return !strcmp(s1, s2); } -}; - template -struct HashStringGroup : hash_map, eqstr> +struct HashStringGroup : std::unordered_map { void add(char* str, const T& data) { (*this)[str] = data; } @@ -31,8 +26,8 @@ struct HashStringGroup : hash_map, eqstr> break; } - iterator it = find(name); - return it == end() ? 0 : &(*it).second; + auto it = this->find(name); + return it == this->end() ? 0 : &(*it).second; } }; diff --git a/MechoSoma/VisGeneric/IncTerra.h b/MechoSoma/VisGeneric/IncTerra.h index 07a34c02..7521058c 100644 --- a/MechoSoma/VisGeneric/IncTerra.h +++ b/MechoSoma/VisGeneric/IncTerra.h @@ -4,7 +4,7 @@ #ifdef _USE_TERRA_ #include "BaseDefine.h" -#include "terra.h" +#include "TERRA.H" #define TERRA_XCYCL(a) XCYCL(a) #define TERRA_YCYCL(a) YCYCL(a) diff --git a/MechoSoma/VisGeneric/Levin.cpp b/MechoSoma/VisGeneric/Levin.cpp index f00c922a..4781fb33 100644 --- a/MechoSoma/VisGeneric/Levin.cpp +++ b/MechoSoma/VisGeneric/Levin.cpp @@ -1,5 +1,5 @@ #include "PolyMgr.h" -#include "camera.h" +#include "Camera.h" #include "Levin.h" #include "Unknown.h" #include "BaseDefine.h" @@ -8,7 +8,7 @@ #include "mch_common.h" // For far target #endif -inline float random() { return (((float)rand())/RAND_MAX); } +inline float random_f() { return (((float)rand())/RAND_MAX); } void cLevin::Draw(cUnknownClass *UCameraList,int var) { @@ -72,19 +72,19 @@ void cLevin::GenerationLevin1(const Vect3f &pos,const Vect3f &dpos,const Vect2f } } Vect3f posNew( - pos.x+step*dpos.x+(random()-0.5f)*pAberration.x, - pos.y+step*dpos.y+(random()-0.5f)*pAberration.y, - pos.z+step*dpos.z+(random()-0.5f)*pAberration.z); + pos.x+step*dpos.x+(random_f()-0.5f)*pAberration.x, + pos.y+step*dpos.y+(random_f()-0.5f)*pAberration.y, + pos.z+step*dpos.z+(random_f()-0.5f)*pAberration.z); - if(random()*level*step(pStop*level*step)) + if(random_f()>(pStop*level*step)) GenerationLevin1(posNew,dpos,width,level,count+=step); } void cLevin::GenerationLevin4(const Vect3f &pos,const Vect3f &dpos,const Vect2f &width,int length,int level,int count) @@ -110,19 +110,19 @@ void cLevin::GenerationLevin4(const Vect3f &pos,const Vect3f &dpos,const Vect2f } } Vect3f posNew( - pos.x+step*dpos.x+(random()-0.5f)*pAberration.x, - pos.y+step*dpos.y+(random()-0.5f)*pAberration.y, - pos.z+step*dpos.z+(random()-0.5f)*pAberration.z); + pos.x+step*dpos.x+(random_f()-0.5f)*pAberration.x, + pos.y+step*dpos.y+(random_f()-0.5f)*pAberration.y, + pos.z+step*dpos.z+(random_f()-0.5f)*pAberration.z); - if(random()*level*step(pStop*level*step))||((level==1)&&(count(pStop*level*step))||((level==1)&&(count #include "PolyMgr.h" sTexture::~sTexture() diff --git a/MechoSoma/VisGeneric/Material.h b/MechoSoma/VisGeneric/Material.h index 829c8833..23933989 100644 --- a/MechoSoma/VisGeneric/Material.h +++ b/MechoSoma/VisGeneric/Material.h @@ -5,7 +5,7 @@ #include "string.h" #include "BaseClass.h" #include "cString.h" -#include "umath.h" +#include "UMATH.H" enum eAttributeMaterial { diff --git a/MechoSoma/VisGeneric/Math3d.cpp b/MechoSoma/VisGeneric/Math3d.cpp index 49ad08c4..7e07469c 100644 --- a/MechoSoma/VisGeneric/Math3d.cpp +++ b/MechoSoma/VisGeneric/Math3d.cpp @@ -2,7 +2,7 @@ #include "Maths.h" #include "math.h" -inline void GetNormal(float *v1,float *v2,float *v3,float *Normal) +void GetNormal(float *v1,float *v2,float *v3,float *Normal) { float mx=v3[0]-v1[0], my=v3[1]-v1[1], mz=v3[2]-v1[2], nx=v2[0]-v1[0], ny=v2[1]-v1[1], nz=v2[2]-v1[2], diff --git a/MechoSoma/VisGeneric/Math3d.h b/MechoSoma/VisGeneric/Math3d.h index e93cf0f8..726934d1 100644 --- a/MechoSoma/VisGeneric/Math3d.h +++ b/MechoSoma/VisGeneric/Math3d.h @@ -1,9 +1,9 @@ #ifndef __MATH3D_H__ #define __MATH3D_H__ -#include "maths.h" -#include "umath.h" -#include "base.h" +#include "Maths.h" +#include "UMATH.H" +#include "Base.h" extern void GetNormal(float *v1,float *v2,float *v3,float *Normal); extern void NormalizeVector(int norma,int *x,int *y,int *z); @@ -40,7 +40,7 @@ class cMatrix : public MatXf rot()[0][2]=matrix[6]; rot()[1][2]=matrix[7]; rot()[2][2]=matrix[8]; trans().set(matrix[9],matrix[10],matrix[11]); } - inline operator MatXf&() { return *(MatXf*)this; } +// inline operator MatXf&() { return *(MatXf*)this; } }; #define PREC_EPSILON 0.00001f @@ -56,7 +56,7 @@ class cPlane ~cPlane() {} char CrossCut(float x1,float y1,float z1,float x2,float y2,float z2,float *x,float *y,float *z); char CrossPolygon(float xv1,float yv1,float zv1,float xv2,float yv2,float zv2,float *x,float *y,float *z); - // óãîë ìåæäó äâóìÿ ïëîñêîñòÿìè (â ãðàäóñàõ) + // ���� ����� ����� ����������� (� ��������) float AnglePlane(cPlane *Plane); inline float Norma() { float f=A*A+B*B+C*C; if(f>PREC_EPSILON) return sqrtf(f); return 0; } }; @@ -109,10 +109,10 @@ inline int ConvertorVector(int xw,int yw,int zw,int *xv,int *yv) return round(m8*xw+m9*yw+m10*zw); } inline void LoadMatrix(cMatrix *m,float sx,float sy,float sz) -{ // îñóùåñòâëÿåò ïåðåõîä èç ïðàâîé ñèñòåìû êîîðäèíàò â ëåâóþ +{ // ������������ ������� �� ������ ������� ��������� � ����� m0 =MATRIX_SIGN_X(sx*m->rot()[0][0]), m1 =MATRIX_SIGN_X(sy*m->rot()[0][1]), m2 =MATRIX_SIGN_X(sz*m->rot()[0][2]), dMx=MATRIX_SIGN_X(m->trans()[0]); m4 =MATRIX_SIGN_Y(sx*m->rot()[1][0]), m5 =MATRIX_SIGN_Y(sy*m->rot()[1][1]), m6 =MATRIX_SIGN_Y(sz*m->rot()[1][2]), dMy=MATRIX_SIGN_Y(m->trans()[1]); m8 =MATRIX_SIGN_Z(sx*m->rot()[2][0]), m9 =MATRIX_SIGN_Z(sy*m->rot()[2][1]), m10=MATRIX_SIGN_Z(sz*m->rot()[2][2]), dMz=MATRIX_SIGN_Z(m->trans()[2]); } -#endif __CONVERTOR3D_H__ \ No newline at end of file +#endif // __CONVERTOR3D_H__ \ No newline at end of file diff --git a/MechoSoma/VisGeneric/Maths.cpp b/MechoSoma/VisGeneric/Maths.cpp index 1a7c0f6a..3df146b9 100644 --- a/MechoSoma/VisGeneric/Maths.cpp +++ b/MechoSoma/VisGeneric/Maths.cpp @@ -1,7 +1,7 @@ -#include "maths.h" -#include "umath.h" -#include "math.h" -#include "stdlib.h" +#include "Maths.h" +#include "UMATH.H" +#include "Math.h" +#include #define SIZE_SHARE_FLOAT ((74*74*2)<<3) @@ -14,9 +14,9 @@ unsigned char *OmniLightMap=0; void InitArray() { - if(CosNChar==0) // òàáëèöà cos â ñòåïåíè COS_DEGREE òèïà char äëÿ èñòî÷íèêà ñâåòà cLight + if(CosNChar==0) // ������� cos � ������� COS_DEGREE ���� char ��� ��������� ����� cLight { - CosNChar=new unsigned char [128+3]; // 3 - ýòî èç-çà íåòî÷íîñòè â ðàñ÷åòàõ + CosNChar=new unsigned char [128+3]; // 3 - ��� ��-�� ���������� � �������� int j; for(j=0;j<(128+3);j++) { @@ -32,7 +32,7 @@ void InitArray() CosFloat[j]=cosf(j*GRAD_RAD/GRAD_TO_DGRAD(1)); } } - if(OmniLightMap==0) // ¤¢ã¬¥à­ ï äã­ªæ¨ï ã¡ë¢ ­¨ï ¨­â¥­á¨¢­®á⨠â®ç¥ç­®£® ¨áâ®ç­¨ª  cOmni + if(OmniLightMap==0) // ��㬥ୠ� �㭪�� �뢠��� ��⥭ᨢ���� ��筮�� ���筨�� cOmni { OmniLightMap=new unsigned char [1<>MAX_SIZE_NORMAL_BIT; } -inline void memfill(unsigned long *buf,int size,unsigned int fill) +inline void memfill(uint32_t *buf,int size,uint32_t fill) { - unsigned long *start=buf, *end=buf+size; + uint32_t *start=buf, *end=buf+size; while(startMesh->GetName()==Name) return start->Mesh; + if(start->Mesh->GetName()==static_cast(Name)) return start->Mesh; if((start->Mesh->Child)&&((tmp=start->Mesh->Child->FindMesh(Name))!=0)) return tmp; start=start->next; @@ -539,7 +546,7 @@ cMesh* cMesh::FindMesh(char *Name) { AssertValid(); if(Name[0]==0) return 0; - if(GetName()==Name) return this; + if(GetName()==static_cast(Name)) return this; if(Child) return Child->FindMesh(Name); return 0; } @@ -891,7 +898,7 @@ void cMesh::BuildShadeDynamic(short **shade,int *xShade,int *yShade,Vect3f &PosS #endif (*shade)=new short [(*xShade)*(*yShade)+1]; assert(shade); - memfill((unsigned long*)(*shade),((*xShade)*(*yShade)+1)>>1,0x80008000); + memfill((uint32_t*)(*shade),((*xShade)*(*yShade)+1)>>1,0x80008000); int nPointFix=0; DrawShadeDynamic((*shade),*xShade,*yShade,nPointFix); PosShade.set(Box.xmin()+*xShade,Box.ymin(),Box.zmax()); @@ -986,7 +993,7 @@ void cMesh::BuildShadeStatic(short **shade,int *xShade,int *yShade,Vect3f &PosSh #endif (*shade)=new short [(*xShade)*(*yShade)+1]; assert(shade); - memfill((unsigned long*)(*shade),((*xShade)*(*yShade)+1)>>1,0x80008000); + memfill((uint32_t*)(*shade),((*xShade)*(*yShade)+1)>>1,0x80008000); int nPointFix=0; DrawShadeStatic((*shade),*xShade,*yShade,nPointFix); /* if(strstr(fname,"ngine")!=0) @@ -1309,7 +1316,7 @@ void cMesh::SetArcane(void (*FunctionSetArcane)(mchArcaneData*)) inline sTile* GetTileByName(cTile *Tile,char *name) { for(int nTile=0;nTileGetNumberTile();nTile++) - if(Tile->GetTile(nTile)->GetName()==name) + if(Tile->GetTile(nTile)->GetName()==static_cast(name)) return Tile->GetTile(nTile); return 0; } @@ -1347,14 +1354,14 @@ void DrawLine1(char *buf,int xs,int ys,float x1,float y1,float x2,float y2) float d=dy/dx_; if(x1>x2) { x=x1; x1=x2; x2=x; y=y2; d=-d; } else y=y1; for(int x=round(x1);x=0)&&(x=0)&&(y=0)&&(x=0)&&(yy2) { x=y1; y1=y2; y2=x; y=x2; d=-d; } else y=x1; for(int x=round(y1);x=0)&&(x=0)&&(y=0)&&(x=0)&&(ymkf->key[i]->GetFileName()==Frame->mkf->key[j]->GetFileName()) + if(Frame->mkf->key[i]->GetFileName()==static_cast(Frame->mkf->key[j]->GetFileName())) FindCopy=1; if(!FindCopy) Frame->mkf->key[i]->WireScale(scale); diff --git a/MechoSoma/VisGeneric/Object3d.h b/MechoSoma/VisGeneric/Object3d.h index 0b2def83..919cd81c 100644 --- a/MechoSoma/VisGeneric/Object3d.h +++ b/MechoSoma/VisGeneric/Object3d.h @@ -3,7 +3,7 @@ #include "Math3d.h" #include "Object.h" -#include "base.h" +#include "Base.h" #include "BaseClass.h" #include "BoundingBox.h" #include "Material.h" @@ -248,7 +248,7 @@ class cTile : public cBaseDynArrayPointer __forceinline sTile* GetTileByName(char *name) { for(int i=0;iGetName()==name) + if(GetTile(i)->GetName()==static_cast(name)) return GetTile(i); return 0; } @@ -263,6 +263,8 @@ class cTile : public cBaseDynArrayPointer friend class cAnimChain; }; +class cMesh; + class cList { friend class cMesh; @@ -343,7 +345,7 @@ class cMesh : public cUnknownClass, public cBound void dSetScale(float dScale) { dSetScale(Vect3f(dScale,dScale,dScale)); } void dSetScale(const Vect3f &dScale) { Vect3f ds=dScale; if(ds.x<=0) ds.x=1e-10f; if(ds.y<=0) ds.y=1e-10f; if(ds.z<=0) ds.z=1e-10f; ScaleMesh(ds); } void SetScale(float Scale) { SetScale(Vect3f(Scale,Scale,Scale)); } - void SetScale(const Vect3f &scale) { Vect3f s=scale; if(s.x<=0) s.x=1e-10f; if(s.y<=0) s.y=1e-10f; if(s.z<=0) s.z=1e-10f; ScaleMesh(s/Scale); } + void SetScale(const Vect3f &scale) { Vect3f s=scale; if(s.x<=0) s.x=1e-10f; if(s.y<=0) s.y=1e-10f; if(s.z<=0) s.z=1e-10f; Vect3f t = s/Scale; ScaleMesh(t); } void SetPosition(const class MatXf &Matrix) { LocalMatrix=Matrix; CalcMatrix(); } void SetPosition(const class Mat3f& matrix3x3, const class Vect3f& vector3) { SetPosition(MatXf(matrix3x3, vector3)); } void SetOrientation(const class Mat3f& matrix3x3) { LocalMatrix.rot()=matrix3x3; CalcMatrix(); } @@ -396,7 +398,7 @@ class cMesh : public cUnknownClass, public cBound void GetTotalBound(int types,cMesh *center,sBox6f &box); void SetWireSize(const Vect3f &size); void SetDescription(char *string); - inline char* GetDescription() { if(description) return description; return ""; } + inline const char* GetDescription() { if(description) return description; return ""; } template void ScanHierarchy(Operation& op) // operator()(cMesh&) ������ ���������� 1 ��� ����������� ������������ diff --git a/MechoSoma/VisGeneric/PlayWSC.cpp b/MechoSoma/VisGeneric/PlayWSC.cpp index 24e83b17..e683b0b2 100644 --- a/MechoSoma/VisGeneric/PlayWSC.cpp +++ b/MechoSoma/VisGeneric/PlayWSC.cpp @@ -6,19 +6,19 @@ #include "IGraph3d.h" #include "CameraDispatcher.h" #include "AnimChannelNode.h" -#include "maths.h" +#include "Maths.h" #include "sound.h" #include "sound_api.h" #include "PolyMgr.h" #include "RenderDevice.h" #include "VisGeneric.h" -// äëÿ ðàáîòû ñî ñêðèïòàìè +// ��� ������ �� ��������� #include "WorldScript.h" #include "BaseDefine.h" #include "aci_parser.h" -extern void fxlabMovieUpdateProcess(const char* name,Vect3f& position,Vect3f& velocity,int status); +extern void fxlabMovieUpdateProcess(const char* name,const Vect3f& position,const Vect3f& velocity,int status); extern void fxlabMovieDestroy(void); cWorldScriptPlay TestWorldScriptPlay; @@ -53,7 +53,7 @@ class cElementWorldScript : public sAttribute }; class cConnectBaseWSC : public cElementWorldScript, public cAnimChainNode -{ // ñîííåêò áàçîâûé äëÿ îáúåêòîâ è ñïåöýôôåêòîâ +{ // ������� ������� ��� �������� � ������������ public: cConnectBaseWSC() {} virtual ~cConnectBaseWSC() { cAnimChainNode::Release(); } @@ -209,9 +209,9 @@ class cTextWSC : public cElementWorldScript } } inline void SetText(char *pText) { Text=pText; } - inline void SetPos(Vect2f &ScrPos) { Pos=ScrPos; } + inline void SetPos(const Vect2f &ScrPos) { Pos=ScrPos; } inline void SetNumberFont(int NumberFont) { nFont=NumberFont; } - inline void SetFontSize(Vect2f &fSize) { FontSize=fSize; } + inline void SetFontSize(const Vect2f &fSize) { FontSize=fSize; } inline void SetCentered(int n) { centered=n; } inline sColor4f& GetColor() { return Color; } }; @@ -253,7 +253,7 @@ class cSoundWSC : public cElementWorldScript return 1; } inline void SetSound(int SoundID) { Sound=SoundID; } - inline void SetPos(Vect2f &WorldPos) { Pos=WorldPos; } + inline void SetPos(const Vect2f &WorldPos) { Pos=WorldPos; } inline void SetParent(cElementWorldScript *ParentWS) { Parent=ParentWS; } }; class cLighingWSC : public cElementWorldScript @@ -323,12 +323,12 @@ void cWorldScriptPlay::Free() fxlabMovieDestroy(); MusicTrack=0; } -int cWorldScriptPlay::OpenWorldScript(char *fname) +int cWorldScriptPlay::OpenWorldScript(const std::filesystem::path &path) { if(IVisGeneric==0) return 1; if(root) delete root; - root=loadScript(fname); - // èäåíòèôèêàöèÿ íà÷àëüíûõ äàííûõ + root=loadScript(path); + // ������������� ��������� ������ scrDataBlock *p,*p1; p=root->find(WORLDSCRIPT_DEFOBJECT3D_PATH); if(p) DefaultPathObject3d=(char*)p->c_dataPtr; @@ -341,7 +341,7 @@ int cWorldScriptPlay::OpenWorldScript(char *fname) if((!DefaultPathObject3d)||(!DefaultPathTexture)) return 1; p=root->nextLevel->first(); - // êýøèðîâàíèå ñöåíû + // ����������� ����� CurrentPathObject3d=DefaultPathObject3d; while(p) { @@ -377,7 +377,7 @@ int cWorldScriptPlay::OpenWorldScript(char *fname) } current=root->nextLevel->first(); mch_sndD->Free(1); - if(SoundScriptName) mch_sndD->Load(SoundScriptName,1); // çàãðóçèòü ñêðèïò, ìèðîâûå çâóêè ïðè ýòîì ñàìè âûãðóçÿòñÿ + if(SoundScriptName) mch_sndD->Load(SoundScriptName,1); // ��������� ������, ������� ����� ��� ���� ���� ���������� return 0; } void cWorldScriptPlay::CloseWorldScript() @@ -394,7 +394,7 @@ void cWorldScriptPlay::CloseWorldScript() sndMusicStop(); sndMusicSetVolume(mchMusicVolume); } - mchLoadWorldSound(); // ïîñëå ðîëèêà çàãðóçèòü íà ìåñòî ìèðîâûå çâóêè/âûãðóçèòü ñêðèïò îò ðîëèêà + mchLoadWorldSound(); // ����� ������ ��������� �� ����� ������� �����/��������� ������ �� ������ } int cWorldScriptPlay::LoadNextWorldScript() { @@ -605,10 +605,10 @@ int cWorldScriptPlay::LoadWSC(void *buffer,int length) strcpy(ConnectName,buf); while(InWSC.eof()==0&&buf[0]!='{') InWSC>>buf; while(InWSC.eof()==0&&buf[0]!='}') - { // ÷òåíèå connect'à + { // ������ connect'� InWSC>>buf; while(InWSC.eof()==0&&buf[0]!='$'&&buf[0]!='}') - InWSC>>buf; // ïðîïóñêàåò ëèøíåå + InWSC>>buf; // ���������� ������ if(stricmp(buf,WSC_CONNECT_POSITION)==0) { sKey3f &key=Connect->GetNewPos(); @@ -674,10 +674,10 @@ int cWorldScriptPlay::LoadWSC(void *buffer,int length) InWSC>>buf; Orientation->SetName(buf); while(InWSC.eof()==0&&buf[0]!='}') - { // ÷òåíèå orientation'à + { // ������ orientation'� InWSC>>buf; while(InWSC.eof()==0&&buf[0]!='$'&&buf[0]!='}') - InWSC>>buf; // ïðîïóñêàåò ëèøíåå + InWSC>>buf; // ���������� ������ if(stricmp(buf,WSC_CONNECT_POSITION)==0) { sKey3f &key=Orientation->GetNewPos(); diff --git a/MechoSoma/VisGeneric/PlayWSC.h b/MechoSoma/VisGeneric/PlayWSC.h index b435b0d5..01b4a2ea 100644 --- a/MechoSoma/VisGeneric/PlayWSC.h +++ b/MechoSoma/VisGeneric/PlayWSC.h @@ -1,10 +1,12 @@ #ifndef __PLAYWSC_H__ #define __PLAYWSC_H__ -#include "unknown.h" +#include + +#include "Unknown.h" #include "cString.h" #include "BaseClass.h" -#include "umath.h" +#include "UMATH.H" enum eAttributeConnectWSC { @@ -32,7 +34,7 @@ class cWorldScriptPlay cWorldScriptPlay(); ~cWorldScriptPlay(); void Free(); - int OpenWorldScript(char *fname); + int OpenWorldScript(const std::filesystem::path &path); int LoadNextWorldScript(); void CloseWorldScript(); void Animate(); diff --git a/MechoSoma/VisGeneric/PluginMAX/inc/meshfile.h b/MechoSoma/VisGeneric/PluginMAX/inc/meshfile.h index db95f37c..f64730c2 100644 --- a/MechoSoma/VisGeneric/PluginMAX/inc/meshfile.h +++ b/MechoSoma/VisGeneric/PluginMAX/inc/meshfile.h @@ -30,7 +30,7 @@ class cMeshFile void *f; char type; int error; - int ofs; // ñìåùåíèå â òåêñòîâîì ôîðìàòå + int ofs; // �������� � ��������� ������� cMeshFile(); ~cMeshFile(); @@ -80,8 +80,8 @@ class cBaseFileMeshArray: public cBaseDynArray { public: cBaseFileMeshArray() { } - ~cBaseFileMeshArray() { Release(); } - void Release() { Delete(); } + ~cBaseFileMeshArray() { this->Release(); } + void Release() { this->Delete(); } void New(int NewSize) { cBaseDynArray::New(NewSize); } int Read(cMeshFile &f) { @@ -94,8 +94,8 @@ class cBaseFileMeshArray: public cBaseDynArray New(NewSize); break; case MF_TYPE_BASEMESH: - assert(CurrentSizelength()); + f.ReadField(&this->Base[CurrentSize++]); break; case MF_TYPE_BLOCK: switch(f.ReadBlock()) @@ -109,10 +109,10 @@ class cBaseFileMeshArray: public cBaseDynArray } int Write(cMeshFile &f) { - if(length()<=0) return MESHFILE_OK; + if(this->length()<=0) return MESHFILE_OK; f.BeginWriteBlock(MF_ID_BLOCK_BASEMESH); - f.WriteField(&length(),MF_TYPE_NUMBER); - for(cBase *b=Base,*e=&Base[length()];blength(),MF_TYPE_NUMBER); + for(cBase *b=this->Base,*e=&this->Base[this->length()];b { public: cBaseMeshPointerLibrary() { } - ~cBaseMeshPointerLibrary() { Release(); } - void Release() { Delete(); } + ~cBaseMeshPointerLibrary() { this->Release(); } + void Release() { this->Delete(); } cBaseMesh* New(cBaseMesh *BaseMesh) { if(BaseMesh==0) BaseMesh=new cBaseMesh; - else for(int i=0;iRelease(); return BaseMesh; } - Resize(length()+1); - Base[length()-1]=BaseMesh; - BaseMesh->ID=length()-1; + else for(int i=0;ilength();i++) if(BaseMesh==this->Base[i]) { BaseMesh->Release(); return BaseMesh; } + this->Resize(this->length()+1); + this->Base[this->length()-1]=BaseMesh; + BaseMesh->ID=this->length()-1; return BaseMesh; } cBaseMesh* Get(unsigned int ID) { - for(int i=0;iID==ID) - return Base[i]; + for(int i=0;ilength();i++) + if(this->Base[i]->ID==ID) + return this->Base[i]; return 0; } cBaseMesh* Get(void *Key) { - for(int i=0;icmp(Key)==0) - return Base[i]; + for(int i=0;ilength();i++) + if(this->Base[i]->cmp(Key)==0) + return this->Base[i]; return 0; } inline cBaseMesh* Append() @@ -155,8 +155,8 @@ class cBaseMeshPointerLibrary: public cBaseDynArrayPointer } int Write(cMeshFile &f) { - for(int i=0;iWrite(f)!=MESHFILE_OK) return MESHFILE_ERROR; + for(int i=0;ilength();i++) + if(this->Base[i]->Write(f)!=MESHFILE_OK) return MESHFILE_ERROR; return MESHFILE_OK; } inline cBaseMeshPointerLibrary& operator = (const cBaseMeshPointerLibrary &Array) diff --git a/MechoSoma/VisGeneric/PluginMAX/src/AnimationMaterial.cpp b/MechoSoma/VisGeneric/PluginMAX/src/AnimationMaterial.cpp index c388f863..53f084de 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/AnimationMaterial.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/AnimationMaterial.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int sSubTexmap::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/AnimationMesh.cpp b/MechoSoma/VisGeneric/PluginMAX/src/AnimationMesh.cpp index d387dbea..21bb6452 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/AnimationMesh.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/AnimationMesh.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int sAnimationMesh::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/ChannelAnimation.cpp b/MechoSoma/VisGeneric/PluginMAX/src/ChannelAnimation.cpp index b1c6ccb8..742ccd4d 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/ChannelAnimation.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/ChannelAnimation.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int sChannelAnimation::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/ChannelMapping.cpp b/MechoSoma/VisGeneric/PluginMAX/src/ChannelMapping.cpp index 0e91c122..6ac9b3ac 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/ChannelMapping.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/ChannelMapping.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int sChannelMapping::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/HelperObject.cpp b/MechoSoma/VisGeneric/PluginMAX/src/HelperObject.cpp index d9176e78..1c395234 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/HelperObject.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/HelperObject.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int sHelperObject::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/LodObject.cpp b/MechoSoma/VisGeneric/PluginMAX/src/LodObject.cpp index b8ccbc01..44053a98 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/LodObject.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/LodObject.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int sLodObject::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/MaterialObject.cpp b/MechoSoma/VisGeneric/PluginMAX/src/MaterialObject.cpp index f6511126..1aeb86f5 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/MaterialObject.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/MaterialObject.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int sMaterialObject::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/NodeObject.cpp b/MechoSoma/VisGeneric/PluginMAX/src/NodeObject.cpp index e588c2a4..19e31d37 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/NodeObject.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/NodeObject.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" void sNodeObject::Release() { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/ObjectMesh.cpp b/MechoSoma/VisGeneric/PluginMAX/src/ObjectMesh.cpp index b8584df4..42fd9ba5 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/ObjectMesh.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/ObjectMesh.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int sObjectMesh::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/SceneMesh.cpp b/MechoSoma/VisGeneric/PluginMAX/src/SceneMesh.cpp index b0e27ae4..78bb3ca0 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/SceneMesh.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/SceneMesh.cpp @@ -1,4 +1,4 @@ -#include "SceneMesh.h" +#include "scenemesh.h" int cMeshScene::Read(cMeshFile &f) { diff --git a/MechoSoma/VisGeneric/PluginMAX/src/StreamBuffer.cpp b/MechoSoma/VisGeneric/PluginMAX/src/StreamBuffer.cpp index 02d0d4e2..3ae6096f 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/StreamBuffer.cpp +++ b/MechoSoma/VisGeneric/PluginMAX/src/StreamBuffer.cpp @@ -8,6 +8,8 @@ #include #include "StreamBuffer.h" +#include "port.h" + #define STREAM_BUFFER_RESIZE 1024 inline double StringToFloat(char *buf) @@ -18,16 +20,16 @@ inline double StringToFloat(char *buf) int i; for(i=0;buf[i]!='+'&&buf[i]!='-'&&buf[i]<'0'&&buf[i]>'9';i++) if(buf[i]) return a; - // âû÷èñëåíå öåëîé ÷àñòè + // ��������� ����� ����� if(buf[i]=='-') { f_sign=-1; i++; } else { if(buf[i]=='+') i++; f_sign=1; } for(;buf[i]&&'0'<=buf[i]&&buf[i]<='9';i++) f_int=(f_int*10)+(buf[i]-'0'); if(buf[i]==0) { - assert(_finite(a)); + assert(isfinite(a)); return a=f_sign*f_int; } - // âû÷èñëåíå äðîáíîé ÷àñòè + // ��������� ������� ����� if(buf[i]=='.'||buf[i]==',') { i++; @@ -36,17 +38,17 @@ inline double StringToFloat(char *buf) } if(buf[i]==0) { - assert(_finite(a)); + assert(isfinite(a)); return a=f_sign*(f_int+f_fract); } - // âû÷èñëåíèå ñòåïåíè ÷èñëà + // ���������� ������� ����� if(buf[i]=='e') { i++; double f_sign_power; if(buf[i]==0) { - assert(_finite(a)); + assert(isfinite(a)); return a=f_sign*(f_int+f_fract); } if(buf[i]=='-') { f_sign_power=-1; i++; } else { if(buf[i]=='+') i++; f_sign_power=1; } @@ -54,7 +56,7 @@ inline double StringToFloat(char *buf) f_power=(f_power*10)+(buf[i]-'0'); f_power=pow(10,f_power*f_sign_power); } - assert(_finite(a)); + assert(isfinite(a)); return a=f_sign*(f_int+f_fract)*f_power; } @@ -162,6 +164,11 @@ int cStream::write(void *buf,int size) } return size; } +int cStream::write(const char *buf,int size) +{ + // TODO rough casting + return write((void *)buf, size); +} int cStream::read(void *buf,int size) { int d=size-(CurrentSize-CurrentPos); @@ -205,7 +212,7 @@ cStream& cStream::operator << (char a) { assert(lpBuffer); char buf[256]; - char *ch=ltoa(a,buf,10); + char *ch=port_ltoa(a,buf,10); write(&ch,strlen(ch)); return *this; } @@ -213,7 +220,7 @@ cStream& cStream::operator << (unsigned char a) { assert(lpBuffer); char buf[256]; - char *ch=ultoa(a,buf,10); + char *ch=port_ultoa(a,buf,10); write(ch,strlen(ch)); return *this; } @@ -221,7 +228,7 @@ cStream& cStream::operator << (short a) { assert(lpBuffer); char buf[256]; - char *ch=ltoa(a,buf,10); + char *ch=port_ltoa(a,buf,10); write(ch,strlen(ch)); return *this; } @@ -229,7 +236,7 @@ cStream& cStream::operator << (unsigned short a) { assert(lpBuffer); char buf[256]; - char *ch=ultoa(a,buf,10); + char *ch=port_ultoa(a,buf,10); write(ch,strlen(ch)); return *this; } @@ -237,7 +244,7 @@ cStream& cStream::operator << (int a) { assert(lpBuffer); char buf[256]; - char *ch=ltoa(a,buf,10); + char *ch=port_ltoa(a,buf,10); write(ch,strlen(ch)); return *this; } @@ -245,7 +252,7 @@ cStream& cStream::operator << (unsigned int a) { assert(lpBuffer); char buf[256]; - char *ch=ultoa(a,buf,10); + char *ch=port_ultoa(a,buf,10); write(ch,strlen(ch)); return *this; } @@ -253,7 +260,7 @@ cStream& cStream::operator << (long a) { assert(lpBuffer); char buf[256]; - char *ch=ltoa(a,buf,10); + char *ch=port_ltoa(a,buf,10); write(ch,strlen(ch)); return *this; } @@ -261,7 +268,7 @@ cStream& cStream::operator << (unsigned long a) { assert(lpBuffer); char buf[256]; - char *ch=ultoa(a,buf,10); + char *ch=port_ultoa(a,buf,10); write(ch,strlen(ch)); return *this; } @@ -289,7 +296,7 @@ cStream& cStream::operator << (long double a) write(buf,strlen(buf)); return *this; } -cStream& cStream::operator << (char *a) +cStream& cStream::operator << (const char *a) { assert(lpBuffer); write(a,strlen(a)); diff --git a/MechoSoma/VisGeneric/PluginMAX/src/StreamBuffer.h b/MechoSoma/VisGeneric/PluginMAX/src/StreamBuffer.h index 54fcbf4a..48307254 100644 --- a/MechoSoma/VisGeneric/PluginMAX/src/StreamBuffer.h +++ b/MechoSoma/VisGeneric/PluginMAX/src/StreamBuffer.h @@ -33,6 +33,7 @@ class cStream int eof(); int read(void *buf,int size); int write(void *buf,int size); + int write(const char *buf,int size); int length(); int tell(); void seek(int pos); @@ -52,7 +53,7 @@ class cStream cStream& operator << (float a); cStream& operator << (double a); cStream& operator << (long double a); - cStream& operator << (char *a); + cStream& operator << (const char *a); cStream& operator >> (char &a); cStream& operator >> (unsigned char &a); diff --git a/MechoSoma/VisGeneric/PolyGrid.cpp b/MechoSoma/VisGeneric/PolyGrid.cpp index e4516383..cc8e3d98 100644 --- a/MechoSoma/VisGeneric/PolyGrid.cpp +++ b/MechoSoma/VisGeneric/PolyGrid.cpp @@ -1,6 +1,8 @@ #include "float.h" #include "PolyGrid.h" +#ifdef _WIN32 #include "SoftWare16.h" +#endif cPolyGrid::cPolyGrid() { diff --git a/MechoSoma/VisGeneric/PolyGrid.h b/MechoSoma/VisGeneric/PolyGrid.h index 8ca474f3..531cf489 100644 --- a/MechoSoma/VisGeneric/PolyGrid.h +++ b/MechoSoma/VisGeneric/PolyGrid.h @@ -1,8 +1,8 @@ #ifndef __POLYGRID_H__ #define __POLYGRID_H__ -#include "camera.h" -#include "material.h" +#include "Camera.h" +#include "Material.h" #define POLYGRID_NOT_USE (0<<0) #define POLYGRID_USE (1<<0) diff --git a/MechoSoma/VisGeneric/PolyMgr.cpp b/MechoSoma/VisGeneric/PolyMgr.cpp index fa7cfae0..24d22732 100644 --- a/MechoSoma/VisGeneric/PolyMgr.cpp +++ b/MechoSoma/VisGeneric/PolyMgr.cpp @@ -1,6 +1,8 @@ #include "PolyMgr.h" +#ifdef _WIN32 #include "Software16.h" -#include "object3d.h" +#endif +#include "Object3d.h" #include "RenderDevice.h" //#define SIGN(a) ((a)<0? -1: 1) diff --git a/MechoSoma/VisGeneric/PolyMgr.h b/MechoSoma/VisGeneric/PolyMgr.h index 476d42cb..311abad0 100644 --- a/MechoSoma/VisGeneric/PolyMgr.h +++ b/MechoSoma/VisGeneric/PolyMgr.h @@ -4,9 +4,13 @@ #include "BaseClass.h" #include "UnkLibrary.h" #include "IGraph3d.h" -#include "umath.h" +#include "UMATH.H" #include "DrawPolygonShade.h" +#ifndef _WIN32 +#define __forceinline inline +#endif + #define POINT_SCALE_W 0.9f #define GET_FRUSTUM_CLIP(a) ((a)&(CLIP_XMIN|CLIP_XMAX|CLIP_YMIN|CLIP_YMAX|CLIP_ZMIN|CLIP_ZMAX)) @@ -91,16 +95,16 @@ struct sSpriteFX unsigned char rD,gD,bD,aD; Vect2f a,b; sSpriteFX() { rD=gD=bD=aD=255; a.set(0,0); b.set(0,0); } - void Init(sColor4f &diffuse,float angle,float scale) { a.set(scale*cosf(angle+0.7854f),scale*sinf(angle+0.7854f)); b.set(scale*cosf(angle+2.3562f),scale*sinf(angle+2.3562f)); rD=diffuse.GetR(); gD=diffuse.GetG(); bD=diffuse.GetB(); aD=diffuse.GetA(); } + void Init(const sColor4f &diffuse,float angle,float scale) { a.set(scale*cosf(angle+0.7854f),scale*sinf(angle+0.7854f)); b.set(scale*cosf(angle+2.3562f),scale*sinf(angle+2.3562f)); rD=diffuse.GetR(); gD=diffuse.GetG(); bD=diffuse.GetB(); aD=diffuse.GetA(); } }; struct sPointAttribute { - Vect3f pv; // êîîðäèíàòû â ïðîñòðàñòâå êàìåðû - unsigned char clip; // ôëàãè êëèïïèðîâàíèÿ - unsigned int edge; // óêàçûâàåò íà äâå âåðøèíû ïîðîäèâøèõ ïðè êëèïîâêå äàííóþ + Vect3f pv; // ���������� � ����������� ������ + unsigned char clip; // ����� ������������� + unsigned int edge; // ��������� �� ��� ������� ���������� ��� �������� ������ inline void Set(float fxv,float fyv,float fzv) { pv.x=fxv; pv.y=fyv; pv.z=fzv; } - inline void Set(sPointAttribute &pa1,sPointAttribute &pa2,float t) { pv.x=pa1.pv.x+(pa2.pv.x-pa1.pv.x)*t; pv.y=pa1.pv.y+(pa2.pv.y-pa1.pv.y)*t; pv.z=pa1.pv.z+(pa2.pv.z-pa1.pv.z)*t; }; + inline void Set(const sPointAttribute &pa1,const sPointAttribute &pa2,float t) { pv.x=pa1.pv.x+(pa2.pv.x-pa1.pv.x)*t; pv.y=pa1.pv.y+(pa2.pv.y-pa1.pv.y)*t; pv.z=pa1.pv.z+(pa2.pv.z-pa1.pv.z)*t; }; }; class cPolyDispatcher : public sTracePolygon @@ -138,7 +142,7 @@ class cPolyDispatcher : public sTracePolygon // Fix-format function void InitFix(int attribute,int NumberPoint=0); - __forceinline void AddPolygonFixTestPointFix(int i1,int i2,int i3);// äîáàâëåíèå â êîíåöïîëèãîíà ïîñëå òåñòà + __forceinline void AddPolygonFixTestPointFix(int i1,int i2,int i3);// ���������� � ������������� ����� ����� __forceinline void SetPointFix(int i,const Vect2f &tex); __forceinline void SetPointFix(int i,int dr,int dg,int db,int da); __forceinline void SetPointFix(int i,int dr,int dg,int db,int da,const Vect2f &tex); @@ -153,7 +157,7 @@ class cPolyDispatcher : public sTracePolygon __forceinline void SetPointFix(int i,const Vect3f &pe,int dr,int dg,int db,int da,const Vect2f &tex,const Vect3f &pv); __forceinline void SetPointFix(int i,const Vect3f &pe,int dr,int dg,int db,int da,int sr,int sg,int sb,int sa,const Vect3f &pv); __forceinline void SetPointFix(int i,const Vect3f &pe,int dr,int dg,int db,int da,int sr,int sg,int sb,int sa,const Vect2f &tex,const Vect3f &pv); - // ôóíêöèè ðàñòåðèçàöèè + // ������� ������������ void Draw(cUnknownClass *UCameraList,cOmni *Omni); void Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMesh *Mesh,Vect3f *vReflection=0); @@ -176,11 +180,11 @@ class cPolyDispatcher : public sTracePolygon void Draw(cUnknownClass *UCameraList,cTangentTrail *TangentTrail); - void SetViewColor(cUnknownClass *UCamera,sColor4f &Diffuse,sColor4f &Specular,int zWrite=0); - void BeginList(cUnknownClass *UCamera,int idTextureChild,MatXf &Matrix); // äëÿ òðåõìåðíûõ ýôôåêòîâ + void SetViewColor(cUnknownClass *UCamera,const sColor4f &Diffuse,const sColor4f &Specular,int zWrite=0); + void BeginList(cUnknownClass *UCamera,int idTextureChild,MatXf &Matrix); // ��� ���������� �������� void AttachCenter(const Vect3f &pos,float angle,float scale,int rgbaDiffuse,int idTextureChild); void AttachCenter(const Vect3f &pos,sSpriteFX *SpriteFX,int idTextureChild); - void BeginList(cUnknownClass *UCamera,int idTextureChild); // äëÿ ïëîñêèõ ýôôåêòîâ + void BeginList(cUnknownClass *UCamera,int idTextureChild); // ��� ������� �������� void AttachCenter(const Vect2f &pos,sSpriteFX *SpriteFX,int idTextureChild); void BeginListShare(cUnknownClass *UCamera,int idTextureChild,MatXf &Matrix); void AttachCenterShare(const Vect3f &pos,sSpriteFX *SpriteFX,int idTextureChild); @@ -189,10 +193,10 @@ class cPolyDispatcher : public sTracePolygon private: inline int AssertValid(); // PolygonFix - inline int AddPolygonFix(int p1,int p2,int p3); // äîáàâëåíèå â êîíåö - inline void DelPolygonFix(int i); // óäàëåíèå ïîëèãîíà èç ïîçèöèè - inline void MovPolygonFix(int i); // ïåðåìåùåíèå èç ïîëîæåíèÿ i â êîíåö - inline void SetPolygonFix(int i,int p1,int p2,int p3); // óñòàíîâêà çíà÷åíèé ïîëèãîíà + inline int AddPolygonFix(int p1,int p2,int p3); // ���������� � ����� + inline void DelPolygonFix(int i); // �������� �������� �� ������� + inline void MovPolygonFix(int i); // ����������� �� ��������� i � ����� + inline void SetPolygonFix(int i,int p1,int p2,int p3); // ��������� �������� �������� inline sVertexFix& NextPointFix() { return PointFix[PointFix.CurrentSize++]; } inline sPolygonFix& NextPolygonFix() { return PolygonFix[PolygonFix.CurrentSize++]; } @@ -231,7 +235,7 @@ extern cPolyDispatcher *P3D; } __forceinline void cPolyDispatcher::AddPolygonFixTestPointFix(int i1,int i2,int i3) -{ // äîáàâëåíèå â êîíåö ïîëèãîíà ïîñëå òåñòà +{ // ���������� � ����� �������� ����� ����� assert((i1GetViewPort(); cInterfaceGraph3d *Graph3d=RenderDevice->GetIGraph3d(); SetClippingPlane(Camera); - // ïîäãîòîâêà ê ðàñ÷åòó êîîðäèíàò îáúåêòà + // ���������� � ������� ��������� ������� cConvertor ConvertorObjectToScreen; Omni->BuildDrawMatrix(Camera,ConvertorObjectToScreen.GetMatrix(),Camera->GetAttribute(ATTRIBUTE_CAMERA_PERSPECTIVE_WORLD_SHARE)==ATTRIBUTE_CAMERA_PERSPECTIVE_WORLD_SHARE); ConvertorObjectToScreen.BuildMatrix(); @@ -204,11 +208,11 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes assert(UCameraList->GetKind(KIND_ARRAYCAMERA)); cUnkClassDynArrayPointer &CameraArray=*(cUnkClassDynArrayPointer*)UCameraList; - // ðàñ÷åò îñâåùåííîñòè îáúåêòà + // ������ ������������ ������� sColor4s AmbientMesh,MulMesh,AddMesh,MetalColor(255,255,255,255); int RenderDiffuse; if(GET_RENDER_TUNING(RENDER_TUNING_DYNAMIC_LIGHTING)&&(Mesh->GetAttribute(MESH_NOT_LIGHTING)==0)) - { // ðàñ÷åò îñâåùåííîñòè äëÿ îáúåêòà ïî èñòî÷íèêàì ñâåòà ñöåíû + { // ������ ������������ ��� ������� �� ���������� ����� ����� sColor4f Ambient,Diffuse,Illumination=Mesh->GetSpecular(); if(IS_STATIC(Mesh->Type)) Ambient.set(0,0,0,1),Diffuse.set(0,0,0,1); else Ambient=LightObject->GetAmbient(),Diffuse=LightObject->GetDiffuse(); @@ -230,13 +234,13 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes RenderDiffuse=1; } else - { // íà îáúåêò íå äåéñòâóþò èñòî÷íèêè ñâåòà, íå ïðîèñõîäèò ðåíäåð îñâåùåíèÿ + { // �� ������ �� ��������� ��������� �����, �� ���������� ������ ��������� AmbientMesh.set(0,0,0,255); MulMesh.set(Mesh->GetDiffuse().GetR(),Mesh->GetDiffuse().GetG(),Mesh->GetDiffuse().GetB(),Mesh->GetDiffuse().GetA()); AddMesh.set(Mesh->GetSpecular().GetR(),Mesh->GetSpecular().GetG(),Mesh->GetSpecular().GetB(),255); RenderDiffuse=0; } - // ïîäãîòîâêà ê ðàñ÷åòó îñâåùåííîñòè îáúåêòà + // ���������� � ������� ������������ ������� cConvertor ConvertorObjectToWorld; ConvertorObjectToWorld.GetMatrix()=Mesh->GlobalMatrix; // ConvertorObjectToWorld.BuildMatrix(); @@ -257,7 +261,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes SetClippingPlane(Camera); sColor4s MetalTile=MetalColor; - // ïîäãîòîâêà ê ðàñ÷åòó îñâåùåííîñòè îáúåêòà - ðàñ÷åò íàïðàâëåíèÿ êàìåðû + // ���������� � ������� ������������ ������� - ������ ����������� ������ int Alpha=MulMesh.a; if(Camera->GetAttribute(ATTRIBUTE_CAMERA_WORLD_SHARE)) { @@ -285,7 +289,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes ConvertorObjectToWorld.InverseConvertVector(dPos,vView); vView.normalize(1.f); float cosLightView=dot(vLight,vView); - // ïîäãîòîâêà ê ðàñ÷åòó êîîðäèíàò îáúåêòà + // ���������� � ������� ��������� ������� cConvertor ConvertorObjectToScreen; if(vReflection==0) ConvertorObjectToScreen.GetMatrix()=Camera->GetMatrix()*Mesh->BuildDrawMatrix(Camera,ConvertorObjectToScreen.GetMatrix()); @@ -320,13 +324,13 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes ConvertorObjectToScreen.SetProjection(Camera,Camera->GetAttribute(ATTRIBUTE_CAMERA_PERSPECTIVE)); if(Mesh->GetAttribute(MESH_NOT_WRITEZBUFFER)) Graph3d->SetRenderState(RENDERSTATE_ZWRITE,FALSE); - // ñîáñòâåííî ðàñ÷åò êîîðäèíàò è îñâåùåííîñòè + // ���������� ������ ��������� � ������������ for(int i=0;iGetNumberTile();i++) { sTile *tile=Mesh->GetTile(i); sPoint *Point=tile->GetPoint(); sPolygon *Polygon=tile->GetPolygon(); - Vect3f pv,pe; // pv.z-z-êîîðäèíàòà ðàññòîÿíèÿ äî õàðàêòåðíîé òî÷êè îáúåêòà + Vect3f pv,pe; // pv.z-z-���������� ���������� �� ����������� ����� ������� // float zDistance=ConvertorObjectToScreen.Matrix[6]*Point->pos.x+ConvertorObjectToScreen.Matrix[7]*Point->pos.y+ConvertorObjectToScreen.Matrix[8]*Point->pos.z+ConvertorObjectToScreen.Matrix[11]; ConvertorObjectToScreen.ConvertPoint(Point->pos,pv,pe); float fLOD=Mesh->Scale.x*tile->size/pv.z; @@ -335,7 +339,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes if(tile->GetAttribute(ATTRMAT_TEXTURE_PAL)) { if(tile->Texture->nTexture==0) CreateTexture((cMaterial*)tile,RenderDevice); - Graph3d->SetTexture(tile->Texture->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(tile->Texture->nTexture); // ��������� �������� } sColor4s MulTile(round(tile->MulCol.r*MulMesh.r),round(tile->MulCol.g*MulMesh.g), round(tile->MulCol.b*MulMesh.b),round(Alpha*tile->MulCol.a)), @@ -343,7 +347,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes if(AddTile.r>255) AddTile.r=255; if(AddTile.g>255) AddTile.g=255; if(AddTile.b>255) AddTile.b=255; - // èíèöèàëèçàöèÿ áóôôåðà äèñïåò÷åðà ðàñòåðèçàöèè + // ������������� ������� ���������� ������������ int AttributeTile=MATERIAL_ATTRIBUTE(tile->GetAttribute()|Mesh->Attribute); // int RenderMetal=(GET_RENDER_TUNING(RENDER_TUNING_METAL)&&((Attribute&MESH_NOT_METALL)==0)&&(tile->GetAttribute(ATTRMAT_METAL)))&&RenderLighting; int RenderMetal=(GET_RENDER_TUNING(RENDER_TUNING_METAL)&&((Attribute&MESH_NOT_METALL)==0)&&(tile->GetAttribute(ATTRMAT_METAL))); @@ -378,7 +382,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes RenderDiffuse,RenderMetal,RenderShade, AmbientMesh,MulTile,AddTile,MetalTile, &Point[i]); - // âñòàâëÿþòñÿ ïîëèãîíû è îäíîâðåìåííî èäåò îòñîðòèðîâêà back-ïîëèãîíîâ (íåâèäèìûõ, ñîîòâåòñòâóþùèõ îáðàòíîé ñòîðîíå îáúåêòà) + // ����������� �������� � ������������ ���� ������������ back-��������� (���������, ��������������� �������� ������� �������) if(PolygonOrientationCCW) for(sPolygon *p=&Polygon[0],*end=&p[tile->GetNumberPolygon()];pp1,p->p2,p->p3); @@ -398,7 +402,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes RenderDiffuse,RenderMetal,RenderShade, AmbientMesh,MulTile,AddTile,MetalTile, &Point[i],&Texel[i]); - // âñòàâëÿþòñÿ ïîëèãîíû è îäíîâðåìåííî èäåò îòñîðòèðîâêà back-ïîëèãîíîâ (íåâèäèìûõ, ñîîòâåòñòâóþùèõ îáðàòíîé ñòîðîíå îáúåêòà) + // ����������� �������� � ������������ ���� ������������ back-��������� (���������, ��������������� �������� ������� �������) if(PolygonOrientationCCW) for(sPolygon *p=&Polygon[0],*end=&p[tile->GetNumberPolygon()];pp1,p->p2,p->p3); @@ -457,7 +461,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes } for(int i=0;iGetNumberPolygon();i++) { - // ïåðåäà÷à ãåîìåòðè÷åñêèõ êîîðäèíàò + // �������� �������������� ��������� int i3=i*3; Vect3f pv,pe; sPolygon &p=Polygon[i]; @@ -466,7 +470,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UScene,cUnknownClass *UCameraList,cMes SetPointMesh(i3+1,P3D,BufPoint[p.p2],BufPointAttribute[p.p2],Texel[t.p2]); SetPointMesh(i3+2,P3D,BufPoint[p.p3],BufPointAttribute[p.p3],Texel[t.p3]); } - // âñòàâëÿþòñÿ ïîëèãîíû è îäíîâðåìåííî èäåò îòñîðòèðîâêà back-ïîëèãîíîâ (íåâèäèìûõ, ñîîòâåòñòâóþùèõ îáðàòíîé ñòîðîíå îáúåêòà) + // ����������� �������� � ������������ ���� ������������ back-��������� (���������, ��������������� �������� ������� �������) if(PolygonOrientationCCW) for(int i3=0;i3<3*tile->GetNumberPolygon();i3+=3) AddPolygonFixTestPointFix(i3+0,i3+1,i3+2); @@ -503,7 +507,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cTileMap *TileMap) { if(bTile->GetTexture()->GetStatus(STATUS_TEXTURE_RESET|STATUS_TEXTURE_LOAD)) ResetTextureTileMap565(bTile->GetMaterial(),RenderDevice); - Graph3d->SetTexture(bTile->GetTexture()->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(bTile->GetTexture()->nTexture); // ��������� �������� Vect3f ShareOfs; cConvertor ConvertorObjectToScreen; ConvertorObjectToScreen.GetMatrix()=bTile->DrawMatrix[nCamera],ShareOfs=bTile->ShareOfs[nCamera]; @@ -529,7 +533,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cTileMap *TileMap) { if(bTile->GetLightMap()->GetStatus(STATUS_TEXTURE_SHADOW)) { -// Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // óñòàíîâêà òåêñòóðû +// Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // ��������� �������� // this->Attribute=RENDER_COLOR_MOD_TEXTURE1|RENDER_ALPHA_MOD_TEXTURE1|RENDER_MULTICANAL; this->Attribute|=RENDER_MULTICANAL; Draw(Camera,RenderDevice,bTile->GetTexture()->nTexture,bTile->GetLightMap()->nTexture); @@ -543,7 +547,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cTileMap *TileMap) for(sTileMap *bTile=TileMap->GetTile(0,0),*eTile=TileMap->GetTile(0,TileMap->NumberTileY());bTileGetVisibleTotal(nCamera)&CONST_VISIBLE_FRUSTUM) { - Graph3d->SetTexture(bTile->GetTexture()->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(bTile->GetTexture()->nTexture); // ��������� �������� Vect3f ShareOfs; cConvertor ConvertorObjectToScreen; ConvertorObjectToScreen.GetMatrix()=bTile->DrawMatrix[nCamera],ShareOfs=bTile->ShareOfs[nCamera]; @@ -571,7 +575,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cTileMap *TileMap) { if(bTile->GetLightMap()->GetStatus(STATUS_TEXTURE_SHADOW)) { - Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // ��������� �������� // this->Attribute=RENDER_COLOR_MOD_TEXTURE1|RENDER_ALPHA_MOD_TEXTURE1|RENDER_MULTICANAL; this->Attribute|=RENDER_MULTICANAL; Draw(Camera,RenderDevice,bTile->GetTexture()->nTexture,bTile->GetLightMap()->nTexture); @@ -586,7 +590,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cTileMap *TileMap) if(GET_RENDER_TUNING(RENDER_TUNING_SHADOW)) if(bTile->GetLightMap()->GetStatus(STATUS_TEXTURE_SHADOW)) { - Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // ��������� �������� this->Attribute=RENDER_COLOR_MOD_TEXTURE1|RENDER_ALPHA_MOD_TEXTURE1|RENDER_MULTICANAL; Draw(Camera,RenderDevice); } @@ -628,7 +632,7 @@ void cPolyDispatcher::DrawReflection(cUnknownClass *UCameraList,cTileMap *TileMa if(bTile->GetVisibleTotal(nCamera)&CONST_VISIBLE_FRUSTUM) if(bTile->GetAttribute(ATTR_TILE_REFLECTION)) { - Graph3d->SetTexture(bTile->GetTexture()->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(bTile->GetTexture()->nTexture); // ��������� �������� Vect3f ShareOfs; cConvertor ConvertorObjectToScreen; ConvertorObjectToScreen.GetMatrix()=bTile->DrawMatrix[nCamera],ShareOfs=bTile->ShareOfs[nCamera]; @@ -676,7 +680,7 @@ void cPolyDispatcher::DrawReflection(cUnknownClass *UCameraList,cTileMap *TileMa { if(bTile->GetLightMap()->GetStatus(STATUS_TEXTURE_SHADOW)) { - Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // ��������� �������� // this->Attribute=RENDER_COLOR_MOD_TEXTURE1|RENDER_ALPHA_MOD_TEXTURE1|RENDER_MULTICANAL; this->Attribute|=RENDER_MULTICANAL; Draw(Camera,RenderDevice,bTile->GetTexture()->nTexture,bTile->GetLightMap()->nTexture); @@ -691,7 +695,7 @@ void cPolyDispatcher::DrawReflection(cUnknownClass *UCameraList,cTileMap *TileMa if(GET_RENDER_TUNING(RENDER_TUNING_SHADOW)) if(bTile->GetLightMap()->GetStatus(STATUS_TEXTURE_SHADOW)) { - Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(bTile->GetLightMap()->nTexture); // ��������� �������� this->Attribute=RENDER_COLOR_MOD_TEXTURE1|RENDER_ALPHA_MOD_TEXTURE1|RENDER_MULTICANAL; Draw(Camera,RenderDevice); } @@ -714,14 +718,14 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cPolyGrid *PolyGrid) cInterfaceGraph3d *Graph3d=RenderDevice->GetIGraph3d(); SetClippingPlane(Camera); int FlagShareWorld=Camera->GetAttribute(ATTRIBUTE_CAMERA_PERSPECTIVE_WORLD_SHARE)==ATTRIBUTE_CAMERA_PERSPECTIVE_WORLD_SHARE; - // ñîçäàíèå êîíâåðòåðà èç îáúåêòíîãî â ýêðàííîå ïðîñòðàíñòâî + // �������� ���������� �� ���������� � �������� ������������ Vect3f ShareOfs; cConvertor ConvertorObjectToScreen; PolyGrid->BuildDrawMatrix(Camera,ConvertorObjectToScreen.GetMatrix(),ShareOfs); ConvertorObjectToScreen.BuildMatrix(); ConvertorObjectToScreen.SetProjection(Camera,Camera->GetAttribute(ATTRIBUTE_CAMERA_PERSPECTIVE)); int RadiusWorldShare=GlobalWorldRadius, RadiusWorldShare2=RadiusWorldShare*RadiusWorldShare; - // ïîäãîòîâêà ê ðåíäåðó + // ���������� � ������� int xsize=PolyGrid->xsize,ysize=PolyGrid->ysize; int xstep=PolyGrid->xstep,ystep=PolyGrid->ystep; float du=PolyGrid->du,dv=PolyGrid->dv; @@ -739,7 +743,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cPolyGrid *PolyGrid) BaseAttribute|=RENDER_COLOR_MOD_TEXTURE1; } InitFix(BaseAttribute,xsize*ysize); - // óñòàíîâêà âåðøèí + // ��������� ������ float xpos=ShareOfs.x,ypos=ShareOfs.y,duPoint=du+uofs,dvPoint=dv+vofs,ddu=usize/(xsize-1),ddv=vsize/(ysize-1),uLimit=usize/255,vLimit=vsize/255; sPointPolyGrid *bPoint=Point,*ePoint=&Point[xsize*ysize]; for(;bPointr,bPoint->g,bPoint->b,bPoint->a, Vect2f(duPoint+bPoint->du*uLimit,dvPoint+bPoint->dv*vLimit)); } - // óñòàíîâêà ïîëèãîíîâ + // ��������� ��������� for(int j=0,jend=(ysize-1)*xsize;jGetIGraph3d(); SetClippingPlane(Camera); int FlagShareWorld=Camera->GetAttribute(ATTRIBUTE_CAMERA_PERSPECTIVE_WORLD_SHARE)==ATTRIBUTE_CAMERA_PERSPECTIVE_WORLD_SHARE; - // ñîçäàíèå êîíâåðòåðà èç îáúåêòíîãî â ýêðàííîå ïðîñòðàíñòâî + // �������� ���������� �� ���������� � �������� ������������ Vect2f dTex(0,0); if(TileWater->GetAttribute(TILEWATER_MOVTEXTURE)) { dTex.x-=Camera->GetPos().x/(TileWater->GetScaleTex().x*(1<_SizeTileX())); dTex.y-=Camera->GetPos().y/(TileWater->GetScaleTex().y*(1<_SizeTileY())); } dTex.x=dTex.x-(int)dTex.x; dTex.y=dTex.y-(int)dTex.y; @@ -805,7 +809,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cTileWater *TileWater) PolyGrid->BuildDrawMatrix(Camera,ConvertorObjectToScreen.GetMatrix(),ShareOfs); ConvertorObjectToScreen.BuildMatrix(); ConvertorObjectToScreen.SetProjection(Camera,Camera->GetAttribute(ATTRIBUTE_CAMERA_PERSPECTIVE)); - // ïîäãîòîâêà ê ðåíäåðó + // ���������� � ������� int xsize=PolyGrid->xsize,ysize=PolyGrid->ysize; int xstep=PolyGrid->xstep,ystep=PolyGrid->ystep; float du=PolyGrid->du+dTex.x,dv=PolyGrid->dv+dTex.y; @@ -823,7 +827,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cTileWater *TileWater) Graph3d->SetTexture(PolyGrid->Texture->nTexture); } InitFix(BaseAttribute,xsize*ysize); - // óñòàíîâêà âåðøèí + // ��������� ������ float xpos=ShareOfs.x,ypos=ShareOfs.y,duPoint=du+uofs,dvPoint=dv+vofs,ddu=usize/(xsize-1),ddv=vsize/(ysize-1),uLimit=usize/255,vLimit=vsize/255; sPointPolyGrid *bPoint=Point,*ePoint=&Point[xsize*ysize]; for(;bPointr,bPoint->g,bPoint->b,bPoint->a, Vect2f(duPoint+bPoint->du*uLimit,dvPoint+bPoint->dv*vLimit)); } - // óñòàíîâêà ïîëèãîíîâ + // ��������� ��������� for(int j=0,jend=(ysize-1)*xsize;jGetAttribute(BASEOBJECT_ATTRIBUTE_DRAW_MULTIMATERIAL)) - { // óáèðàåòñÿ çàöèêëèâàíèå, êîíñòàíòû ïîäîáðàíû èìïåðè÷åñêè äëÿ òåêñòóðû 128 + { // ��������� ������������, ��������� ��������� ����������� ��� �������� 128 ustep=WorldPolyGrid->u/xsize, vstep=WorldPolyGrid->v/ysize; duPoint0=WorldPolyGrid->du+WorldPolyGrid->uofs+ustep*i1; dvPoint=WorldPolyGrid->dv+WorldPolyGrid->vofs+vstep*j1; @@ -953,7 +957,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cWorldPolyGrid *WorldPolyG { if(Material->Texture->nTexture==0) CreateTexture(Material,RenderDevice); - Graph3d->SetTexture(Material->Texture->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(Material->Texture->nTexture); // ��������� �������� } Vect2f CameraPosScale(Camera->GetPos().x*GlobalWorldScale.x,Camera->GetPos().y*GlobalWorldScale.y); int xView=Cycl(CameraPosScale.x+GlobalWorldSize.x*GlobalWorldScale.x/2,GlobalWorldSize.x*GlobalWorldScale.x), @@ -997,7 +1001,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cSurfaceReflectionMultiMat CreateTexture(Material,RenderDevice); if(Material->Texture->GetStatus(STATUS_TEXTURE_RESET)) ResetTextureMultiMaterialSurface565(Graph3d,Material,Surface); - Graph3d->SetTexture(Material->Texture->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(Material->Texture->nTexture); // ��������� �������� } DrawTilePolyGrid(RenderDevice,Camera,Surface,i1,j1,i2,j2,Material); } @@ -1042,7 +1046,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cUnkClassDynArrayPointer * Vect3f pw(0,0,0),pv,pe; ConvertorObjectToScreen.ConvertPoint(pw,pv,pe); - // èíèöèàëèçàöèÿ áóôôåðà äèñïåò÷åðà ðàñòåðèçàöèè + // ������������� ������� ���������� ������������ if(Material->GetAttribute(ATTRMAT_TEXTURE_PAL)) { float RadiusSun=Sun.GetRadiusSun(); @@ -1157,7 +1161,7 @@ void cPolyDispatcher::Draw(cUnknownClass *UCameraList,cTangentTrail *TangentTrai if(Camera->GetAttribute(ATTRIBUTE_CAMERA_PERSPECTIVE)) BaseAttribute|=RENDER_CLIPPING3D; if(Material&&Material->GetAttribute(ATTRMAT_TEXTURE_PAL)) { - Graph3d->SetTexture(Material->Texture->nTexture); // óñòàíîâêà òåêñòóðû + Graph3d->SetTexture(Material->Texture->nTexture); // ��������� �������� BaseAttribute|=RENDER_COLOR_MOD_TEXTURE1; } InitFix(BaseAttribute,4); @@ -1307,8 +1311,8 @@ void cPolyDispatcher::AttachCenterShare(const Vect3f &pos,sSpriteFX *SpriteFX,in cRenderDevice *RenderDevice=GetRenderDevice(0); sTextureChild &TextureChild=TextureBuffer->GetTextureChild(idTextureChild); Vect3f pv,pe,pv1,pe1,Pos=pos; - int xr=GetShortDistX(round(pos.x),round(CurrentCamera->GetPos().x),2048), - yr=GetShortDistY(round(pos.y),round(CurrentCamera->GetPos().y),2048); + int xr=GetShortDistX(int(round(pos.x)),int(round(CurrentCamera->GetPos().x)),2048), + yr=GetShortDistY(int(round(pos.y)),int(round(CurrentCamera->GetPos().y)),2048); Pos.x=xr; Pos.y=yr; Pos.z-=SHARE_FLOAT(xr*xr+yr*yr); CurrentConvertorObjectToScreen->ConvertPoint(Pos,pv,pe); @@ -1383,7 +1387,7 @@ void cPolyDispatcher::EndList() CurrentCamera=0; AlphaForSprite=255; } -void cPolyDispatcher::SetViewColor(cUnknownClass *UCamera,sColor4f &Diffuse,sColor4f &Specular,int zWrite) +void cPolyDispatcher::SetViewColor(cUnknownClass *UCamera,const sColor4f &Diffuse,const sColor4f &Specular,int zWrite) { assert(UCamera->GetKind(KIND_CAMERA)); cCamera *Camera=(cCamera*)UCamera; diff --git a/MechoSoma/VisGeneric/PolyMgrTex.cpp b/MechoSoma/VisGeneric/PolyMgrTex.cpp index ff52b194..3c6fd333 100644 --- a/MechoSoma/VisGeneric/PolyMgrTex.cpp +++ b/MechoSoma/VisGeneric/PolyMgrTex.cpp @@ -432,10 +432,10 @@ void cPolyDispatcher::BuildShade(short *shade,int xShade,int yShade,Vect3f &PosS cRenderDevice *RenderDevice=GetRenderDevice(0); cInterfaceGraph3d *Graph3d=RenderDevice->GetIGraph3d(); int aShift4444=RenderDevice->GetTexFmt4444().aBitShift; - int dwShade=(round(1.f*((1<GetTexFmt4444().aBitCount)-1))<GetTexFmt4444().aBitShift)| - (round(0.5f*((1<GetTexFmt4444().rBitCount)-1))<GetTexFmt4444().rBitShift)| - (round(0.5f*((1<GetTexFmt4444().gBitCount)-1))<GetTexFmt4444().gBitShift)| - (round(0.5f*((1<GetTexFmt4444().bBitCount)-1))<GetTexFmt4444().bBitShift); + int dwShade=(int(round(1.f*((1<GetTexFmt4444().aBitCount)-1)))<GetTexFmt4444().aBitShift)| + (int(round(0.5f*((1<GetTexFmt4444().rBitCount)-1)))<GetTexFmt4444().rBitShift)| + (int(round(0.5f*((1<GetTexFmt4444().gBitCount)-1)))<GetTexFmt4444().gBitShift)| + (int(round(0.5f*((1<GetTexFmt4444().bBitCount)-1)))<GetTexFmt4444().bBitShift); int xSh=TERRA_XCYCL(round(PosShade.x)),ySh=TERRA_YCYCL(round(PosShade.y)),zSh=round(PosShade.z); short *shadeBuf=shade; @@ -478,7 +478,7 @@ void cPolyDispatcher::BuildShade(short *shade,int xShade,int yShade,Vect3f &PosS if(!CurrentLightMap->GetStatus(STATUS_TEXTURE_CREATE)) SetCreateTexture(Graph3d,CurrentLightMap,1<_x,1<_y,TEXFMT_ARGB4444); SetLockTexture(Graph3d,CurrentLightMap,(void**)&MemTextureTile); - memfill((unsigned long*)MemTextureTile,CurrentLightMap->bpl<<(CurrentLightMap->_y-2),0xFFFFFFFF); + memfill((uint32_t*)MemTextureTile,CurrentLightMap->bpl<<(CurrentLightMap->_y-2),0xFFFFFFFF); // memfill((unsigned long*)MemTextureTile,CurrentLightMap->bpl<<(CurrentLightMap->_y-2),0x00000000); CurrentLightMap->texture=MemTextureTile; CurrentLightMap->SetStatus(STATUS_TEXTURE_RESET); diff --git a/MechoSoma/VisGeneric/RenderDevice.h b/MechoSoma/VisGeneric/RenderDevice.h index de2db698..4b803008 100644 --- a/MechoSoma/VisGeneric/RenderDevice.h +++ b/MechoSoma/VisGeneric/RenderDevice.h @@ -4,7 +4,7 @@ #include "IGraph3d.h" #include "Unknown.h" #include "UnkLibrary.h" -#include "umath.h" +#include "UMATH.H" const int NUMBER_TEXTURE_MAX=1000; @@ -13,8 +13,8 @@ struct sTexture; struct sTextureDevice { - int hTexture; // íîìåð òåêñòóðû - int Status; // ñòàòóñ òåêñòóðû + int hTexture; // ����� �������� + int Status; // ������ �������� sTexture *Texture; inline int& GetStatus() { return Status; } @@ -40,7 +40,7 @@ class cRenderDevice : public cUnknownClass void Release(); void Attach(cInterfaceGraph3d *iGraph3d); - // ôóíêöèè äëÿ ðàáîòû ñî ñïèñêîì êàìåð äëÿ äàííîãî óñòðîéñòâà + // ������� ��� ������ �� ������� ����� ��� ������� ���������� void Attach(cCamera *Camera); void Detach(cCamera *Camera); inline cCamera* GetCamera(int number) { return (cCamera*)CameraList[number]; } diff --git a/MechoSoma/VisGeneric/Scene.cpp b/MechoSoma/VisGeneric/Scene.cpp index 92caffd9..584d3081 100644 --- a/MechoSoma/VisGeneric/Scene.cpp +++ b/MechoSoma/VisGeneric/Scene.cpp @@ -1,4 +1,4 @@ -#include "scene.h" +#include "Scene.h" #include "cString.h" #include "TileMap.h" #include "TileWater.h" @@ -6,11 +6,11 @@ #include "PolyMgr.h" #include "TexMgr.h" #include "RenderDevice.h" -// äëÿ ðàáîòû ñî ñêðèïòàìè +// ��� ������ �� ��������� #include "WorldSetup.h" #include "BaseDefine.h" #include "aci_parser.h" -// ñòàðûå âêëþ÷åíèÿ +// ������ ��������� #include "Dispatcher.h" #include "BaseTrail.h" #include "BaseLight.h" @@ -134,13 +134,13 @@ void cScene::ReleaseWorld() if(BaseObjectMgr) BaseObjectMgr->Release(); GetLibTex()->Release(1); } -void cScene::LoadWorld(char *fname,int number,int track) +void cScene::LoadWorld(const std::filesystem::path &path,int number,int track) { ReleaseWorld(); - UNKNOWN_ASSERT((fname)&&strlen(fname)); - scrDataBlock *p,*root=loadScript(fname); + UNKNOWN_ASSERT(!path.empty()); + scrDataBlock *p,*root=loadScript(path); - // èäåíòèôèêàöèÿ íà÷àëüíûõ äàííûõ + // ������������� ��������� ������ RadiusPlanet()=1000; int DefaultAttribute=0,AirHeight=0,CloudHeight=0; cString DefaultPathTextureWater; @@ -174,12 +174,12 @@ void cScene::LoadWorld(char *fname,int number,int track) if((!DefaultPathObject3dMap)||(!DefaultPathTextureMap)||(!DefaultPathTextureWater)) ErrH.Abort("cScene::LoadWorld()\r\nWorld path not found\r\n"); - // çàãðóçêà ñîáñòâåííî ìèðà + // �������� ���������� ���� p=root->nextLevel->first(); while(p) if((p->ID==WORLD_STRUCT)&&(number==*p->i_dataPtr)) break; else p=p->next; - // èíèöèàëèçàöèÿ ïî óìîë÷àíèþ + // ������������� �� ��������� cString FileNameTileMap=DefaultFileNameTileMap, FileNameObjectMap=DefaultFileNameObjectMap, FileNameOmniMap=DefaultFileNameOmniMap, @@ -295,7 +295,7 @@ void cScene::LoadWorld(char *fname,int number,int track) } } delete root; - // èíèöèàëèçàöèÿ øàðà + // ������������� ���� #ifdef _MECHOSOMA_ extern char* mch_mainINI; extern char* getIniKey(char* fname,char* section,char* key); @@ -303,23 +303,23 @@ void cScene::LoadWorld(char *fname,int number,int track) #endif InitArrayShare(RadiusPlanet()=RadiusPlanet()); xWorldSize()=2048; yWorldSize()=2048; - // ñîçäàíèå ïîëèãîíàëüíîé êàðòû ìèðà + // �������� ������������� ����� ���� if(GetTileMap()) delete GetTileMap(); GetTileMap()=0; GetTileMap()=new cTileMap; GetTileMap()->Load(vMap_GetTargetName(FileNameTileMap)); - // ñîçäàíèå âîäû íà ìèðå + // �������� ���� �� ���� if(GetTileWater()) delete GetTileWater(); GetTileWater()=0; GetTileWater()=new cTileWater; GetTileWater()->Attach(GetTileMap()); GetTileWater()->SetLevelWater(vMap_LevelH2O()); GetTileWater()->Load(WaterTileSize,WaterTileSize,WaterScale,WaterScale,WaterVelocityX,WaterVelocityY,FileNameTextureWater,DefaultPathTextureWater,WaterEnvMap); - // ñîçäàíèå îáëàêîâ íà ìèðå + // �������� ������� �� ���� if(GetAir()) delete GetAir(); GetAir()=0; GetAir()=LoadAir(AirTileSize,AirTileSize,AirScale,AirScale,AirVelocityX,AirVelocityY,FileNameTextureAir,DefaultPathTextureWater,AirHeight); - // ñîçäàíèå îáëàêîâ íà ìèðå + // �������� ������� �� ���� if(GetCloud()) delete GetCloud(); GetCloud()=0; GetCloud()=LoadCloud(CloudTileSize,CloudTileSize,CloudScale,CloudScale,CloudVelocityX,CloudVelocityY,FileNameTextureCloud,FileNameOpacityCloud,DefaultPathTextureWater,CloudHeight); - // çàãðóçêà èñòî÷íèêîâ ñâåòà äëÿ ìèðà (íà íåáî, îáëàêà) + // �������� ���������� ����� ��� ���� (�� ����, ������) if(GetAir()) for(int k=0;kysize*GetAir()->xsize;k++) GetAir()->pColor[k].Set(ColorAmbientAir.GetR(),ColorAmbientAir.GetG(),ColorAmbientAir.GetB()); @@ -336,7 +336,7 @@ void cScene::Animate(float CurrentTime,float PreviousTime) start_timer(cScene_Animate, STAT_M3D); float dTime=CurrentTime-PreviousTime; GetM3D()->Animate(GetCameraList(),CurrentTime,PreviousTime); - // ïðîöåññû + // �������� if((GetAir())&&(GetCloud())) { GetAir()->uofs=fmod(GetAir()->uofs+GetAir()->du*dTime,1.f); @@ -347,7 +347,7 @@ void cScene::Animate(float CurrentTime,float PreviousTime) if(GetBaseObjectMgr()&&GetBaseObjectMgr()->BaseList) { /* for(cBaseObjectList *start=GetBaseObjectMgr()->BaseList;start;start=start->next) - { // àíèìàöèÿ ñëåäîâ + { // �������� ������ assert(start->Base); if(start->Base->GetType(BASEOBJECT_TYPE_BASETRAIL_TANGENT)) { @@ -356,7 +356,7 @@ void cScene::Animate(float CurrentTime,float PreviousTime) } } */ - //î÷èñòêà îò ëèøíèõ îáúåêòîâ + //������� �� ������ �������� GetBaseObjectMgr()->Release(BASEOBJECT_TYPE_DELETE); } stop_timer(cScene_Animate, STAT_M3D); @@ -364,7 +364,7 @@ void cScene::Animate(float CurrentTime,float PreviousTime) void cScene::Draw(int number) { if(number&0x0000000F) - { // òîëüêî îòðàæåííûå îáúåêòû + { // ������ ���������� ������� start_timer(cTileMap_DrawReflection, STAT_M3D); if(GET_RENDER_TUNING(RENDER_TUNING_TILEMAP)) if(GetTileMap()) GetTileMap()->DrawReflection(GetCameraList()); @@ -375,7 +375,7 @@ void cScene::Draw(int number) stop_timer(cM3D_DrawReflection, STAT_M3D); } if(number&0x000000F0) - { // ãëîáàëüíûå íå ïðîçðà÷íûå îáúåêòû ìèðà + { // ���������� �� ���������� ������� ���� cWorldPolyGrid *pAir=GetAir(),*pCloud=GetCloud(); start_timer(cTileMap_Draw, STAT_M3D); if(GET_RENDER_TUNING(RENDER_TUNING_TILEMAP)) @@ -397,14 +397,14 @@ void cScene::Draw(int number) stop_timer(Cloud_Sky_Sun_Draw, STAT_M3D); } if(number&0x00000F00) - { // äèíàìè÷åñêèå íå ïðîçðà÷íûå îáúåêòû + { // ������������ �� ���������� ������� start_timer(cM3D_Draw, STAT_M3D); M3D->Draw(this); P3D->GetRenderDevice(0)->GetIGraph3d()->NullClipRect(); stop_timer(cM3D_Draw, STAT_M3D); } if(number&0x0000F000) - { // ãëîáàëüíûå ïðîçðà÷íûå îáúåêòû ìèðà + { // ���������� ���������� ������� ���� start_timer(cTangentTrail_Draw, STAT_M3D); if(GetBaseObjectMgr()&&GetBaseObjectMgr()->BaseList) for(cBaseObjectList *start=GetBaseObjectMgr()->BaseList;start;start=start->next) @@ -427,7 +427,7 @@ void cScene::Draw(int number) O3D->Draw(GetCameraList()); stop_timer(cO3D_Draw, STAT_M3D); } - if(number&0x00F00000) // óñòàíîâêà öâåòà ýêðàíà ïîä âîäîé + if(number&0x00F00000) // ��������� ����� ������ ��� ����� if(vMap_IsActive()) for(int i=0;iGetKind(KIND_CAMERA)); cCamera *Camera=(cCamera*)GetCamera(0); @@ -468,7 +468,7 @@ void cScene::PreDraw(int number) else GlobalWorldRadius=RadiusPlanet(); stop_timer(cTileMap_RadiusShare, STAT_M3D); - // òåñòû âèäèìîñòè îáúåêòîâ è ìèðà + // ����� ��������� �������� � ���� start_timer(cTileMap_TestVisible, STAT_M3D); if(number&0x000000F0) if(GetTileMap()) GetTileMap()->TestVisible(GetCameraList()); @@ -479,20 +479,20 @@ void cScene::PreDraw(int number) stop_timer(cM3D_TestVisible, STAT_M3D); start_timer(cM3D_ShadeDynamic, STAT_M3D); if(number&0x000000F0) - if(GetTileMap()) M3D->ShadeDynamic(GetCameraList(),GetTileMap()); // ïîñòðîåíèå äèíàìè÷åñêèõ òåíåé + if(GetTileMap()) M3D->ShadeDynamic(GetCameraList(),GetTileMap()); // ���������� ������������ ����� stop_timer(cM3D_ShadeDynamic, STAT_M3D); start_timer(cTileWater_PreDraw, STAT_M3D); if(number&0x0000F000) if(GetTileWater()) GetTileWater()->PreDraw(this); stop_timer(cTileWater_PreDraw, STAT_M3D); - // êåøèðîâàíèå òåêñòóð + // ����������� ������� start_timer(cTileMap_UnlockTexture, STAT_M3D); if(number&0x000000F0) if(GetTileMap()) GetTileMap()->UnlockTexture(GetCameraList()); stop_timer(cTileMap_UnlockTexture, STAT_M3D); } void cScene::PostDraw(int number) -{ // äåéñòâèÿ ïîñëå ïðîðèñîâêè, îñâîáîæäåíèå âðåìåííûõ áóôåðîâ è ò.ä. +{ // �������� ����� ����������, ������������ ��������� ������� � �.�. start_timer(cScene_PostDraw, STAT_M3D); if(GetTileMap()) M3D->RestoreShadeDynamic(); stop_timer(cScene_PostDraw, STAT_M3D); @@ -690,7 +690,7 @@ void cScene::LoadWorldLight(int number,int track,sColor4f &ColorAmbientAir,char case 2: AddAirLight(pos,ambient,diffuse,illumination,t_radius*0.7f,100,50,TextureMoon,TexturePath); break; - case -1: // ñòàðûé ñêðèïò + case -1: // ������ ������ break; default: assert(0); diff --git a/MechoSoma/VisGeneric/Scene.h b/MechoSoma/VisGeneric/Scene.h index d861f24c..e38e18f6 100644 --- a/MechoSoma/VisGeneric/Scene.h +++ b/MechoSoma/VisGeneric/Scene.h @@ -1,7 +1,9 @@ #ifndef __SCENE_H__ #define __SCENE_H__ -#include "umath.h" +#include + +#include "UMATH.H" #include "UnkLibrary.h" class cM3D; @@ -23,11 +25,11 @@ class cScene : public cUnknownClass ~cScene(); void Release(); void Animate(float CurrentTime,float PreviousTime); - void Draw(int number=0xFFFFFFFF); // îòðèñîâêà óêàçàííîé ÷àñòè ìèðà - void PreDraw(int number=0xFFFFFFFF); // ïîäãîòîâêà ê ïðîðèñîâêå, îïðåäåëåíèå âèäèìîñòè, âûñòàâëåíèå àíèìàöèè è ò.ä. - void PostDraw(int number=0xFFFFFFFF); // äåéñòâèÿ ïîñëå ïðîðèñîâêè, îñâîáîæäåíèå âðåìåííûõ áóôåðîâ è ò.ä. - void GetOmniLight(const Vect3f &pos,sColor4f &diffuse,sColor4f &illumination); // âîçâðàùàåò îñâåùåííîñòü òî÷êè â ñöåíå - // äîñòóï ê ïåðåìåííûì + void Draw(int number=0xFFFFFFFF); // ��������� ��������� ����� ���� + void PreDraw(int number=0xFFFFFFFF); // ���������� � ����������, ����������� ���������, ����������� �������� � �.�. + void PostDraw(int number=0xFFFFFFFF); // �������� ����� ����������, ������������ ��������� ������� � �.�. + void GetOmniLight(const Vect3f &pos,sColor4f &diffuse,sColor4f &illumination); // ���������� ������������ ����� � ����� + // ������ � ���������� inline cM3D*& GetM3D() { return M3D; } inline cO3D*& GetO3D() { return O3D; } inline cLight*& GetLight() { return Light; } @@ -50,39 +52,39 @@ class cScene : public cUnknownClass inline sColor4f& GetAmbientObjectMechos() { return AmbientObjectMechos; } inline sColor4f& GetDiffuseLightingMax() { return DiffuseLightingMax; } inline sColor4f& GetAmbientLightingMax() { return AmbientLightingMax; } - // äëÿ ðàáîòû ñî ñïèñêîì êàìåð + // ��� ������ �� ������� ����� inline int GetNumberCamera() { return CameraArray->length(); } inline cCamera*& GetCamera(int number) { assert(0<=number&&numberlength()); return (cCamera*&)(*CameraArray)[number]; } inline cUnknownClass*& GetCameraList() { return (cUnknownClass*&)CameraArray; } inline void Attach(cCamera *Camera) { for(int i=0;iAttach((cUnknownClass*)Camera); } inline void Detach(cCamera *Camera) { CameraArray->Detach((cUnknownClass*)Camera); } - // äëÿ ðàáîòû ñ áèáëèîòåêîé òåêñòóð + // ��� ������ � ����������� ������� void Attach(cTextureBuffer *pTextureLibrary) { TextureLibrary=pTextureLibrary; } void Detach(cTextureBuffer *pTextureLibrary) { if(TextureLibrary) TextureLibrary=0; } - // äëÿ ðàáîòû ñ áèáëèîòåêîé îáúåêòîâ + // ��� ������ � ����������� �������� void Attach(cMeshLibrary *pMeshLibrary) { MeshLibrary=pMeshLibrary; } void Detach(cMeshLibrary *pMeshLibrary) { if(MeshLibrary) MeshLibrary=0; } - // èíèöèàëèçàöèÿ - void LoadWorld(char *fname,int number=0,int track=0); // çàãðóçêà ñêðèïòà îïèñûâàþùåãî èíèöèàëèçàöèþ ìèðà - void ReleaseWorld(); // âûãðóçêà ñêðèïòà îïèñûâàþùåãî èíèöèàëèçàöèþ ìèðà - void AddOmniLight(const Vect3f &pos,float radius,const sColor4f &ambient,const sColor4f &diffuse,const sColor4f &illumination);// äîáàâëÿåò òî÷å÷íûé èñòî÷íèê + // ������������� + void LoadWorld(const std::filesystem::path &path,int number=0,int track=0); // �������� ������� ������������ ������������� ���� + void ReleaseWorld(); // �������� ������� ������������ ������������� ���� + void AddOmniLight(const Vect3f &pos,float radius,const sColor4f &ambient,const sColor4f &diffuse,const sColor4f &illumination);// ��������� �������� �������� private: - cTextureBuffer *TextureLibrary; // áèáëèîòåêà òåêñòóð - cMeshLibrary *MeshLibrary; // áèáëèîòåêà 3d-îáúåêòîâ - cUnkClassDynArrayPointer *CameraArray; // ñïèñîê âñåõ ñîçäàííûõ êàìåð - cM3D *M3D; // äèñïåò÷åð 3d-îáúåêòîâ - cO3D *O3D; // äèñïåò÷åð âèçóàëüíûõ äèíàìè÷åñêèõ èñòî÷íèêîâ ñâåòà - cManagerBaseObject *BaseObjectMgr; // êëàññ ïðèìèòèâíûõ îáúåêòîâ - cLight *Light; // ãëîáàëüíûé èñòî÷íèê îñâåùåíèÿ - // îïèñàíèå ìèðà - int xSize; // x - ðàçìåð ìèðà - int ySize; // y - ðàçìåð ìèðà - int RadiusShare; // ðàäèóñ ïëàíåòû ìèðà - cTileMap *tMap; // óêàçàòåëü íà cTileMap - cTileWater *tWater; // óêàçàòåëü íà cTileWater - cWorldPolyGrid *Air; // óêàçàòåëü íà ñWorldPolyGrid - cWorldPolyGrid *Cloud; // óêàçàòåëü íà ñWorldPolyGrid - cUnkClassDynArrayPointer *SunArray; // ìàññèâ íåáåñíûõ ñâåòèë + cTextureBuffer *TextureLibrary; // ���������� ������� + cMeshLibrary *MeshLibrary; // ���������� 3d-�������� + cUnkClassDynArrayPointer *CameraArray; // ������ ���� ��������� ����� + cM3D *M3D; // ��������� 3d-�������� + cO3D *O3D; // ��������� ���������� ������������ ���������� ����� + cManagerBaseObject *BaseObjectMgr; // ����� ����������� �������� + cLight *Light; // ���������� �������� ��������� + // �������� ���� + int xSize; // x - ������ ���� + int ySize; // y - ������ ���� + int RadiusShare; // ������ ������� ���� + cTileMap *tMap; // ��������� �� cTileMap + cTileWater *tWater; // ��������� �� cTileWater + cWorldPolyGrid *Air; // ��������� �� �WorldPolyGrid + cWorldPolyGrid *Cloud; // ��������� �� �WorldPolyGrid + cUnkClassDynArrayPointer *SunArray; // ������ �������� ������ sColor4f AmbientObjectAll,AmbientObjectMechos,DiffuseLightingMax,AmbientLightingMax; cWorldPolyGrid* LoadAir(int xstep,int ystep,float uScale,float vScale,float duOfs,float dvOfs,char *TextureName,char *TexturePath,int AirHeight); diff --git a/MechoSoma/VisGeneric/SurmapClient.cpp b/MechoSoma/VisGeneric/SurmapClient.cpp index e5e5e29b..d5715723 100644 --- a/MechoSoma/VisGeneric/SurmapClient.cpp +++ b/MechoSoma/VisGeneric/SurmapClient.cpp @@ -1,5 +1,5 @@ #include "SurmapClient.h" -#include "dispatcher.h" +#include "Dispatcher.h" #include "IGraph3d.h" #ifdef _SURMAP_ @@ -41,19 +41,19 @@ void initM3D(int xScr,int yScr,int FullScr) gb_UScene=gb_IVisGeneric->CreateScene(); gb_IVisGeneric->SetScene(gb_UScene); gb_UCamera=gb_IVisGeneric->CreateCamera(); - gb_IVisGeneric->AttachCamera(gb_UCamera); // ÿ¨ø¸þõôøýõýøõ úðüõ¨v ú ðúªøòýþù ¸¡õýõ - gb_IVisGeneric->SetCameraAttribute(gb_UCamera,ATTRIBUTE_CAMERA_WORLD_CUTTING); // ¸¯õ¨ø¢ýþ¸ª¹ òvòþôð ø ÿõ¨¸ÿõúªøòð + gb_IVisGeneric->AttachCamera(gb_UCamera); // ������������� �����v � �������� ����� + gb_IVisGeneric->SetCameraAttribute(gb_UCamera,ATTRIBUTE_CAMERA_WORLD_CUTTING); // ����������� �v���� � ����������� gb_IVisGeneric->SetCameraPosition(gb_UCamera,&Vect3f(0,0,512),&Vect3f(0,0,0)); - gb_IVisGeneric->SetCameraFrustum(gb_UCamera, // º¸ªðýðòûøòðõª¸  ÿø¨ðüøôð òøôøüþ¸ªø - &Vect2f(0.5f,0.5f), // ¡õýª¨ úðüõ¨v - &sRectangle4f(-0.49f,-0.49f,0.49f,0.49f), // òøôøüð  þñû𸪹 úðüõ¨v - &Vect2f(1.0f,1.0f), // ¯þúº¸ úðüõ¨v - &Vect2f(10.0f,3000.0f), // ñûøöðù°øù ø ôðû¹ýøù z-ÿûþ¸úþ¸ªø þª¸õ¢õýø  - &Vect2f(0.2f,0.90f)); // zNear ø zFar ôû  üðÿø¨þòðýø  ò zBuffer + gb_IVisGeneric->SetCameraFrustum(gb_UCamera, // ��������������� �������� ��������� + &Vect2f(0.5f,0.5f), // ����� �����v + &sRectangle4f(-0.49f,-0.49f,0.49f,0.49f), // ������ ���𸪹 �����v + &Vect2f(1.0f,1.0f), // ����� �����v + &Vect2f(10.0f,3000.0f), // ��������� � ������� z-��������� ��������� + &Vect2f(0.2f,0.90f)); // zNear � zFar ��� ����������� � zBuffer gb_IVisGeneric->AttachCameraViewPort(gb_UCamera,gb_URenderDevice); gb_IVisGeneric->SetRenderObjectSwitch(RENDER_TUNING_OBJECT_LIGHTING_CONST); gb_UArrayCamera(0)=gb_UCamera; - //¦ðó¨º÷úð úº¨¸þ¨ð START POINTOW + //������ ������� START POINTOW cM3D *M3D=(cM3D*)gb_IVisGeneric->GetM3D(); assert(M3D); if(MeshPoint) delete MeshPoint; @@ -66,11 +66,11 @@ void doneM3D() { gb_UArrayCamera(0)=0; gb_UArrayCamera.Delete(); - gb_IVisGeneric->ReleaseWorld(); // âûãðóçêà ìèðà - if(gb_UCamera) gb_IVisGeneric->ReleaseCamera(gb_UCamera); // óäàëåíèå íåíóæíîé êàìåðû - if(gb_UScene) gb_IVisGeneric->ReleaseScene(gb_UScene); // óäàëåíèå ñöåíû - gb_IVisGeneric->ReleaseGraph(gb_URenderDevice); // çàêðûòèå îêíà âûâîäà - gb_IVisGeneric->Release(); // çàêðûòèå áèáëèîòåêè + gb_IVisGeneric->ReleaseWorld(); // �������� ���� + if(gb_UCamera) gb_IVisGeneric->ReleaseCamera(gb_UCamera); // �������� �������� ������ + if(gb_UScene) gb_IVisGeneric->ReleaseScene(gb_UScene); // �������� ����� + gb_IVisGeneric->ReleaseGraph(gb_URenderDevice); // �������� ���� ������ + gb_IVisGeneric->Release(); // �������� ���������� gb_UCamera=0; gb_UScene=0; gb_URenderDevice=0; gb_IGraph3d=0; gb_IVisGeneric=0; } void setCamera(float x,float y,float z,int xCenter,int yCenter,int xSize,int ySize,float ax,float ay,float az,int focus,char perspective) @@ -226,7 +226,7 @@ int loadM3D(char* name,char flCollision,float x,float y,float z,float ax,float Mesh->NumberTrack=MESH_GLOBAL_TRACK; editM3D=Mesh->ID; extern void RenderShadovM3D(int number,float y); - RenderShadovM3D(editM3D,Mesh->y()); //+ª¨ø¸þòúð ªõýø + RenderShadovM3D(editM3D,Mesh->y()); //+�������� ���� if(flCollision) Mesh->Type=M3D_TOTAL_TYPE(M3D_KIND(Mesh->Type),M3D_STATIC_COLLIDING); else Mesh->Type=M3D_TOTAL_TYPE(M3D_KIND(Mesh->Type),M3D_STATIC_NON_COLLIDING); return Mesh->ID; diff --git a/MechoSoma/VisGeneric/SurmapClient.h b/MechoSoma/VisGeneric/SurmapClient.h index 2c2eb975..88ad1696 100644 --- a/MechoSoma/VisGeneric/SurmapClient.h +++ b/MechoSoma/VisGeneric/SurmapClient.h @@ -9,7 +9,7 @@ #define delCLSAll delO3DAll #include "IVisGeneric.h" -#include "math3d.h" +#include "Math3d.h" extern void initM3D(int xScr,int yScr,int FullScr); extern void doneM3D(); diff --git a/MechoSoma/VisGeneric/TERRA.H b/MechoSoma/VisGeneric/TERRA.H index 4b3d4db5..77d5c8ad 100644 --- a/MechoSoma/VisGeneric/TERRA.H +++ b/MechoSoma/VisGeneric/TERRA.H @@ -2,8 +2,8 @@ #define __TERRA_H__ //Global Define -#define XCYCL(x) ((x) & clip_mask_x) -#define YCYCL(y) ((y) & clip_mask_y) +#define XCYCL(x) (int(x) & clip_mask_x) +#define YCYCL(y) (int(y) & clip_mask_y) const unsigned int H_SIZE_POWER= 11; const unsigned int H_SIZE = 1 << H_SIZE_POWER; @@ -92,8 +92,8 @@ const int BIZARRE_ALT_MAP = 0; const int NOISELEVEL = 256; const unsigned char DELTA_MASK = 1 | (1 << 1); -#include "vmap.h" -#include "render.h" +#include "VMAP.H" +#include "RENDER.H" #include "ch_points.h" #include "sur_scr.h" #include "tools.h" diff --git a/MechoSoma/VisGeneric/TexMgr.cpp b/MechoSoma/VisGeneric/TexMgr.cpp index 4f5e4d3d..57bc9743 100644 --- a/MechoSoma/VisGeneric/TexMgr.cpp +++ b/MechoSoma/VisGeneric/TexMgr.cpp @@ -1,7 +1,7 @@ #include "BaseDefine.h" #include "TgaServ.h" #include "TexMgr.h" -#include "base.h" +#include "Base.h" #include "PolyMgr.h" #ifdef _MECHOSOMA_ diff --git a/MechoSoma/VisGeneric/TexMgr.h b/MechoSoma/VisGeneric/TexMgr.h index 710e94cb..be07c83e 100644 --- a/MechoSoma/VisGeneric/TexMgr.h +++ b/MechoSoma/VisGeneric/TexMgr.h @@ -17,14 +17,14 @@ class cTextureBuffer : public cBaseArrayPointer { cBaseDynArray TextureChildArray; int xCurrent,yCurrent,yMax; - sTexture *MultiTexture; // òåêóùàÿ òåêñòóðà â êîòîðóþ èäåò íàêîïëåíèå ïî Attach() + sTexture *MultiTexture; // ������� �������� � ������� ���� ���������� �� Attach() public: cTextureBuffer():cBaseArrayPointer(1000,100) { } ~cTextureBuffer(); - sTexture* BeginList(int x,int y); // ñîçäàòü ìóëüòè òåêñòóðó ðàçìåðà x*y - sTextureChild* AttachChild(char *name,int id); // äîáàâèòü â ìóëüòè òåêñòóðó òåêñòóðó - sTexture* EndList(); // çàâåðøèòü ñîçäàíèå ìóëüòèòåêòóðû + sTexture* BeginList(int x,int y); // ������� ������ �������� ������� x*y + sTextureChild* AttachChild(char *name,int id); // �������� � ������ �������� �������� + sTexture* EndList(); // ��������� �������� ������������� sTextureChild& GetTextureChild(int number) { assert(0<=number&&number }; extern cTextureBuffer *TextureBuffer; -#endif __TEXTUREMGR_H__ \ No newline at end of file +#endif // __TEXTUREMGR_H__ \ No newline at end of file diff --git a/MechoSoma/VisGeneric/TgaServ.h b/MechoSoma/VisGeneric/TgaServ.h index f0c8bcb2..4db45c59 100644 --- a/MechoSoma/VisGeneric/TgaServ.h +++ b/MechoSoma/VisGeneric/TgaServ.h @@ -1,4 +1,4 @@ -#include "_xtool.h" +#include "xtool.h" struct TGA_Header { diff --git a/MechoSoma/VisGeneric/TileMap.h b/MechoSoma/VisGeneric/TileMap.h index 7b8c0a43..87a6dacf 100644 --- a/MechoSoma/VisGeneric/TileMap.h +++ b/MechoSoma/VisGeneric/TileMap.h @@ -1,11 +1,11 @@ #ifndef __TILEMAP_H__ #define __TILEMAP_H__ -#include "unknown.h" +#include "Unknown.h" -#include "object.h" +#include "Object.h" #include "BaseClass.h" -#include "object3d.h" +#include "Object3d.h" #include "PolyGrid.h" #include "IncTerra.h" diff --git a/MechoSoma/VisGeneric/TileWater.h b/MechoSoma/VisGeneric/TileWater.h index f7f3439d..80eeae5e 100644 --- a/MechoSoma/VisGeneric/TileWater.h +++ b/MechoSoma/VisGeneric/TileWater.h @@ -3,8 +3,8 @@ #define TILEWATER_MOVTEXTURE 1 -#include "unknown.h" -#include "umath.h" +#include "Unknown.h" +#include "UMATH.H" class cTileMap; class cPolyGrid; diff --git a/MechoSoma/VisGeneric/UTIL/cString.h b/MechoSoma/VisGeneric/UTIL/cString.h index bbcc31ad..67c7062e 100644 --- a/MechoSoma/VisGeneric/UTIL/cString.h +++ b/MechoSoma/VisGeneric/UTIL/cString.h @@ -1,52 +1,252 @@ #ifndef __CSTRING_H__ #define __CSTRING_H__ -#include "assert.h" -#include "malloc.h" -#include "string.h" +#include +#include +#include + +#ifdef __APPLE__ +#include +#define stricmp strcasecmp +#define strnicmp strncasecmp +#endif //#define _STRING_DEBUG_ -#define STRING_ASSERT(a) assert(a) +#define STRING_ASSERT(a) assert(a) class cString { char *buf; public: - cString() { buf=0; SetSize(); } - cString(int size) { if(size) { buf=(char*)malloc(size); SetSize(size); } else { buf=0; SetSize(); } } - cString(char *string) { if(string) { buf=strdup(string); SetSize(); } else { buf=0; SetSize(); } } - cString(cString &string) { if(string.buf) { buf=strdup(string); SetSize(); } else { buf=0; SetSize(); } } - ~cString() { if(buf) free(buf); } - - inline int operator == (char *string) { if((string)&&(buf)) return !stricmp(string,buf); return string==buf; } - inline int operator != (char *string) { if((string)&&(buf)) return stricmp(string,buf); return string!=buf; } - inline char& operator [](int l) { AssertValid(l); return buf[l]; } - inline operator char*() { return buf; } - inline char* ptr() { return buf; } - inline int length() { if(buf) return strlen(buf); return 0; } - inline cString& operator << (cString &string) { if(string.buf) if(buf) { char *tmp=buf; buf=(char*)malloc(strlen(tmp)+strlen(string.buf)+1); SetSize(); strcpy(buf,tmp); strcat(buf,string.buf); free(tmp); } else { buf=strdup(string.buf); SetSize(); } return *this; } - inline cString& operator << (char *string) { if(string) if(buf) { char *tmp=buf; buf=(char*)malloc(strlen(tmp)+strlen(string)+1); SetSize(); strcpy(buf,tmp); strcat(buf,string); free(tmp); } else { buf=strdup(string); SetSize(); } return *this; } - inline cString& operator = (cString &string) { if(buf) free(buf); if(string.buf) { buf=strdup(string.buf); SetSize(); } else { buf=0; SetSize(); } return *this; } - inline cString& operator = (char *string) { if(buf) free(buf); if(string) buf=strdup(string); else buf=0; SetSize(); return *this; } - inline void New(char *string) { if(buf) free(buf); if(string) buf=strdup(string); else buf=0; SetSize(); } - inline void New(int size) { if(buf) free(buf); if(size) { buf=(char*)malloc(size); SetSize(size); } else { buf=0; SetSize(); } } - inline void Delete() { if(buf) { free(buf); buf=0; SetSize(); } } - inline void Release() { if(buf) { free(buf); buf=0; SetSize(); } } - inline void Set(char *string,int pos=0); + cString() + { + buf=0; SetSize(); + } + + cString(int size) + { + if(size) + { + buf=(char*)malloc(size); + SetSize(size); + } + else + { + buf=0; + SetSize(); + } + } + + cString(char *string) + { + if(string) + { + buf=strdup(string); + SetSize(); + } + else + { + buf=0; + SetSize(); + } + } + + cString(cString &string) + { + if(string.buf) + { + buf=strdup(string); + SetSize(); + } + else + { + buf=0; + SetSize(); + } + } + + ~cString() + { + if(buf) free(buf); + } + + inline int operator == (const char *string) + { + if((string)&&(buf)) return !stricmp(string,buf); + return string==buf; + } + + inline int operator != (const char *string) + { + if((string)&&(buf)) return stricmp(string,buf); + return string!=buf; + } + + inline char& operator [](int l) + { + AssertValid(l); + return buf[l]; + } + + inline operator char*() + { + return buf; + } + + inline char* ptr() + { + return buf; + } + + inline int length() + { + if(buf) return strlen(buf); + return 0; + } + + inline cString& operator << (cString &string) + { + if(string.buf) + { + if(buf) + { + char *tmp=buf; + buf=(char*)malloc(strlen(tmp)+strlen(string.buf)+1); + SetSize(); + strcpy(buf,tmp); + strcat(buf,string.buf); + free(tmp); + } + else + { + buf=strdup(string.buf); + SetSize(); + } + } + return *this; + } + + inline cString& operator << (const char *string) + { + if(string) + { + if(buf) + { + char *tmp=buf; + buf=(char*)malloc(strlen(tmp)+strlen(string)+1); + SetSize(); + strcpy(buf,tmp); + strcat(buf,string); + free(tmp); + } + else + { + buf=strdup(string); + SetSize(); + } + } + return *this; + } + + inline cString& operator = (cString &string) + { + if(buf) free(buf); + if(string.buf) + { + buf=strdup(string.buf); + SetSize(); + } + else + { + buf=0; + SetSize(); + } + return *this; + } + + inline cString& operator = (const char *string) + { + if(buf) free(buf); + if(string) buf=strdup(string); + else buf=0; + SetSize(); + return *this; + } + + inline void New(const char *string) + { + if(buf) free(buf); + if(string) buf=strdup(string); + else buf=0; + SetSize(); + } + + inline void New(int size) + { + if(buf) free(buf); + if(size) + { + buf=(char*)malloc(size); + SetSize(size); + } + else + { + buf=0; + SetSize(); + } + } + + inline void Delete() + { + if(buf) + { + free(buf); + buf=0; + SetSize(); + } + } + + inline void Release() + { + if(buf) + { + free(buf); + buf=0; + SetSize(); + } + } + + inline void Set(const char *string,int pos=0); private: #ifdef _STRING_DEBUG_ int size; - inline int AssertValid(int l) { STRING_ASSERT(l=0) size=l; else if(buf) size=strlen(buf)+1; else size=0; } + inline int AssertValid(int l) + { + STRING_ASSERT(l=0) size=l; + else if(buf) size=strlen(buf)+1; + else size=0; + } #else - inline int AssertValid(int l) { return 1; } - inline void SetSize(int l=-1) { } + inline int AssertValid(int l) + { + return 1; + } + + inline void SetSize(int l=-1) + { + } #endif //_STRING_DEBUG_ }; -inline void cString::Set(char *string,int pos) +inline void cString::Set(const char *string,int pos) { if(string) { @@ -78,4 +278,4 @@ inline void cString::Set(char *string,int pos) SetSize(); } -#endif // __CSTRING_H__ \ No newline at end of file +#endif // __CSTRING_H__ diff --git a/MechoSoma/VisGeneric/UnkLibrary.h b/MechoSoma/VisGeneric/UnkLibrary.h index a0767840..c08f8830 100644 --- a/MechoSoma/VisGeneric/UnkLibrary.h +++ b/MechoSoma/VisGeneric/UnkLibrary.h @@ -1,7 +1,7 @@ #ifndef __UNKLIBRARY_H__ #define __UNKLIBRARY_H__ -#include "unknown.h" +#include "Unknown.h" #include "BaseDefine.h" typedef cBaseList cUnknownClassList; diff --git a/MechoSoma/VisGeneric/VisGeneric.h b/MechoSoma/VisGeneric/VisGeneric.h index 578e2918..7c68d275 100644 --- a/MechoSoma/VisGeneric/VisGeneric.h +++ b/MechoSoma/VisGeneric/VisGeneric.h @@ -9,24 +9,24 @@ class cInterfaceGraph3d; class cVisGeneric : public cInterfaceVisGeneric { public: - // èíèöèàëèçàöèîííàÿ ÷àñòü + // ����������������� ����� cVisGeneric(); ~cVisGeneric(); - // èíèöèàëèçàöèîííàÿ ÷àñòü + // ����������������� ����� virtual int Create(char *CreateBuffer); virtual int Release(); - // ôóíêöèè äëÿ ðàáîòû ñîáñòâåííî ñ áèáëèîòåêîé âûâîäà + // ������� ��� ������ ���������� � ����������� ������ virtual int PreDraw(int mask=0xFFFFFFFF); virtual int Draw(int mask=0xFFFFFFFF); virtual int PostDraw(int mask=0xFFFFFFFF); virtual int SetTime(int Time); virtual int dSetTime(int dTime); virtual int GetTime(int *Time); - // ôóíêöèè äëÿ ðàáîòû ñî ñöåíîé + // ������� ��� ������ �� ������ virtual cUnknownClass* CreateScene(); virtual int ReleaseScene(cUnknownClass* Scene); virtual int SetScene(cUnknownClass* Scene); - // îáùèå ôóíêöèè äëÿ ðàáîòû îáúåêòàìè cUnknownClass: Camera + // ����� ������� ��� ������ ��������� cUnknownClass: Camera virtual int Release(cUnknownClass *UnkClass); virtual int SetAttribute(cUnknownClass *UnkClass,int Attribute); virtual int ClearAttribute(cUnknownClass *UnkClass,int Attribute); @@ -34,7 +34,7 @@ class cVisGeneric : public cInterfaceVisGeneric virtual int SetPosition(cUnknownClass *UnkClass,const Vect3f *Pos,const Vect3f *AngleGrad=0); virtual int dSetPosition(cUnknownClass *UnkClass,const Vect3f *dPos,const Vect3f *dAngleGrad); virtual int GetPosition(cUnknownClass *UnkClass,Vect3f *Pos,Vect3f *AngleGrad); - // ôóíêöèè äëÿ ðàáîòû ñ îêíîì âûâîäà + // ������� ��� ������ � ����� ������ virtual cUnknownClass* CreateGraph(int xScr,int yScr,int GraphMode=0,int FullScr=0,int ColorBit=16); virtual int ReInitGraph(cUnknownClass *URenderDevice,int xScr,int yScr,int GraphMode=0,int FullScr=0,int ColorBit=16); virtual int GetGraphInfo(cUnknownClass *URenderDevice,int *xScr,int *yScr,int *GraphMode=0,int *FullScr=0,int *ColorBit=0); @@ -44,8 +44,8 @@ class cVisGeneric : public cInterfaceVisGeneric virtual int FlushGraph(cUnknownClass *URenderDevice=0); virtual int ReleaseGraph(cUnknownClass *URenderDevice=0); virtual cInterfaceGraph3d* GetIGraph3d(cUnknownClass *URenderDevice=0); - // ôóíêöèè äëÿ ðàáîòû ñ îáúåêòàìè - virtual int LoadObjectLibrary(char *fname="RESOURCE\\m3d.scb"); + // ������� ��� ������ � ��������� + virtual int LoadObjectLibrary(const std::filesystem::path &path); virtual int FreeObjectLibrary(int kind=0xFFFFFFFF,int type=0xFFFFFFFF); virtual int ReleaseObject(int kind,int type); virtual cUnknownClass* CreateObject(char *fname,char *TexturePath,int Kind=0,int Type=0); @@ -79,7 +79,7 @@ class cVisGeneric : public cInterfaceVisGeneric virtual int ClearRenderObjectSwitch(int attribute=0xFFFFFFFF); virtual int LoadObject(cUnknownClass **UObject,XBuffer &buf,cUnknownClass *UParent=0); virtual int SaveObject(cUnknownClass *UObject,XBuffer &buf); - // ôóíêöèè äëÿ ðàáîòû ñ òî÷å÷íûìè èñòî÷íèêàìè ñâåòà + // ������� ��� ������ � ��������� ����������� ����� virtual cUnknownClass* CreateOmni(const Vect3f *Pos,float radius,const sColor4f *Color); virtual int ReleaseOmni(cUnknownClass *UOmni); virtual int ReleaseOmni(int type); @@ -92,7 +92,7 @@ class cVisGeneric : public cInterfaceVisGeneric virtual int GetOmniSize(cUnknownClass *UOmni,float *radius); virtual int SetOmniVisible(cUnknownClass *UOmni,int visible); virtual int GetOmniVisible(cUnknownClass *UOmni,int visible=0xFFFFFFFF); - // ôóíêöèè äëÿ ðàáîòû ñ êàìåðàìè + // ������� ��� ������ � �������� virtual cUnknownClass* CreateCamera(char *CreateBuffer=0); virtual int AttachCamera(cUnknownClass *UCamera); virtual int DetachCamera(cUnknownClass *UCamera); @@ -113,8 +113,8 @@ class cVisGeneric : public cInterfaceVisGeneric virtual int ConvertorWorldToCamera(cUnknownClass *UCamera,const Vect3f *pw,Vect3f *pv,Vect3f *pe); virtual int ConvertorWorldToViewPort(cUnknownClass *UCamera,const Vect3f *pw,Vect3f *pv,Vect3f *pe); virtual int ReleaseCamera(cUnknownClass *UCamera); - // ôóíêöèè äëÿ ðàáîòû ñ èñòî÷íèêàìè ñâåòà, âëèÿþùèìè íà îñâåùåíèå îáúåêòîâ òåêóùåé ñöåíû - virtual cUnknownClass* CreateLight(int id=-1);// äîáàâëÿåò òî÷å÷íûé èñòî÷íèê + // ������� ��� ������ � ����������� �����, ��������� �� ��������� �������� ������� ����� + virtual cUnknownClass* CreateLight(int id=-1);// ��������� �������� �������� virtual int SetLightPosition(cUnknownClass *ULight,const Vect3f *pos); virtual int GetLightPosition(cUnknownClass *ULight,Vect3f *pos); virtual int SetLightSize(cUnknownClass *ULight,float radius); @@ -122,16 +122,16 @@ class cVisGeneric : public cInterfaceVisGeneric virtual int SetLightColor(cUnknownClass *ULight,const sColor4f *ambient=0,const sColor4f *diffuse=0,const sColor4f *illumination=0); virtual int GetLightColor(cUnknownClass *ULight,sColor4f *ambient=0,sColor4f *diffuse=0,sColor4f *illumination=0); virtual cUnknownClass* GetLight(int id); - virtual int ReleaseLight(cUnknownClass *ULight);// óäàëÿåò òî÷å÷íûé èñòî÷íèê - // ôóíêöèè äëÿ ðàáîòû ñî ñëåäàìè + virtual int ReleaseLight(cUnknownClass *ULight);// ������� �������� �������� + // ������� ��� ������ �� ������� virtual cUnknownClass* CreateTangentTrail(const Vect3f *pos,const sColor4f *c1,const Vect3f *dpos,const sColor4f *c2,float Time=10000.f,float dAnimTime=1.e30f,float Width=2.f); virtual int ReleaseTangentTrail(cUnknownClass* UTangentTrail); - // ñîçäàíèå ìèðà, ïî èíôîðìàöèè â ñêðèïòå fname, number - íîìåð ìèðà - virtual cUnknownClass* CreateWorld(char *fname,int number=0,int track=0,int LoadTerra=0); + // �������� ����, �� ���������� � ������� fname, number - ����� ���� + virtual cUnknownClass* CreateWorld(const std::filesystem::path &path,int number=0,int track=0,int LoadTerra=0); virtual int ReleaseWorld(cUnknownClass *UWorld); virtual int GetPolygonMapAttribute(int x1,int y1,int x2,int y2,int x3,int y3); - virtual cUnknownClass* FindObject(char *name); // ïîèñê îáúåêòà íà ìèðó ïî èìåíè îáúåêòà - virtual cUnknownClass* FindObjectByFileName(char *fname); // ïîèñê îáúåêòà íà ìèðó ïî èìåíè ôàéëà îáúåêòà + virtual cUnknownClass* FindObject(char *name); // ����� ������� �� ���� �� ����� ������� + virtual cUnknownClass* FindObjectByFileName(char *fname); // ����� ������� �� ���� �� ����� ����� ������� virtual cUnknownClass* GetMeshLibrary(cUnknownClass *UScene=0); virtual cUnknownClass* GetCameraList(cUnknownClass *UScene=0); virtual cUnknownClass* GetTileWater(cUnknownClass *UScene=0); @@ -144,8 +144,8 @@ class cVisGeneric : public cInterfaceVisGeneric inline cScene* GetActiveScene() { return Scene; } private: int CurrentTime,PreviousTime; - cUnkClassDynArrayPointer SceneArray; // òåêóùàÿ ñöåíà - cScene *Scene; // óêàçàòåëü íà òåêóùóþ ñöåíó + cUnkClassDynArrayPointer SceneArray; // ������� ����� + cScene *Scene; // ��������� �� ������� ����� inline int GetNumberScene() { return SceneArray.length(); } inline cScene*& GetScene(int number) { return (cScene*&)SceneArray[number]; } diff --git a/MechoSoma/VisGeneric/WinVideo_port.cpp b/MechoSoma/VisGeneric/WinVideo_port.cpp new file mode 100644 index 00000000..5639b0b6 --- /dev/null +++ b/MechoSoma/VisGeneric/WinVideo_port.cpp @@ -0,0 +1,60 @@ +#include "WinVideo.h" + +void sWinVideo::Init() +{ +} + +void sWinVideo::Done() +{ +} + +void sWinVideo::SetWin(void *hWnd,int x,int y,int xsize,int ysize) +{ +} + +int sWinVideo::Open(char *fname) +{ + return 0; +} + +void sWinVideo::Play() +{ +} + +void sWinVideo::Stop() +{ +} + +int sWinVideo::IsPlay() +{ + return 0; +} + +void sWinVideo::WaitEnd() +{ +} + +int sWinVideo::IsComplete() +{ + return 0; +} + +void sWinVideo::FullScreen(int bFullScreen) +{ +} + +void sWinVideo::HideCursor(int hide) +{ +} + +void sWinVideo::GetSize(int *xsize,int *ysize) +{ +} + +void sWinVideo::SetSize(int xsize,int ysize) +{ +} + +void sWinVideo::Close() +{ +} diff --git a/MechoSoma/VisGeneric/drawPolygonShade.cpp b/MechoSoma/VisGeneric/drawPolygonShade.cpp index 3380d774..8f656ccd 100644 --- a/MechoSoma/VisGeneric/drawPolygonShade.cpp +++ b/MechoSoma/VisGeneric/drawPolygonShade.cpp @@ -1,7 +1,7 @@ #include "DrawPolygonShade.h" #include "Maths.h" #include "IncTerra.h" -#include "object3d.h" +#include "Object3d.h" #include "PolyMgr.h" #include @@ -9,9 +9,9 @@ #define SET_COORD_SHADE(p1,p2,p3) \ { \ - xe1=round(p1.xe); ye1=round(p1.ye); w1=round(p1.z)< #include +#else +#include "d3d_port.h" +#endif //#define _PROFILE_D3D @@ -20,6 +24,10 @@ typedef DWORD MD3DERROR; +#ifndef _WIN32 +#define FAILED(hr) (((MD3DERROR)(hr)) < 0) +#endif + typedef struct { DWORD dwTotalBitCount; BOOL bPalette8; @@ -98,7 +106,7 @@ struct MD3DMODE // Function prototypes -------------------------------------------- // -//////array ïîñëå èñïîëüçîâàíèÿ íåîáõîäèìî óíè÷òîæàòü ïðè ïîìîùè delete[] pArray; +//////array ����� ������������� ���������� ���������� ��� ������ delete[] pArray; MD3DERROR d3dEnumVideoMode(int* pnumvideomode,MD3DMODE** ppArray); MD3DERROR d3dGetAvailableVidMem (DWORD* allvideomem); @@ -110,7 +118,7 @@ MD3DERROR d3dQueryCaps( MD3DCAPS Caps, DWORD *dwData ); MD3DERROR d3dGetWindowHandle( HWND *hWnd ); MD3DERROR d3dClear(DWORD); MD3DERROR d3dFlip(bool WaitVerticalBlank=true); -MD3DERROR d3dFlipToGdiSurface();///Âûçûâàòü ïåðåä èñïîëüçîâàíèåì äèàëîãîâ è ò.ä. +MD3DERROR d3dFlipToGdiSurface();///�������� ����� �������������� �������� � �.�. MD3DERROR d3dCreateBackBuffer(); @@ -130,7 +138,7 @@ MD3DERROR d3dTestCooperativeLevel(); #ifdef _PROFILE_D3D void d3dGetTransferMemoryVideo(DWORD& byte_per_frame, DWORD& n256,DWORD& n128,DWORD& n64,DWORD& n32); -#endif _PROFILE_D3D +#endif // _PROFILE_D3D MD3DERROR d3dSetRenderState(D3DRENDERSTATETYPE, DWORD); @@ -235,25 +243,25 @@ MD3DERROR d3dSetFocusLossBehavior( BOOL bSleep ); #define MD3D_OK 0 -// Generic (îáëîì îáùåãî âèäà) +// Generic (����� ������ ����) #define MD3DERR_GENERIC 0x83000001 -#define MD3DERR_NODIRECTDRAW 0x83000002 // Íå óäàëîñü ñîçäàòü DirectDraw-îáúåêò (DX íå óñòàíîâëåí èëè óñòàíîâëåí êðèâî) -#define MD3DERR_NODIRECT3D 0x83000003 // Íåòó 3D-æåëåçà èëè äðàéâåðà -#define MD3DERR_ENUMERATIONFAILED 0x83000004 // Íå óäàëîñü ïîëó÷èòü èíôîðìàöèþ î DirectDraw-äðàéâåðàõ (DX íå óñòàíîâëåí èëè óñòàíîâëåí êðèâî) -#define MD3DERR_NOCOMPATIBLEDEVICES 0x83000005 // Íè îäèí èç íàéäåííûõ àêñåëåðàòîðîâ íå óäîâëåòâîðÿåò íàøèì òðåáîâàíèÿì +#define MD3DERR_NODIRECTDRAW 0x83000002 // �� ������� ������� DirectDraw-������ (DX �� ���������� ��� ���������� �����) +#define MD3DERR_NODIRECT3D 0x83000003 // ���� 3D-������ ��� �������� +#define MD3DERR_ENUMERATIONFAILED 0x83000004 // �� ������� �������� ���������� � DirectDraw-��������� (DX �� ���������� ��� ���������� �����) +#define MD3DERR_NOCOMPATIBLEDEVICES 0x83000005 // �� ���� �� ��������� ������������� �� ������������� ����� ����������� #define MD3DERR_OUTOFMEMORY 0x83000006 -#define MD3DERR_OUTOFVIDEOMEMORY 0x83000007 // Íåäîñòàòî÷íî âèäåîïàìÿòè +#define MD3DERR_OUTOFVIDEOMEMORY 0x83000007 // ������������ ����������� #define MD3DERR_VMCACHEFULL 0x83000008 // Videomemory texture cache is full -#define MD3DERR_BADDISPLAYMODE 0x83000009 // Òåêóùèé ðåæèì äèñïëåÿ íå ïîçâîëÿåò ðåíäåðèòü â îêíî -#define MD3DERR_INVALIDMODE 0x8300000a // Óêàçàííûé ðåæèì äèñïëåÿ íå ïîääåðæèâàåòñÿ -#define MD3DERR_NOZBUFFER 0x8300000b // Íå óäàëîñü ñîçäàòü Z-áóôåð (âîçìîæíî íå õâàòàåò âèäåîïàìÿòè) -#define MD3DERR_NOTINITIALIZED 0x8300000c // md3d íå èíèöèàëèçèðîâàí -#define MD3DERR_ILLEGALCALL 0x8300000d // Ôóíêöèþ íåëüçÿ âûçûâàòü â ýòîì êîíòåêñòå -#define MD3DERR_NOEXCLUSIVEMODE 0x8300000e // Êòî-òî äðóãîé ïîëó÷èë exclusive-äîñòóï ê óñòðîéñòâó -#define MD3DERR_INVALIDPARAM 0x8300000f // Îøèáêà â ïàðàìåòðàõ âûçîâà +#define MD3DERR_BADDISPLAYMODE 0x83000009 // ������� ����� ������� �� ��������� ��������� � ���� +#define MD3DERR_INVALIDMODE 0x8300000a // ��������� ����� ������� �� �������������� +#define MD3DERR_NOZBUFFER 0x8300000b // �� ������� ������� Z-����� (�������� �� ������� �����������) +#define MD3DERR_NOTINITIALIZED 0x8300000c // md3d �� ��������������� +#define MD3DERR_ILLEGALCALL 0x8300000d // ������� ������ �������� � ���� ��������� +#define MD3DERR_NOEXCLUSIVEMODE 0x8300000e // ���-�� ������ ������� exclusive-������ � ���������� +#define MD3DERR_INVALIDPARAM 0x8300000f // ������ � ���������� ������ -#define MD3DERR_UNSUPPORTED 0x83000010 // Çàïðîøåííàÿ îïåðàöèÿ íå ïîääåðæèâàåòñÿ æåëåçîì +#define MD3DERR_UNSUPPORTED 0x83000010 // ����������� �������� �� �������������� ������� // Debugging stuff -------------------------------------------------- // @@ -311,32 +319,32 @@ void __d3dLogMessage( DWORD dwLevel, TCHAR *szFormat, ... ); TCHAR* __d3dBinaryDump( LPVOID, DWORD ); -BOOL d3dIsActive();//Àêòèâíî ëè ïðèëîæåíèå â äàííûé ìîìåíò +BOOL d3dIsActive();//������� �� ���������� � ������ ������ -//Òåêóùèå óñòàíîâêè ýêðàíà +//������� ��������� ������ MD3DERROR d3dGetDisplayMode(DWORD& width,DWORD& height,DWORD& bpp); /* - Ôóíêöèè, ïîçâîëÿþùèè ðèñîâàòü íà BackBuffer - ñ ïîìîùüþ ñòàíäàðòíûõ ôóíêöèé + �������, ����������� �������� �� BackBuffer + � ������� ����������� ������� - GetBackBufferDC - Ïîëó÷èòü hdc è íà÷àòü ðèñîâàòü - ReleaseBackBufferDC óäàëèòü hdc ïîëó÷åííûé ñ ïîìîùüþ GetBackBufferDC + GetBackBufferDC - �������� hdc � ������ �������� + ReleaseBackBufferDC ������� hdc ���������� � ������� GetBackBufferDC - hdc íå äîëæåí íèãäå ãëîáàëüíî ñîõðàíÿòüñÿ, òàê êàê - ýòî âðåìåííûé handle, èìåþùèé ñìûñë òîëüêî îäèí êàäð. + hdc �� ������ ����� ��������� �����������, ��� ��� + ��� ��������� handle, ������� ����� ������ ���� ����. */ MD3DERROR GetBackBufferDC(HDC* hdc); MD3DERROR ReleaseBackBufferDC(HDC hdc); /* - Îïåðàöèè äëÿ ðàáîòû ñ ìóëüòèòåêñòóèðîâàíèåì + �������� ��� ������ � ��������������������� */ -//Ìîæåò ëè êàðòî÷êà ïîääåðæèâàòü ìóëüòèòåêñòóèðîâàíèå +//����� �� �������� ������������ �������������������� BOOL IsMultiTextureSupport(); -//dwVertexTypeDesc îáÿçàòåëüíî äîëæåí èìåòü õîòÿáû îäèí íàáîð òåêñòóðíûõ êîîðäèíàò -//Ýòà ôóíêöèÿ ðàáîòàåò äàæå â ñëó÷àå IsMultiTextureSupport()==FALSE +//dwVertexTypeDesc ����������� ������ ����� ������ ���� ����� ���������� ��������� +//��� ������� �������� ���� � ������ IsMultiTextureSupport()==FALSE MD3DERROR d3dTrianglesIndexed2(DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, diff --git a/MechoSoma/VisGeneric/md3d/d3dSprites.cpp b/MechoSoma/VisGeneric/md3d/d3dSprites.cpp index ba748742..1851477c 100644 --- a/MechoSoma/VisGeneric/md3d/d3dSprites.cpp +++ b/MechoSoma/VisGeneric/md3d/d3dSprites.cpp @@ -7,8 +7,19 @@ // //******************************************************************* -#include "md3d.h" +#include "Md3d.h" +#ifdef _WIN32 #include +#else +#include +#include +#define _ASSERTE assert +#define _ASSERT assert + +#define _CRT_ERROR 0 +#define _RPT0(X, Y) +#define _RPTF0(X, Y) +#endif #include diff --git a/MechoSoma/VisGeneric/md3d/d3d_port.h b/MechoSoma/VisGeneric/md3d/d3d_port.h new file mode 100644 index 00000000..cfeb2476 --- /dev/null +++ b/MechoSoma/VisGeneric/md3d/d3d_port.h @@ -0,0 +1,341 @@ +#ifndef _D3D_PORT_H +#define _D3D_PORT_H + +#include + +#define VOID void + +#ifndef OBJC_BOOL_DEFINED +typedef int BOOL; +#endif + +typedef unsigned char BYTE; +typedef uint32_t DWORD; +typedef float FLOAT; +typedef int32_t LONG; +typedef char TCHAR; +typedef unsigned short WORD; + +typedef void *LPVOID; +typedef WORD *LPWORD; +typedef void *PVOID; + +typedef PVOID HANDLE; +typedef LONG HRESULT; + +typedef HANDLE HDC; +typedef HANDLE HICON; +typedef HANDLE HINSTANCE; +typedef HANDLE HWND; + +#define TRUE 1 +#define FALSE 0 + +typedef struct tagRECT { + LONG left; + LONG top; + LONG right; + LONG bottom; +} RECT, *PRECT, *NPRECT, *LPRECT; + +typedef struct tagPALETTEENTRY { + BYTE peRed; + BYTE peGreen; + BYTE peBlue; + BYTE peFlags; +} PALETTEENTRY, *PPALETTEENTRY, *LPPALETTEENTRY; + +typedef enum _D3DRENDERSTATETYPE +{ + D3DRENDERSTATE_ANTIALIAS = 2, /* D3DANTIALIASMODE */ + D3DRENDERSTATE_ZENABLE = 7, /* D3DZBUFFERTYPE (or TRUE/FALSE for legacy) */ + D3DRENDERSTATE_ZWRITEENABLE = 14, /* TRUE to enable z writes */ + D3DRENDERSTATE_ALPHATESTENABLE = 15, /* TRUE to enable alpha tests */ + D3DRENDERSTATE_LASTPIXEL = 16, /* TRUE for last-pixel on lines */ + D3DRENDERSTATE_SRCBLEND = 19, /* D3DBLEND */ + D3DRENDERSTATE_DESTBLEND = 20, /* D3DBLEND */ + D3DRENDERSTATE_DITHERENABLE = 26, /* TRUE to enable dithering */ + D3DRENDERSTATE_ALPHABLENDENABLE = 27, /* TRUE to enable alpha blending */ + D3DRENDERSTATE_FOGENABLE = 28, /* TRUE to enable fog blending */ + D3DRENDERSTATE_SPECULARENABLE = 29, /* TRUE to enable specular */ + D3DRENDERSTATE_FOGCOLOR = 34, /* D3DCOLOR */ + D3DRENDERSTATE_FOGTABLEMODE = 35, /* D3DFOGMODE */ + D3DRENDERSTATE_FOGSTART = 36, /* Fog start (for both vertex and pixel fog) */ + D3DRENDERSTATE_FOGEND = 37, /* Fog end */ + D3DRENDERSTATE_FOGDENSITY = 38, /* Fog density */ + D3DRENDERSTATE_COLORKEYENABLE = 41, /* TRUE to enable source colorkeyed textures */ + D3DRENDERSTATE_RANGEFOGENABLE = 48, /* Enables range-based fog */ + D3DRENDERSTATE_TEXTUREFACTOR = 60, /* D3DCOLOR used for multi-texture blend */ + D3DRENDERSTATE_CLIPPING = 136, + D3DRENDERSTATE_LIGHTING = 137, + D3DRENDERSTATE_AMBIENT = 139, + D3DRENDERSTATE_FOGVERTEXMODE = 140, + D3DRENDERSTATE_COLORVERTEX = 141, + D3DRENDERSTATE_COLORKEYBLENDENABLE = 144, + D3DRENDERSTATE_DIFFUSEMATERIALSOURCE = 145, + D3DRENDERSTATE_SPECULARMATERIALSOURCE = 146, + D3DRENDERSTATE_AMBIENTMATERIALSOURCE = 147, + D3DRENDERSTATE_EMISSIVEMATERIALSOURCE = 148, + D3DRENDERSTATE_VERTEXBLEND = 151, + D3DRENDERSTATE_CLIPPLANEENABLE = 152, + + D3DRENDERSTATE_FOGTABLESTART = 36, /* Fog table start */ + D3DRENDERSTATE_FOGTABLEEND = 37, /* Fog table end */ + D3DRENDERSTATE_FOGTABLEDENSITY = 38, /* Fog table density */ + +} D3DRENDERSTATETYPE; + +#define D3DRENDERSTATE_TEXTUREPERSPECTIVE (D3DRENDERSTATETYPE)4 +#define D3DRENDERSTATE_FILLMODE (D3DRENDERSTATETYPE)8 +#define D3DRENDERSTATE_SHADEMODE (D3DRENDERSTATETYPE)9 +#define D3DRENDERSTATE_CULLMODE (D3DRENDERSTATETYPE)22 +#define D3DRENDERSTATE_ZFUNC (D3DRENDERSTATETYPE)23 +#define D3DRENDERSTATE_ALPHAREF (D3DRENDERSTATETYPE)24 +#define D3DRENDERSTATE_ALPHAFUNC (D3DRENDERSTATETYPE)25 +#define D3DRENDERSTATE_SUBPIXEL (D3DRENDERSTATETYPE)31 +#define D3DRENDERSTATE_ZBIAS (D3DRENDERSTATETYPE)47 + +typedef enum _D3DBLEND { + D3DBLEND_ZERO = 1, + D3DBLEND_ONE = 2, + D3DBLEND_SRCCOLOR = 3, + D3DBLEND_INVSRCCOLOR = 4, + D3DBLEND_SRCALPHA = 5, + D3DBLEND_INVSRCALPHA = 6, + D3DBLEND_DESTALPHA = 7, + D3DBLEND_INVDESTALPHA = 8, + D3DBLEND_DESTCOLOR = 9, + D3DBLEND_INVDESTCOLOR = 10, + D3DBLEND_SRCALPHASAT = 11, + D3DBLEND_BOTHSRCALPHA = 12, + D3DBLEND_BOTHINVSRCALPHA = 13, +#if(DIRECT3D_VERSION >= 0x0500) + D3DBLEND_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +#endif /* DIRECT3D_VERSION >= 0x0500 */ +} D3DBLEND; + +typedef enum _D3DZBUFFERTYPE { + D3DZB_FALSE = 0, + D3DZB_TRUE = 1, // Z buffering + D3DZB_USEW = 2, // W buffering + D3DZB_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DZBUFFERTYPE; + +typedef float D3DVALUE, *LPD3DVALUE; + +typedef struct IDirect3DDevice3 *LPDIRECT3DDEVICE3; +typedef struct IDirect3DDevice7 *LPDIRECT3DDEVICE7; + +/* + * DDGAMMARAMP + */ +typedef struct _DDGAMMARAMP +{ + WORD red[256]; + WORD green[256]; + WORD blue[256]; +} DDGAMMARAMP; +typedef DDGAMMARAMP *LPDDGAMMARAMP; + +typedef enum _D3DTEXTUREADDRESS { + D3DTADDRESS_WRAP = 1, + D3DTADDRESS_MIRROR = 2, + D3DTADDRESS_CLAMP = 3, + D3DTADDRESS_BORDER = 4, + D3DTADDRESS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DTEXTUREADDRESS; + +#define D3DFVF_XYZ 0x002 +#define D3DFVF_XYZRHW 0x004 +#define D3DFVF_DIFFUSE 0x040 +#define D3DFVF_SPECULAR 0x080 +#define D3DFVF_TEX1 0x100 + +#ifndef D3DCOLOR_DEFINED +typedef DWORD D3DCOLOR; +#define D3DCOLOR_DEFINED +#endif +typedef DWORD *LPD3DCOLOR; + +#define RGB_MAKE(r, g, b) ((D3DCOLOR) (((r) << 16) | ((g) << 8) | (b))) +#define RGBA_MAKE(r, g, b, a) ((D3DCOLOR) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))) + +typedef enum _D3DCULL { + D3DCULL_NONE = 1, + D3DCULL_CW = 2, + D3DCULL_CCW = 3, + D3DCULL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DCULL; + +typedef enum _D3DTEXTURESTAGESTATETYPE +{ + D3DTSS_COLOROP = 1, /* D3DTEXTUREOP - per-stage blending controls for color channels */ + D3DTSS_COLORARG1 = 2, /* D3DTA_* (texture arg) */ + D3DTSS_COLORARG2 = 3, /* D3DTA_* (texture arg) */ + D3DTSS_ALPHAOP = 4, /* D3DTEXTUREOP - per-stage blending controls for alpha channel */ + D3DTSS_ALPHAARG1 = 5, /* D3DTA_* (texture arg) */ + D3DTSS_ALPHAARG2 = 6, /* D3DTA_* (texture arg) */ + D3DTSS_BUMPENVMAT00 = 7, /* D3DVALUE (bump mapping matrix) */ + D3DTSS_BUMPENVMAT01 = 8, /* D3DVALUE (bump mapping matrix) */ + D3DTSS_BUMPENVMAT10 = 9, /* D3DVALUE (bump mapping matrix) */ + D3DTSS_BUMPENVMAT11 = 10, /* D3DVALUE (bump mapping matrix) */ + D3DTSS_TEXCOORDINDEX = 11, /* identifies which set of texture coordinates index this texture */ + D3DTSS_ADDRESS = 12, /* D3DTEXTUREADDRESS for both coordinates */ + D3DTSS_ADDRESSU = 13, /* D3DTEXTUREADDRESS for U coordinate */ + D3DTSS_ADDRESSV = 14, /* D3DTEXTUREADDRESS for V coordinate */ + D3DTSS_BORDERCOLOR = 15, /* D3DCOLOR */ + D3DTSS_MAGFILTER = 16, /* D3DTEXTUREMAGFILTER filter to use for magnification */ + D3DTSS_MINFILTER = 17, /* D3DTEXTUREMINFILTER filter to use for minification */ + D3DTSS_MIPFILTER = 18, /* D3DTEXTUREMIPFILTER filter to use between mipmaps during minification */ + D3DTSS_MIPMAPLODBIAS = 19, /* D3DVALUE Mipmap LOD bias */ + D3DTSS_MAXMIPLEVEL = 20, /* DWORD 0..(n-1) LOD index of largest map to use (0 == largest) */ + D3DTSS_MAXANISOTROPY = 21, /* DWORD maximum anisotropy */ + D3DTSS_BUMPENVLSCALE = 22, /* D3DVALUE scale for bump map luminance */ + D3DTSS_BUMPENVLOFFSET = 23, /* D3DVALUE offset for bump map luminance */ + D3DTSS_TEXTURETRANSFORMFLAGS = 24, /* D3DTEXTURETRANSFORMFLAGS controls texture transform */ + D3DTSS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DTEXTURESTAGESTATETYPE; + +typedef enum _D3DTEXTUREOP +{ +// Control + D3DTOP_DISABLE = 1, // disables stage + D3DTOP_SELECTARG1 = 2, // the default + D3DTOP_SELECTARG2 = 3, + +// Modulate + D3DTOP_MODULATE = 4, // multiply args together + D3DTOP_MODULATE2X = 5, // multiply and 1 bit + D3DTOP_MODULATE4X = 6, // multiply and 2 bits + +// Add + D3DTOP_ADD = 7, // add arguments together + D3DTOP_ADDSIGNED = 8, // add with -0.5 bias + D3DTOP_ADDSIGNED2X = 9, // as above but left 1 bit + D3DTOP_SUBTRACT = 10, // Arg1 - Arg2, with no saturation + D3DTOP_ADDSMOOTH = 11, // add 2 args, subtract product + // Arg1 + Arg2 - Arg1*Arg2 + // = Arg1 + (1-Arg1)*Arg2 + +// Linear alpha blend: Arg1*(Alpha) + Arg2*(1-Alpha) + D3DTOP_BLENDDIFFUSEALPHA = 12, // iterated alpha + D3DTOP_BLENDTEXTUREALPHA = 13, // texture alpha + D3DTOP_BLENDFACTORALPHA = 14, // alpha from D3DRENDERSTATE_TEXTUREFACTOR + // Linear alpha blend with pre-multiplied arg1 input: Arg1 + Arg2*(1-Alpha) + D3DTOP_BLENDTEXTUREALPHAPM = 15, // texture alpha + D3DTOP_BLENDCURRENTALPHA = 16, // by alpha of current color + +// Specular mapping + D3DTOP_PREMODULATE = 17, // modulate with next texture before use + D3DTOP_MODULATEALPHA_ADDCOLOR = 18, // Arg1.RGB + Arg1.A*Arg2.RGB + // COLOROP only + D3DTOP_MODULATECOLOR_ADDALPHA = 19, // Arg1.RGB*Arg2.RGB + Arg1.A + // COLOROP only + D3DTOP_MODULATEINVALPHA_ADDCOLOR = 20, // (1-Arg1.A)*Arg2.RGB + Arg1.RGB + // COLOROP only + D3DTOP_MODULATEINVCOLOR_ADDALPHA = 21, // (1-Arg1.RGB)*Arg2.RGB + Arg1.A + // COLOROP only + +// Bump mapping + D3DTOP_BUMPENVMAP = 22, // per pixel env map perturbation + D3DTOP_BUMPENVMAPLUMINANCE = 23, // with luminance channel + // This can do either diffuse or specular bump mapping with correct input. + // Performs the function (Arg1.R*Arg2.R + Arg1.G*Arg2.G + Arg1.B*Arg2.B) + // where each component has been scaled and offset to make it signed. + // The result is replicated into all four (including alpha) channels. + // This is a valid COLOROP only. + D3DTOP_DOTPRODUCT3 = 24, + + D3DTOP_FORCE_DWORD = 0x7fffffff, +} D3DTEXTUREOP; + +/* + * Values for COLORARG1,2 and ALPHAARG1,2 texture blending operations + * set in texture processing stage controls in D3DRENDERSTATE. + */ +#define D3DTA_SELECTMASK 0x0000000f // mask for arg selector +#define D3DTA_DIFFUSE 0x00000000 // select diffuse color +#define D3DTA_CURRENT 0x00000001 // select result of previous stage +#define D3DTA_TEXTURE 0x00000002 // select texture color +#define D3DTA_TFACTOR 0x00000003 // select RENDERSTATE_TEXTUREFACTOR +#define D3DTA_SPECULAR 0x00000004 // select specular color +#define D3DTA_COMPLEMENT 0x00000010 // take 1.0 - x +#define D3DTA_ALPHAREPLICATE 0x00000020 // replicate alpha to color components + +typedef enum _D3DTEXTUREMINFILTER +{ + D3DTFN_POINT = 1, // nearest + D3DTFN_LINEAR = 2, // linear interpolation + D3DTFN_ANISOTROPIC = 3, // + D3DTFN_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum +} D3DTEXTUREMINFILTER; + +typedef enum _D3DTEXTUREMIPFILTER +{ + D3DTFP_NONE = 1, // mipmapping disabled (use MAG filter) + D3DTFP_POINT = 2, // nearest + D3DTFP_LINEAR = 3, // linear interpolation + D3DTFP_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum +} D3DTEXTUREMIPFILTER; + +typedef enum _D3DANTIALIASMODE { + D3DANTIALIAS_NONE = 0, + D3DANTIALIAS_SORTDEPENDENT = 1, + D3DANTIALIAS_SORTINDEPENDENT = 2, + D3DANTIALIAS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DANTIALIASMODE; + +typedef enum _D3DSHADEMODE { + D3DSHADE_FLAT = 1, + D3DSHADE_GOURAUD = 2, + D3DSHADE_PHONG = 3, + D3DSHADE_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DSHADEMODE; + +typedef enum _D3DFILLMODE { + D3DFILL_POINT = 1, + D3DFILL_WIREFRAME = 2, + D3DFILL_SOLID = 3, + D3DFILL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DFILLMODE; + +typedef enum _D3DCMPFUNC { + D3DCMP_NEVER = 1, + D3DCMP_LESS = 2, + D3DCMP_EQUAL = 3, + D3DCMP_LESSEQUAL = 4, + D3DCMP_GREATER = 5, + D3DCMP_NOTEQUAL = 6, + D3DCMP_GREATEREQUAL = 7, + D3DCMP_ALWAYS = 8, + D3DCMP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DCMPFUNC; + +typedef enum _D3DFOGMODE { + D3DFOG_NONE = 0, + D3DFOG_EXP = 1, + D3DFOG_EXP2 = 2, + D3DFOG_LINEAR = 3, + D3DFOG_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DFOGMODE; + +// Values for material source +typedef enum _D3DMATERIALCOLORSOURCE +{ + D3DMCS_MATERIAL = 0, // Color from material is used + D3DMCS_COLOR1 = 1, // Diffuse vertex color is used + D3DMCS_COLOR2 = 2, // Specular vertex color is used + D3DMCS_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum +} D3DMATERIALCOLORSOURCE; + +// The D3DVERTEXBLENDFLAGS type is used with D3DRENDERSTATE_VERTEXBLEND state. +// +typedef enum _D3DVERTEXBLENDFLAGS +{ + D3DVBLEND_DISABLE = 0, // Disable vertex blending + D3DVBLEND_1WEIGHT = 1, // blend between 2 matrices + D3DVBLEND_2WEIGHTS = 2, // blend between 3 matrices + D3DVBLEND_3WEIGHTS = 3, // blend between 4 matrices +} D3DVERTEXBLENDFLAGS; + +#endif \ No newline at end of file diff --git a/MechoSoma/VisGeneric/vgGraph.cpp b/MechoSoma/VisGeneric/vgGraph.cpp index eb651c88..fd499347 100644 --- a/MechoSoma/VisGeneric/vgGraph.cpp +++ b/MechoSoma/VisGeneric/vgGraph.cpp @@ -1,10 +1,10 @@ #include "VisGeneric.h" #include "PolyMgr.h" #include "RenderDevice.h" -#include "xgr.h" -#include "md3d.h" +#include "XGR.h" +#include "Md3d.h" -// ôóíêöèè äëÿ ðàáîòû ñ îêíîì âûâîäà +// ������� ��� ������ � ����� ������ cUnknownClass* cVisGeneric::CreateGraph(int xScr,int yScr,int GraphMode,int FullScr,int ColorBit) { assert(P3D); diff --git a/MechoSoma/VisGeneric/vgObject.cpp b/MechoSoma/VisGeneric/vgObject.cpp index 15bc0a3a..7c02b69d 100644 --- a/MechoSoma/VisGeneric/vgObject.cpp +++ b/MechoSoma/VisGeneric/vgObject.cpp @@ -2,10 +2,10 @@ #include "Dispatcher.h" #include "Frame.h" -int cVisGeneric::LoadObjectLibrary(char *fname) +int cVisGeneric::LoadObjectLibrary(const std::filesystem::path &path) { assert(Scene); - Scene->GetM3D()->LoadLib(fname); + Scene->GetM3D()->LoadLib(path); return 0; } int cVisGeneric::FreeObjectLibrary(int kind,int type) @@ -249,7 +249,7 @@ int cVisGeneric::ClearRenderObjectSwitch(int attribute) return 0; } cUnknownClass* cVisGeneric::FindObjectByFileName(char *fname) -{ // ïîèñê îáúåêòà íà ìèðó ïî èìåíè ôàéëà îáúåêòà +{ // ����� ������� �� ���� �� ����� ����� ������� if(fname==0||fname[0]==0) return 0; return GetActiveScene()->GetM3D()->FindObjectByFileName(fname); } diff --git a/MechoSoma/VisGeneric/vgWorld.cpp b/MechoSoma/VisGeneric/vgWorld.cpp index daba4d24..f69b28bd 100644 --- a/MechoSoma/VisGeneric/vgWorld.cpp +++ b/MechoSoma/VisGeneric/vgWorld.cpp @@ -5,7 +5,7 @@ #include "TileMap.h" #include "BaseLight.h" -cUnknownClass* cVisGeneric::CreateWorld(char *fname,int number,int track,int LoadTerra) +cUnknownClass* cVisGeneric::CreateWorld(const std::filesystem::path &path,int number,int track,int LoadTerra) { if(LoadTerra) { @@ -14,7 +14,7 @@ cUnknownClass* cVisGeneric::CreateWorld(char *fname,int number,int track,int Loa vMap_load3Buf(0,0,track); } assert(GetActiveScene()); - Scene->LoadWorld(fname,number,track); + Scene->LoadWorld(path,number,track); return GetActiveScene(); } int cVisGeneric::ReleaseWorld(cUnknownClass *UWorld) diff --git a/MechoSoma/VisGeneric/xgr.cpp b/MechoSoma/VisGeneric/xgr.cpp index 2d9774f9..8e379f8d 100644 --- a/MechoSoma/VisGeneric/xgr.cpp +++ b/MechoSoma/VisGeneric/xgr.cpp @@ -1,8 +1,8 @@ -#include "_xtool.h" -#include "xgr.h" -#include "assert.h" +#include "xtool.h" +#include "XGR.h" +#include -#include "md3d.h" +#include "Md3d.h" int RenderMode=XGRAPH_HICOLOR; diff --git a/MechoSoma/XMath/XMath.cpp b/MechoSoma/XMath/XMath.cpp index 9192ca91..ccc34891 100644 --- a/MechoSoma/XMath/XMath.cpp +++ b/MechoSoma/XMath/XMath.cpp @@ -16,7 +16,7 @@ #include #include -#include "_xtool.h" +#include "xtool.h" #include "xmath.h" #pragma warning(disable : 4073 ) diff --git a/MechoSoma/XMath/-xmath.h b/MechoSoma/XMath/xmath.h similarity index 99% rename from MechoSoma/XMath/-xmath.h rename to MechoSoma/XMath/xmath.h index 3d10c37b..caab6c71 100644 --- a/MechoSoma/XMath/-xmath.h +++ b/MechoSoma/XMath/xmath.h @@ -6,6 +6,8 @@ #ifndef __XMATH_H__ #define __XMATH_H__ +#include + #ifndef _XMATH_NO_IOSTREAM #include using std::istream; @@ -13,6 +15,18 @@ using std::ostream; using std::endl; #endif +#ifndef FORCEINLINE +#ifdef _MSC_VER + #if _MSC_VER == 1100 //MSVisual C++ 5.0 + #define FORCEINLINE inline + #else + #define FORCEINLINE __forceinline + #endif +#else +#define FORCEINLINE inline //__attribute__((always_inline)) +#endif //_MSC_VER +#endif //FORCEINLINE + /////////////////////////////////////////////////////////////////////////////// // Structures predefenition /////////////////////////////////////////////////////////////////////////////// @@ -61,11 +75,7 @@ const float FLT_INF = 1.e+30f; const float FLT_COMPARE_TOLERANCE = 1.e-5f; -#if _MSC_VER == 1100 /* if MSVisual C++ 5.0 */ -#define xm_inline inline -#else -#define xm_inline __forceinline -#endif //_MSC_VER +#define xm_inline FORCEINLINE /////////////////////////////////////////////////////////////////////////////// // @@ -76,6 +86,7 @@ const float FLT_COMPARE_TOLERANCE = 1.e-5f; #ifndef __ROUND__ #define __ROUND__ +#ifdef _MSC_VER xm_inline int round(double x) { int a; @@ -95,6 +106,7 @@ xm_inline int round(float x) } return a; } +#endif template xm_inline T sqr(const T& x){ return x*x; } @@ -393,7 +405,7 @@ class Mat2f xm_inline Vect2f invXform(const Vect2f& v) const { return Vect2f(v.x*xx + v.y*yx, v.x*xy + v.y*yy); } }; // forward transform -xm_inline const Vect2f operator* (const Mat2f& m, const Vect2f& v) { return Vect2f(v) *= m; } +xm_inline const Vect2f operator* (const Mat2f& m, const Vect2f& v) { Vect2f t(v); return t *= m; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -419,7 +431,7 @@ class MatX2f friend Vect2f& operator *=(Vect2f& v, const MatX2f& m) { v *= m.rot; v += m.trans; return v; } }; // forward transform -xm_inline const Vect2f operator* (const MatX2f& m, const Vect2f& v) { return Vect2f(v) *= m; } +xm_inline const Vect2f operator* (const MatX2f& m, const Vect2f& v) { Vect2f t(v); return t *= m; } @@ -554,7 +566,7 @@ class Vect3f xm_inline Vect3f& interpolate(const Vect3f& u, const Vect3f& v, float lambda); // (1-lambda)*u + lambda*v // I/O operations ////////////////////////////////////// - friend ostream& operator<< (ostream& os, const Vect3f& v); + friend ostream& operator<< (ostream& os, Vect3f& v); friend istream& operator>> (istream& is, Vect3f& v); friend XStream& operator<= (XStream& s,const Vect3f& v); @@ -2879,6 +2891,8 @@ Mat3f& Mat3f::set(float angle, eAxis axis) yx = 0; yy = 1; yz = 0; zx = -salpha; zy = 0; zz = calpha; break; + case W_AXIS: + break; } return *this; } @@ -3372,6 +3386,8 @@ Mat3d& Mat3d::set(double angle, eAxis axis) yx = 0; yy = 1; yz = 0; zx = -salpha; zy = 0; zz = calpha; break; + case W_AXIS: + break; } return *this; } diff --git a/MechoSoma/XTool/Statistics.h b/MechoSoma/XTool/Statistics.h new file mode 100644 index 00000000..1db3feee --- /dev/null +++ b/MechoSoma/XTool/Statistics.h @@ -0,0 +1,186 @@ +#ifndef __STATISTICS_H__ +#define __STATISTICS_H__ + +#ifdef __APPLE__ +#define __forceinline inline +#define __int64 int64_t +#endif + +// Use to profile memory by start_timers +#ifdef _DEBUG +//@caiiiycuk +//#define USE_TIMERS_TO_PROFILE_MEMORY +#endif + +struct AllocationStatistics +{ + int size; + int blocks; + int operations; + + AllocationStatistics() { size = blocks = operations = 0; } + AllocationStatistics& operator += (const AllocationStatistics& data) { size += data.size; blocks += data.blocks; operations += data.operations; return *this; } + AllocationStatistics& operator -= (const AllocationStatistics& data) { size -= data.size; blocks -= data.blocks; operations -= data.operations; return *this; } + + // @caiiiycuk + // static AllocationStatistics dbg_hook_data; +}; + + +///////////////////////////////////////// +// Memory allocation monitoring +// Using: +// Switch "memory" in command line -> file +// memory dump. +///////////////////////////////////////// +#ifndef _FINAL_VERSION_ + +struct AllocationAccumulator ; +//{ +// int size, blocks; +// int total_size; +// AllocationAccumulator() { init(); } +// void init() { total_size = size = blocks = 0; } +//}; + +void allocation_tracking(char* title); +void allocation_tracking(char* title, AllocationAccumulator* state); + +#else // _FINAL_VERSION_ + +inline void allocation_tracking(char* title){} +inline void allocation_tracking(char* title, struct AllocationAccumulator* state){} + +#endif // _FINAL_VERSION_ + +int total_memory_used(); // count by pages, works under release and finale + + +///////////////////////////////////////// +// Profiler +///////////////////////////////////////// +#ifdef _FINAL_VERSION_ + +#define start_timer(title, group) +#define stop_timer(title, group) +#define create_timer(title, group) +#define start_created_timer(title, group) +#define start_autostop_timer(title, group) +#define statistics_add(title, group, x) + +inline void profiler_start_stop(){} +inline void profiler_quant(){} +inline void show_profile(const char* text) {} +inline void show_debug_window(const char* text, int sx, int sy) {} +inline void hide_debug_window() {} + +#else //_FINAL_VERSION_ + +__int64 getRDTSC(void); + +struct TimerData +{ + __int64 t; + __int64 dt_sum; + int n; + __int64 dt_max, dt_min; + __int64 t_min, t_max; + + char* title; + int group; + int timer_data; + + AllocationStatistics accumulated_alloc; + AllocationStatistics last_alloc; + + TimerData(char* title_ = 0, int group_ = 0, int dont_attach = 0); + + __forceinline void start() + { + t = getRDTSC(); + #ifdef USE_TIMERS_TO_PROFILE_MEMORY + last_alloc = AllocationStatistics::dbg_hook_data; + #endif + } + __forceinline void stop() + { + t = getRDTSC() - t; + dt_sum += t; + + if(dt_max < t){ + dt_max = t; + t_max = getRDTSC(); + } + if(dt_min > t){ + dt_min = t; + t_min = getRDTSC(); + } + n++; + + #ifdef USE_TIMERS_TO_PROFILE_MEMORY + accumulated_alloc += AllocationStatistics::dbg_hook_data; + accumulated_alloc -= last_alloc; + #endif + } + virtual void clear(); + TimerData& operator += (const TimerData& t); + virtual void print(XBuffer& buf); +}; + +class StatisticalData : public TimerData +{ + double x_sum, x2_sum, x_min, x_max; +public: + StatisticalData(char* title_ = 0, int group_ = 0) : TimerData(title_, group_, 0) { timer_data = 0; clear(); } + void clear() { TimerData::clear(); x_sum = x2_sum = 0; x_max = -1e15; x_min = 1e15; } + void add(double x) { n++; x_sum += x; if(x_min > x){ x_min = x; t_min = getRDTSC(); } if(x_max < x){ x_max = x; t_max = getRDTSC(); } x2_sum += x*x; } + void print(XBuffer& buf); + double avr() const { return n ? x_sum/n : 0; } + double sigma() const { double d2 = (x2_sum - x_sum*x_sum/n); return n > 1 && d2 > 0 ? sqrt(d2/((double)n*(n - 1))) : 0; } +}; + +class Profiler +{ + class TimerDataList& timers; + __int64 ticks; + int frames; + int milliseconds; + TimerData total_data; + int started; + int memory; +public: + Profiler(); + ~Profiler(); + void attach(TimerData* td); + void start_stop(); + void quant(); + void print(XBuffer& buf); +}; + +Profiler& get_profiler(); + +class AutoStopTimer +{ + TimerData& timer; +public: + AutoStopTimer(TimerData& timer_) : timer(timer_) {} + ~AutoStopTimer() { timer.stop(); } +}; + +#define start_timer(title, group) static TimerData timer_##title##group(#title, group); timer_##title##group.start(); +#define stop_timer(title, group) timer_##title##group.stop(); +#define create_timer(title, group) static TimerData timer_##title##group(#title, group); +#define start_created_timer(title, group) timer_##title##group.start(); +#define start_autostop_timer(title, group) static TimerData timer_##title##group(#title, group); timer_##title##group.start(); AutoStopTimer autostop_timer_##title##group(timer_##title##group); +#define statistics_add(title, group, x) { static StatisticalData timer_##title##group(#title, group); timer_##title##group.add(x); } + +inline void profiler_start_stop() { get_profiler().start_stop(); } +inline void profiler_quant() { get_profiler().quant(); } +void show_profile(const char* text); +void show_debug_window(const char* text, int sx, int sy); +void hide_debug_window(); + +#endif //_FINAL_VERSION_ + + +#endif // __STATISTICS_H__ diff --git a/MechoSoma/XTool/filesystem.cpp b/MechoSoma/XTool/filesystem.cpp new file mode 100644 index 00000000..b9bb264b --- /dev/null +++ b/MechoSoma/XTool/filesystem.cpp @@ -0,0 +1,58 @@ +#include "filesystem.h" + +#include +#include +#include + +std::filesystem::path file::normalize_path(const char* input) +{ + namespace fs = std::filesystem; + + const auto current_locale = std::locale(); + auto comparator = [¤t_locale](char left, char right) { + return std::tolower(left, current_locale) == std::tolower(right, current_locale); + }; + + std::string t{input}; + for (auto& c : t) + { + if (c == '\\') + { + c = '/'; + } + } + fs::path input_path{t}; + + auto result_path = fs::current_path(); + auto result_path_item = result_path.begin(); + + for (const auto& part : input_path) + { + const auto part_name = part.filename().string(); + const auto name = result_path_item->filename().string(); + if (std::equal(part_name.cbegin(), part_name.cend(), name.cbegin(), comparator)) + { + result_path_item++; + continue; + } + + bool is_found = false; + for (const auto& entry : fs::directory_iterator{result_path}) + { + const auto entry_name = entry.path().filename().string(); + if (std::equal(part_name.cbegin(), part_name.cend(), entry_name.cbegin(), comparator)) + { + result_path = entry.path(); + is_found = true; + break; + } + } + + if (!is_found) + { + return input_path; + } + } + + return result_path.string(); +} diff --git a/MechoSoma/XTool/filesystem.h b/MechoSoma/XTool/filesystem.h new file mode 100644 index 00000000..743bdc1b --- /dev/null +++ b/MechoSoma/XTool/filesystem.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +namespace file +{ + +std::filesystem::path normalize_path(const char* input); + +} diff --git a/MechoSoma/XTool/inzip.cpp b/MechoSoma/XTool/inzip.cpp new file mode 100644 index 00000000..7f057fac --- /dev/null +++ b/MechoSoma/XTool/inzip.cpp @@ -0,0 +1,570 @@ +#include "xtool.h" + +#include +#include + +typedef unsigned char uchar; +typedef unsigned short ushort; +//typedef unsigned long ulong; + +struct huft; + +#ifdef _LARGE_MODEL_ +#define WSIZE 0x4000U +#define OUTBUFSIZ 0x800U +#else +#define WSIZE 0x8000U +#define OUTBUFSIZ 0x1000U +#endif + +#define MIN_MATCH 3 +#define MAX_MATCH 258 + +#define DYN_ALLOC +#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) +#define MAX_DIST (WSIZE-MIN_LOOKAHEAD) + +#define UNKNOWN (-1) +#define BINARY 0 +#define ASCII 1 + +#define STORE 0 +#define DEFLATE 8 + + +#define Buf_size (8 * 2 * sizeof(char)) + +#define PUTSHORT(w) \ +{ if(out_offset < out_size-1){ \ + out_buf[out_offset++] = (char)((w) & 0xFF); \ + out_buf[out_offset++] = (char)((ushort)(w) >> 8); \ + } else { \ + flush_outbuf((w),2); \ + } \ +} + +#define PUTBYTE(b) \ +{ if(out_offset < out_size){ \ + out_buf[out_offset++] = (char)(b); \ + } else { \ + flush_outbuf((b),1); \ + } \ +} + +// ---------- EXTERN SECTION ---------- + +extern unsigned int window_size; + +// ---------- PROTOTYPE SECTION ---------- + +unsigned int deflate(void); + +void lm_init(int pack_level,ushort* flags); +void bi_init(void); +void bi_windup(void); +unsigned bi_reverse(unsigned code,int len); + +void ct_init(ushort* attr,int* method); + +void send_bits(int value,int length); +void flush_outbuf(unsigned w,unsigned bytes); +int mem_read(char* b,unsigned bsize); +void copy_block(char* buf,unsigned len,int header); +void free_data(void); + +// ---------- DEFINITION SECTION ---------- + +unsigned short bi_buf; + +char IErrMsg[] = "ZIP Internal Error"; + +int level = 6; +int verbose = 0; +int bi_valid; + +char* in_buf; +char* out_buf; + +unsigned in_offset; +unsigned out_offset; +unsigned in_size; +unsigned out_size; + +int (*read_buf)(char* buf,unsigned size); + +ulong ZIP_compress(char* trg,ulong trgsize,char* src,ulong srcsize) +{ + ushort att = (ushort)UNKNOWN; + ushort flags = 0; + int method = DEFLATE; + + read_buf = mem_read; + in_buf = src; + in_size = (unsigned)srcsize; + in_offset = 0; + + out_buf = trg; + out_size = (unsigned)trgsize; + out_offset = 2 + 4; + window_size = 0L; + + if(out_size <= 6) return 0; + + bi_init(); + ct_init(&att,&method); + lm_init((level != 0 ? level : 1),&flags); + deflate(); + free_data(); + window_size = 0L; + + trg[0] = (char)(method & 0xFF); + trg[1] = (char)((method >> 8) & 0xFF); + + *(unsigned int*)(trg + 2) = (unsigned int)srcsize; + return (unsigned int)out_offset; +} + +void bi_init(void) +{ + bi_buf = 0; + bi_valid = 0; +} + +void send_bits(int value,int length) +{ + if(bi_valid > (int)Buf_size - length){ + bi_buf |= (value << bi_valid); + PUTSHORT(bi_buf); + bi_buf = (ushort)value >> (Buf_size - bi_valid); + bi_valid += length - Buf_size; + } + else { + bi_buf |= value << bi_valid; + bi_valid += length; + } +} + +unsigned bi_reverse(unsigned code,int len) +{ + unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} + +void flush_outbuf(unsigned w,unsigned bytes) +{ + //ErrH.Abort(IErrMsg); +} + +void bi_windup(void) +{ + if(bi_valid > 8){ + PUTSHORT(bi_buf); + } + else + if(bi_valid > 0){ + PUTBYTE(bi_buf); + } + bi_buf = 0; + bi_valid = 0; +} + +void copy_block(char* buf,unsigned len,int header) +{ + bi_windup(); + if(header){ + PUTSHORT((ushort)len); + PUTSHORT((ushort)~len); + } + if(out_offset + len > out_size){ + //ErrH.Abort(IErrMsg); + } + else { + memcpy(out_buf + out_offset, buf, len); + out_offset += len; + } +} + +int mem_read(char* b,unsigned bsize) +{ + if(in_offset < in_size){ + unsigned int block_size = in_size - in_offset; + if (block_size > (unsigned int)bsize) block_size = (unsigned int)bsize; + memcpy(b, in_buf + in_offset, (unsigned)block_size); + in_offset += (unsigned)block_size; + return (int)block_size; + } + else { + return 0; + } +} + + + +#ifdef _LARGE_MODEL_ +#define HASH_BITS 14 +#else +#define HASH_BITS 15 +#endif + +#define HASH_SIZE (unsigned short)(1< 9) ErrH.Abort(IErrMsg); + + sliding = 0; + if(window_size == 0L){ + sliding = 1; + window_size = (unsigned int)2L*WSIZE; + } + +#ifdef DYN_ALLOC + if(window == NULL) + window = new uchar[WSIZE * 2]; + if(prev == NULL){ + prev = new Pos[WSIZE]; + head = new Pos[HASH_SIZE]; + } +#endif + + head[HASH_SIZE-1] = NIL; + memset((char*)head,NIL,(unsigned)(HASH_SIZE - 1) * sizeof(*head)); + + max_lazy_match = configuration_table[pack_level].max_lazy; + good_match = configuration_table[pack_level].good_length; + nice_match = configuration_table[pack_level].nice_length; + max_chain_length = configuration_table[pack_level].max_chain; + if(pack_level == 1){ + *flags |= FAST; + } else + if(pack_level == 9){ + *flags |= SLOW; + } + strstart = 0; + block_start = 0L; + + j = WSIZE; + + if(sizeof(int) > 2) + j <<= 1; + + lookahead = (*read_buf)((char*)window, j); + + if(lookahead == 0 || lookahead == (unsigned)EOF){ + eofile = 1, lookahead = 0; + return; + } + eofile = 0; + while(lookahead < MIN_LOOKAHEAD && !eofile) fill_window(); + + ins_h = 0; + for(j=0; j (IPos)MAX_DIST ? strstart - (IPos)MAX_DIST : NIL; + + uchar *strend = window + strstart + MAX_MATCH; + uchar scan_end1 = scan[best_len-1]; + uchar scan_end = scan[best_len]; + if(prev_length >= good_match){ + chain_length >>= 2; + } + do { + match = window + cur_match; + if(match[best_len] != scan_end || + match[best_len-1] != scan_end1 || + *match != *scan || + *++match != scan[1]) continue; + + scan += 2, match++; + do { + } while(*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + len = MAX_MATCH - (int)(strend - scan); + scan = strend - MAX_MATCH; + if(len > best_len){ + match_start = cur_match; + best_len = len; + if(len >= nice_match) break; + scan_end1 = scan[best_len-1]; + scan_end = scan[best_len]; + } + } while((cur_match = prev[cur_match & WMASK]) > limit && --chain_length != 0); + return best_len; +} + +#define check_match(start, match, length) + +void fill_window(void) +{ + unsigned n, m; + unsigned more = (unsigned)(window_size - (unsigned int)lookahead - (unsigned int)strstart); + if(more == (unsigned)EOF){ + more--; + } else + if(strstart >= WSIZE+MAX_DIST && sliding){ + memcpy((char*)window, (char*)window+WSIZE, (unsigned)WSIZE); + match_start -= WSIZE; + strstart -= WSIZE; /* we now have strstart >= MAX_DIST: */ + + block_start -= (int) WSIZE; + + for(n = 0; n < HASH_SIZE; n++){ + m = head[n]; + head[n] = (Pos)(m >= WSIZE ? m-WSIZE : NIL); + } + for(n = 0; n < WSIZE; n++){ + m = prev[n]; + prev[n] = (Pos)(m >= WSIZE ? m-WSIZE : NIL); + } + more += WSIZE; + if(verbose) putc('.', stderr); + } + if(!eofile){ + n = (*read_buf)((char*)window+strstart+lookahead, more); + if(n == 0 || n == (unsigned)EOF){ + eofile = 1; + } + else { + lookahead += n; + } + } +} + +#define FLUSH_BLOCK(eof) \ + flush_block(block_start >= 0L ? (char*)&window[(unsigned)block_start] : \ + (char*)NULL,(int)strstart - block_start,(eof)) + +unsigned int deflate_fast(void) +{ + IPos hash_head; + int flush; + unsigned match_length = 0; + + prev_length = MIN_MATCH-1; + while(lookahead != 0){ + INSERT_STRING(strstart, hash_head); + if(hash_head != NIL && strstart - hash_head <= MAX_DIST){ + match_length = longest_match (hash_head); + if(match_length > lookahead) match_length = lookahead; + } + if(match_length >= MIN_MATCH){ + check_match(strstart, match_start, match_length); + flush = ct_tally(strstart-match_start, match_length - MIN_MATCH); + lookahead -= match_length; + if(match_length <= max_insert_length){ + match_length--; + do { + strstart++; + INSERT_STRING(strstart, hash_head); + } while(--match_length != 0); + strstart++; + } + else { + strstart += match_length; + match_length = 0; + ins_h = window[strstart]; + UPDATE_HASH(ins_h, window[strstart+1]); + } + } + else { + flush = ct_tally (0, window[strstart]); + lookahead--; + strstart++; + } + if(flush) FLUSH_BLOCK(0), block_start = strstart; + while(lookahead < MIN_LOOKAHEAD && !eofile) fill_window(); + } + return FLUSH_BLOCK(1); +} + +unsigned int deflate(void) +{ + IPos hash_head; + IPos prev_match; + int flush; + int match_available = 0; + unsigned match_length = MIN_MATCH - 1; + + if(level <= 3) return deflate_fast(); + + while(lookahead != 0){ + INSERT_STRING(strstart, hash_head); + + prev_length = match_length, prev_match = match_start; + match_length = MIN_MATCH-1; + + if(hash_head != NIL && prev_length < max_lazy_match && strstart - hash_head <= MAX_DIST){ + match_length = longest_match (hash_head); + if(match_length > lookahead) match_length = lookahead; + + if(match_length == MIN_MATCH && strstart-match_start > TOO_FAR){ + match_length--; + } + } + if(prev_length >= MIN_MATCH && match_length <= prev_length){ + check_match(strstart-1, prev_match, prev_length); + flush = ct_tally(strstart-1-prev_match, prev_length - MIN_MATCH); + lookahead -= prev_length-1; + prev_length -= 2; + do { + strstart++; + INSERT_STRING(strstart, hash_head); + } while(--prev_length != 0); + match_available = 0; + match_length = MIN_MATCH-1; + strstart++; + if(flush) FLUSH_BLOCK(0), block_start = strstart; + } + else + if(match_available){ + if(ct_tally (0, window[strstart-1])){ + FLUSH_BLOCK(0), block_start = strstart; + } + strstart++; + lookahead--; + } + else { + match_available = 1; + strstart++; + lookahead--; + } + while(lookahead < MIN_LOOKAHEAD && !eofile) fill_window(); + } + if(match_available) ct_tally(0, window[strstart-1]); + return FLUSH_BLOCK(1); +} + diff --git a/MechoSoma/XTool/outzip.cpp b/MechoSoma/XTool/outzip.cpp new file mode 100644 index 00000000..98dfeeb2 --- /dev/null +++ b/MechoSoma/XTool/outzip.cpp @@ -0,0 +1,701 @@ +#include "xtool.h" + +#include +#include + +typedef unsigned char uchar; +//typedef unsigned short ushort; +//typedef unsigned long ulong; + +struct huft; + +#ifdef _LARGE_MODEL_ +#define WSIZE 0x4000U +#define OUTBUFSIZ 0x800U +#else +#define WSIZE 0x8000U +#define OUTBUFSIZ 0x1000U +#endif + +#define MIN_MATCH 3 +#define MAX_MATCH 258 + +#define DYN_ALLOC +#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) +#define MAX_DIST (WSIZE-MIN_LOOKAHEAD) + +#define UNKNOWN (-1) +#define BINARY 0 +#define ASCII 1 + +#define STORE 0 +#define DEFLATE 8 + +// ---------- EXTERN SECTION ---------- +// ---------- PROTOTYPE SECTION ---------- + +int FlushMemory(void); +int FlushOutput(void); +void inflate(void); +int ReadMemoryByte(unsigned short* x); + +// ---------- DEFINITION SECTION ---------- + +uchar* outbuf; +uchar* outptr; + +uchar* slide; + +int outcnt = 0; +int outpos = 0; +unsigned int bitbuf = 0; +int bits_left = 0; +char zipeof = 0; + +unsigned short mask_bits[] = { + 0x0000, + 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, + 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF +}; + +static uchar* mem_i_buffer; +static uchar* mem_o_buffer; +static unsigned int mem_i_size,mem_i_offset; +static unsigned int mem_o_size,mem_o_offset; + +ulong ZIP_GetExpandedSize(char* p) +{ + return *(unsigned int*)(p + 2); +} + +void ZIP_expand(char* trg,ulong trgsize,char* src,ulong srcsize) +{ + unsigned short method; + + outbuf = new uchar[OUTBUFSIZ + 1]; + slide = new uchar[WSIZE]; + + method = *(short*)(src); + + mem_i_buffer = (uchar*)src + 2 + 4; + mem_i_size = srcsize - 2 - 4; + mem_i_offset = 0; + + mem_o_buffer = (uchar*)trg; + mem_o_size = trgsize; + mem_o_offset = 0; + + bits_left = 0; + bitbuf = 0L; + outpos = 0L; + outcnt = 0; + outptr = outbuf; + zipeof = 0; + memset(outbuf,0xAA,OUTBUFSIZ); + + switch (method) { + case STORE: + memcpy(trg,src + 2 + 4,(unsigned)(srcsize - 2 - 4)); + break; + case DEFLATE: + inflate(); + FlushOutput(); + break; + default: + break; + } + + delete outbuf; + delete slide; +} + +int FlushOutput(void) +{ + int rc = FlushMemory(); + outpos += outcnt; + outcnt = 0; + outptr = outbuf; + return rc; +} + +int ReadMemoryByte(unsigned short* x) +{ + if (mem_i_offset < mem_i_size) { + *x = (unsigned short) mem_i_buffer[mem_i_offset++]; + return 8; + } else + return 0; +} + +int FlushMemory(void) +{ + if(outcnt == 0) + return 0; + + if(mem_o_offset + outcnt <= mem_o_size){ + memcpy((char*)(mem_o_buffer + mem_o_offset),(char*)outbuf,outcnt); + mem_o_offset += outcnt; + return 0; + } else + return 50; +} + + +#define NEXTBYTE (ReadByte(&bytebuf), bytebuf) +#define NEEDBITS(n) {while(k<(n)){b|=((unsigned int)NEXTBYTE)<>=(n);k-=(n);} + +#define BMAX 16 +#define N_MAX 288 + +// ---------- EXTERN SECTION ---------- + +extern uchar* outptr; +extern int outcnt; + +// ---------- PROTOTYPE SECTION ---------- + +int FlushOutput(void); +int ReadMemoryByte(unsigned short* x); + +int huft_build(unsigned int* b,unsigned int n,unsigned int s,unsigned short* d,unsigned short* e,struct huft** t,int* m); +int huft_free(struct huft* t); +void flush(unsigned w); +int inflate_codes(struct huft* tl,struct huft* td,int bl,int bd); +int inflate_stored(void); +int inflate_fixed(void); +int inflate_dynamic(void); +int inflate_block(int* e); +int inflate_entry(void); +void inflate(void); +int ReadByte(unsigned short* x); + +// ---------- DEFINITION SECTION ---------- + +struct huft { + uchar e; + uchar b; + union { + unsigned short n; + struct huft *t; + } v; +}; + +static unsigned border[] = { + 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; +static unsigned short cplens[] = { + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; +static unsigned short cplext[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; +static unsigned short cpdist[] = { + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577}; +static unsigned short cpdext[] = { + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, + 12, 12, 13, 13}; + +unsigned wp; +unsigned int bb; +unsigned bk; +unsigned short bytebuf; + +int lbits = 9; +int dbits = 6; + +unsigned hufts; + +int huft_build(unsigned int* b,unsigned int n,unsigned int s,unsigned short* d,unsigned short* e,struct huft** t,int* m) +{ + unsigned a; + unsigned c[BMAX+1]; + unsigned f; + int g; + int h; + unsigned i; + unsigned j; + int k; + int l; + unsigned *p; + struct huft *q; + struct huft r; + struct huft *u[BMAX]; + unsigned v[N_MAX]; + int w; + unsigned x[BMAX+1]; + unsigned *xp; + int y; + unsigned z; + + memset(c, 0,sizeof(c)); + p = b; i = n; + do { + c[*p++]++; + } while(--i); + if(c[0] == n) + return 2; + + l = *m; + for(j = 1; j <= BMAX; j++) + if(c[j]) + break; + k = j; + if((unsigned)l < j) + l = j; + for(i = BMAX; i; i--) + if(c[i]) + break; + g = i; + if((unsigned)l > i) + l = i; + *m = l; + + for(y = 1 << j; j < i; j++,y <<= 1) + if((y -= c[j]) < 0) + return 2; + if((y -= c[i]) < 0) + return 2; + c[i] += y; + + x[1] = j = 0; + p = c + 1; xp = x + 2; + while(--i){ + *xp++ = (j += *p++); + } + + p = b; i = 0; + do { + if((j = *p++) != 0) + v[x[j]++] = i; + } while(++i < n); + + x[0] = i = 0; + p = v; + h = -1; + w = -l; + u[0] = (struct huft*)NULL; + q = (struct huft*)NULL; + z = 0; + + for(; k <= g; k++){ + a = c[k]; + while(a--){ + while(k > w + l){ + h++; + w += l; + z = (z = g - w) > (unsigned)l ? l : z; + if((f = 1 << (j = k - w)) > a + 1) + { + f -= a + 1; + xp = c + k; + while(++j < z) + { + if((f <<= 1) <= *++xp) + break; + f -= *xp; + } + } + z = 1 << j; + q = new huft[z + 1]; + hufts += z + 1; + *t = q + 1; + *(t = &(q->v.t)) = (struct huft*)NULL; + u[h] = ++q; + + if(h){ + x[h] = i; + r.b = (uchar)l; + r.e = (uchar)(16 + j); + r.v.t = q; + j = i >> (w - l); + u[h-1][j] = r; + } + } + + r.b = (uchar)(k - w); + if(p >= v + n) + r.e = 99; + else + if(*p < s){ + r.e = (uchar)(*p < 256 ? 16 : 15); + r.v.n = *p++; + } + else { + r.e = (uchar)e[*p - s]; /* non-simple--look up in lists */ + r.v.n = d[*p++ - s]; + } + + f = 1 << (k - w); + for(j = i >> w; j < z; j += f) + q[j] = r; + + for(j = 1 << (k - 1); i & j; j >>= 1) + i ^= j; + i ^= j; + + while((i & ((1 << w) - 1)) != x[h]){ + h--; + w -= l; + } + } + } + return y != 0 && n != 1; +} + +int huft_free(struct huft* t) +{ + struct huft *p,*q; + p = t; + while(p != (struct huft*)NULL){ + q = (--p)->v.t; +// free(p); + delete p; + p = q; + } + return 0; +} + +void flush(unsigned w) +{ + unsigned n; + uchar *p; + + p = slide; + while(w){ + n = (n = OUTBUFSIZ - outcnt) < w ? n : w; + memcpy(outptr,p,n); + outptr += n; + if((outcnt += n) == OUTBUFSIZ) + FlushOutput(); + p += n; + w -= n; + } +} + +int inflate_codes(struct huft* tl,struct huft* td,int bl,int bd) +{ + unsigned e; + unsigned n,d; + unsigned w; + struct huft *t; + unsigned ml,md; + unsigned int b; + unsigned k; + + b = bb; + k = bk; + w = wp; + + ml = mask_bits[bl]; + md = mask_bits[bd]; + while(1){ + NEEDBITS((unsigned)bl) + if((e = (t = tl + ((unsigned)b & ml))->e) > 16) + do { + if(e == 99) + return 1; + DUMPBITS(t->b) + e -= 16; + NEEDBITS(e) + } while((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16); + DUMPBITS(t->b) + if(e == 16){ + slide[w++] = (uchar)t->v.n; + if(w == WSIZE){ + flush(w); + w = 0; + } + } + else { + if(e == 15) + break; + NEEDBITS(e) + n = t->v.n + ((unsigned)b & mask_bits[e]); + DUMPBITS(e); + NEEDBITS((unsigned)bd) + if((e = (t = td + ((unsigned)b & md))->e) > 16) + do { + if(e == 99) + return 1; + DUMPBITS(t->b) + e -= 16; + NEEDBITS(e) + } while((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16); + DUMPBITS(t->b) + NEEDBITS(e) + d = w - t->v.n - ((unsigned)b & mask_bits[e]); + DUMPBITS(e) + do { + n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e); + if(w - d >= e){ + memcpy(slide + w,slide + d,e); + w += e; + d += e; + } + else + do { + slide[w++] = slide[d++]; + } while(--e); + if(w == WSIZE){ + flush(w); + w = 0; + } + } while(n); + } + } + wp = w; + bb = b; + bk = k; + return 0; +} + +int inflate_stored(void) +{ + unsigned n; + unsigned w; + unsigned int b; + unsigned k; + + b = bb; + k = bk; + w = wp; + n = k & 7; + DUMPBITS(n); + + NEEDBITS(16) + n = ((unsigned)b & 0xffff); + DUMPBITS(16) + NEEDBITS(16) + if(n != (unsigned)((~b) & 0xffff)) + return 1; + DUMPBITS(16) + + while(n--){ + NEEDBITS(8) + slide[w++] = (uchar)b; + if(w == WSIZE){ + flush(w); + w = 0; + } + DUMPBITS(8) + } + + wp = w; + bb = b; + bk = k; + return 0; +} + +int inflate_fixed(void) +{ + int i; + struct huft *tl; + struct huft *td; + int bl; + int bd; + unsigned l[288]; + + for(i = 0; i < 144; i++) + l[i] = 8; + for(; i < 256; i++) + l[i] = 9; + for(; i < 280; i++) + l[i] = 7; + for(; i < 288; i++) + l[i] = 8; + bl = 7; + if((i = huft_build(l,288,257,cplens,cplext,&tl,&bl)) != 0) + return i; + + for(i = 0; i < 30; i++) + l[i] = 5; + bd = 5; + if((i = huft_build(l,30,0,cpdist,cpdext,&td,&bd)) > 1){ + huft_free(tl); + return i; + } + + if(inflate_codes(tl,td,bl,bd)) + return 1; + + huft_free(tl); + huft_free(td); + return 0; +} + +int inflate_dynamic(void) +{ + int i; + unsigned j; + unsigned l; + unsigned m; + unsigned n; + struct huft *tl; + struct huft *td; + int bl; + int bd; + unsigned nb; + unsigned nl; + unsigned nd; + unsigned ll[286+30]; + unsigned int b; + unsigned k; + + b = bb; + k = bk; + + NEEDBITS(5) + nl = 257 + ((unsigned)b & 0x1f); + DUMPBITS(5) + NEEDBITS(5) + nd = 1 + ((unsigned)b & 0x1f); + DUMPBITS(5) + NEEDBITS(4) + nb = 4 + ((unsigned)b & 0xf); + DUMPBITS(4) + if(nl > 286 || nd > 30) + return 1; + for(j = 0; j < nb; j++){ + NEEDBITS(3) + ll[border[j]] = (unsigned)b & 7; + DUMPBITS(3) + } + for(; j < 19; j++) + ll[border[j]] = 0; + bl = 7; + if((i = huft_build(ll,19,19,NULL,NULL,&tl,&bl)) != 0){ + if(i == 1) + huft_free(tl); + return i; + } + n = nl + nd; + m = mask_bits[bl]; + i = l = 0; + while((unsigned)i < n){ + NEEDBITS((unsigned)bl) + j = (td = tl + ((unsigned)b & m))->b; + DUMPBITS(j) + j = td->v.n; + if(j < 16) + ll[i++] = l = j; + else + if(j == 16){ + NEEDBITS(2) + j = 3 + ((unsigned)b & 3); + DUMPBITS(2) + if((unsigned)i + j > n) + return 1; + while(j--) + ll[i++] = l; + } + else + if(j == 17){ + NEEDBITS(3) + j = 3 + ((unsigned)b & 7); + DUMPBITS(3) + if((unsigned)i + j > n) + return 1; + while(j--) + ll[i++] = 0; + l = 0; + } + else { + NEEDBITS(7) + j = 11 + ((unsigned)b & 0x7f); + DUMPBITS(7) + if((unsigned)i + j > n) + return 1; + while(j--) + ll[i++] = 0; + l = 0; + } + } + huft_free(tl); + + bb = b; + bk = k; + bl = lbits; + if((i = huft_build(ll,nl,257,cplens,cplext,&tl,&bl)) != 0){ + if(i == 1) + huft_free(tl); + return i; + } + bd = dbits; + if((i = huft_build(ll + nl,nd,0,cpdist,cpdext,&td,&bd)) != 0){ + if(i == 1) + huft_free(td); + huft_free(tl); + return i; + } + if(inflate_codes(tl,td,bl,bd)) + return 1; + huft_free(tl); + huft_free(td); + return 0; +} + +int inflate_block(int* e) +{ + unsigned t; + unsigned int b; + unsigned k; + + b = bb; + k = bk; + + NEEDBITS(1) + *e = (int)b & 1; + DUMPBITS(1) + + NEEDBITS(2) + t = (unsigned)b & 3; + DUMPBITS(2) + + bb = b; + bk = k; + + if(t == 2) + return inflate_dynamic(); + if(t == 0) + return inflate_stored(); + if(t == 1) + return inflate_fixed(); + return 2; +} + +int inflate_entry(void) +{ + int e; + int r; + unsigned h; + + wp = 0; + bk = 0; + bb = 0; + + h = 0; + do { + hufts = 0; + if((r = inflate_block(&e)) != 0) + return r; + if(hufts > h) + h = hufts; + } while(!e); + + flush(wp); + return 0; +} + +void inflate(void) +{ + inflate_entry(); +} + +int ReadByte(unsigned short* x) +{ + return ReadMemoryByte(x); +} + diff --git a/MechoSoma/XTool/port.cpp b/MechoSoma/XTool/port.cpp new file mode 100644 index 00000000..3758076d --- /dev/null +++ b/MechoSoma/XTool/port.cpp @@ -0,0 +1,180 @@ +#include "port.h" + +#include +#include +#include +#include +#include + +#include "filesystem.h" +#include "xtool.h" +#include "xINI_File.h" + +char *strupr(char *string) { + char *s; + + if (string) { + for (s = string; *s; ++s) + *s = toupper(*s); + } + return string; +} + +/** + + * C++ version char* style "itoa": + + */ + +char* port_itoa( int value, char* result, int base ) { + // check that the base if valid + if (base < 2 || base > 16) { + *result = 0; + return result; + } + + char* out = result; + int quotient = value; + + do { + *out = "0123456789abcdef"[ std::abs( quotient % base ) ]; + ++out; + quotient /= base; + + } while ( quotient ); + + // Only apply negative sign for base 10 + if ( value < 0 && base == 10) + *out++ = '-'; + + std::reverse( result, out ); + *out = 0; + return result; +} + +char* port_ltoa( long value, char* result, int base ) { + // check that the base if valid + if (base < 2 || base > 16) { + *result = 0; + return result; + } + + char* out = result; + long quotient = value; + + do { + *out = "0123456789abcdef"[ std::abs( quotient % base ) ]; + ++out; + quotient /= base; + } while ( quotient ); + + // Only apply negative sign for base 10 + if ( value < 0 && base == 10) + *out++ = '-'; + + std::reverse( result, out ); + *out = 0; + return result; +} + +char* port_ultoa( unsigned long value, char* result, int base ) { + // check that the base if valid + if (base < 2 || base > 16) { + *result = 0; + return result; + } + + char* out = result; + unsigned long quotient = value; + + do { + *out = "0123456789abcdef"[ quotient % base ]; + ++out; + quotient /= base; + } while ( quotient ); + + std::reverse( result, out ); + *out = 0; + return result; +} + +char *_fullpath(char *absPath, const char *relPath, size_t maxLength) +{ + return realpath(relPath, absPath); +} + +char *strlwr(char *str) +{ + return str; +} + +struct PrivateProfile +{ + std::string name; + xINI_File* file = nullptr; + + explicit PrivateProfile(const char* name) + { + this->name = name; + file = new xINI_File(name); + file->load(); + } + + ~PrivateProfile() + { + delete file; + } +}; +std::vector> private_profiles; + +uint32_t GetPrivateProfileString( + const char* lpAppName, + const char* lpKeyName, + const char* lpDefault, + char* lpReturnedString, + uint32_t nSize, + const char* lpFileName +) +{ + xINI_File* file; + + auto p = std::find_if(private_profiles.cbegin(), private_profiles.cend(), [lpFileName](const auto& e) { + return e->name == lpFileName; + }); + if (p == private_profiles.cend()) + { + const auto path = file::normalize_path(lpFileName); + if (!exists(path)) + { + return 0; + } + file = private_profiles.emplace_back(std::make_unique(lpFileName))->file; + } + else + { + file = p->get()->file; + } + + auto value = file->get_key(lpAppName, lpKeyName); + if (value == nullptr) + { + return 0; + } + + std::string t(value); + const size_t value_size = std::min(t.size(), static_cast(nSize)); + std::copy(t.cbegin(), t.cbegin() + value_size, lpReturnedString); + lpReturnedString[value_size] = 0; + + return value_size; +} + +bool WritePrivateProfileString( + const char* lpAppName, + const char* lpKeyName, + const char* lpString, + const char* lpFileName +) +{ + return false; +} diff --git a/MechoSoma/XTool/port.h b/MechoSoma/XTool/port.h new file mode 100644 index 00000000..14680470 --- /dev/null +++ b/MechoSoma/XTool/port.h @@ -0,0 +1,53 @@ +#ifndef __PORT_H +#define __PORT_H + +#include + +/** + + * C++ version char* style "itoa": + + */ + +char* port_itoa( int value, char* result, int base ); + +char* port_ltoa( long value, char* result, int base ); + +char* port_ultoa( unsigned long value, char* result, int base ); + +#if defined(__unix__) || defined(__APPLE__) +char *strupr(char *string); +#endif + +// Copied C version from Vangers +// TODO(amdmi3): very inefficient; rewrite +inline int BitSR(int x) { + unsigned int a = abs(x); + for (int i = 31; i > 0; i--) + if (a & (1 << i)) + return i; + + return 0; +} + +char *_fullpath(char *absPath, const char *relPath, size_t maxLength); + +char *strlwr(char *str); + +uint32_t GetPrivateProfileString( + const char* lpAppName, + const char* lpKeyName, + const char* lpDefault, + char* lpReturnedString, + uint32_t nSize, + const char* lpFileName +); + +bool WritePrivateProfileString( + const char* lpAppName, + const char* lpKeyName, + const char* lpString, + const char* lpFileName +); + +#endif diff --git a/MechoSoma/XTool/treezip.cpp b/MechoSoma/XTool/treezip.cpp new file mode 100644 index 00000000..db9a8281 --- /dev/null +++ b/MechoSoma/XTool/treezip.cpp @@ -0,0 +1,709 @@ +#include "xtool.h" + +#include +#include + +typedef unsigned char uchar; +//typedef unsigned short ushort; +//typedef unsigned long ulong; + +extern char* IErrMsg; + +#ifdef _LARGE_MODEL_ +#define WSIZE 0x4000U +#define OUTBUFSIZ 0x800U +#else +#define WSIZE 0x8000U +#define OUTBUFSIZ 0x1000U +#endif + +#define MIN_MATCH 3 +#define MAX_MATCH 258 + +#define DYN_ALLOC +#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) +#define MAX_DIST (WSIZE-MIN_LOOKAHEAD) + +#define UNKNOWN (-1) +#define BINARY 0 +#define ASCII 1 + +#define STORE 0 +#define DEFLATE 8 + +#define MAX_BITS 15 +#define MAX_BL_BITS 7 +#define LENGTH_CODES 29 +#define LITERALS 256 +#define END_BLOCK 256 +#define L_CODES (LITERALS+1+LENGTH_CODES) +#define D_CODES 30 +#define BL_CODES 19 + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 + +#define LIT_BUFSIZE 0x4000 + +#define DIST_BUFSIZE LIT_BUFSIZE + +#define REP_3_6 16 +#define REPZ_3_10 17 +#define REPZ_11_138 18 + +typedef struct ct_data { + union { + unsigned short freq; + unsigned short code; + } fc; + union { + unsigned short dad; + unsigned short len; + } dl; +} ct_data; + +typedef struct tree_desc +{ + ct_data* dyn_tree; + ct_data* static_tree; + int* extra_bits; + int extra_base; + int elems; + int max_length; + int max_code; +} tree_desc; + +#define Freq fc.freq +#define Code fc.code +#define Dad dl.dad +#define Len dl.len + +#define HEAP_SIZE (2 * L_CODES + 1) + +// ---------- EXTERN SECTION ---------- + +extern int verbose; +extern int level; + +// ---------- PROTOTYPE SECTION ---------- + +void ct_init(unsigned short* attr,int* method); +unsigned int flush_block(char* buf,unsigned int stored_len,int eof); +int ct_tally(int dist,int lc); + +void copy_block(char* buf,unsigned len,int header); +void bi_windup(void); +unsigned bi_reverse(unsigned code,int len); +void send_bits(int value,int length); +void free_data(void); +void lm_free(void); + +static void init_block(void); +static void pqdownheap(ct_data* tree, int k); +static void gen_bitlen(tree_desc* desc); +static void gen_codes(ct_data* tree, int max_code); +static void build_tree(tree_desc* desc); +static void scan_tree(ct_data* tree, int max_code); +static void send_tree(ct_data* tree, int max_code); +static int build_bl_tree(void); +static void send_all_trees(int lcodes, int dcodes, int blcodes); +static void compress_block(ct_data* ltree, ct_data* dtree); +static void set_file_type(void); + +// ---------- DEFINITION SECTION ---------- + +static int extra_lbits[LENGTH_CODES] + = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; + +static int extra_dbits[D_CODES] + = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; + +static int extra_blbits[BL_CODES] + = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; + +static ct_data dyn_ltree[HEAP_SIZE]; +static ct_data dyn_dtree[2*D_CODES+1]; + +static ct_data static_ltree[L_CODES+2]; +static ct_data static_dtree[D_CODES]; +static ct_data bl_tree[2*BL_CODES+1]; + +static tree_desc l_desc = +{dyn_ltree, static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS, 0}; + +static tree_desc d_desc = +{dyn_dtree, static_dtree, extra_dbits, 0, D_CODES, MAX_BITS, 0}; + +static tree_desc bl_desc = +{bl_tree, NULL, extra_blbits, 0, BL_CODES, MAX_BL_BITS, 0}; + +static unsigned short bl_count[MAX_BITS + 1]; + +static uchar bl_order[BL_CODES] + = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; + +static int heap[2 * L_CODES + 1]; +static int heap_len; +static int heap_max; + +static uchar depth[2 * L_CODES + 1]; +static uchar length_code[MAX_MATCH - MIN_MATCH + 1]; +static uchar dist_code[512]; +static int base_length[LENGTH_CODES]; + +static int base_dist[D_CODES]; + +#ifndef DYN_ALLOC + static uchar l_buf[LIT_BUFSIZE]; + static unsigned short d_buf[DIST_BUFSIZE]; +#else + static uchar* l_buf; + static unsigned short* d_buf; +#endif + +static uchar flag_buf[(LIT_BUFSIZE/8)]; + +static unsigned last_lit; +static unsigned last_dist; +static unsigned last_flags; +static uchar flags; +static uchar flag_bit; + +static unsigned int opt_len; +static unsigned int static_len; + +static unsigned int compressed_len; + +static unsigned int input_len; + +unsigned short *file_type; +int *file_method; + +extern int block_start; +extern unsigned strstart; + +# define send_code(c, tree) \ + { if(verbose>1) fprintf(stderr,"\ncd %3d ",(c)); \ + send_bits(tree[c].Code, tree[c].Len); } + +#define d_code(dist) \ + ((dist) < 256 ? dist_code[dist] : dist_code[256+((dist)>>7)]) + +#define MAX(a,b) (a >= b ? a : b) + +void ct_init(unsigned short* attr,int* method) +{ + int n; + int bits; + int length; + int code; + int dist; + + file_type = attr; + file_method = method; + compressed_len = input_len = 0L; + +#ifdef DYN_ALLOC + d_buf = new unsigned short[DIST_BUFSIZE]; + l_buf = new uchar[LIT_BUFSIZE]; +#endif + length = 0; + for(code = 0; code < LENGTH_CODES-1; code++){ + base_length[code] = length; + for(n = 0; n < (1<>= 7; + for( ; code < D_CODES; code++){ + base_dist[code] = dist << 7; + for(n = 0; n < (1<<(extra_dbits[code]-7)); n++){ + dist_code[256 + dist++] = (uchar)code; + } + } + + for(bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; + n = 0; + while(n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; + while(n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; + while(n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; + while(n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; + gen_codes((ct_data*)static_ltree, L_CODES+1); + + for(n = 0; n < D_CODES; n++){ + static_dtree[n].Len = 5; + static_dtree[n].Code = bi_reverse(n, 5); + } + + init_block(); +} + +static void init_block(void) +{ + int n; + + for(n = 0; n < L_CODES; n++) dyn_ltree[n].Freq = 0; + for(n = 0; n < D_CODES; n++) dyn_dtree[n].Freq = 0; + for(n = 0; n < BL_CODES; n++) bl_tree[n].Freq = 0; + + dyn_ltree[END_BLOCK].Freq = 1; + opt_len = static_len = 0L; + last_lit = last_dist = last_flags = 0; + flags = 0; flag_bit = 1; +} + +#define SMALLEST 1 + +#define pqremove(tree, top) \ +{\ + top = heap[SMALLEST]; \ + heap[SMALLEST] = heap[heap_len--]; \ + pqdownheap(tree,SMALLEST); \ +} + +#define smaller(tree, n, m) \ + (tree[n].Freq < tree[m].Freq || \ + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) + +static void pqdownheap(ct_data* tree,int k) +{ + int v = heap[k]; + int j = k << 1; + int htemp; + + while(j <= heap_len){ + if(j < heap_len && smaller(tree, heap[j+1], heap[j])) j++; + + htemp = heap[j]; + if(smaller(tree, v, htemp)) break; + + heap[k] = htemp; + k = j; + + j <<= 1; + } + heap[k] = v; +} + +static void gen_bitlen(tree_desc* desc) +{ + ct_data* tree = desc->dyn_tree; + int* extra = desc->extra_bits; + int base = desc->extra_base; + int max_code = desc->max_code; + int max_length = desc->max_length; + ct_data* stree = desc->static_tree; + int h; + int n, m; + int bits; + int xbits; + unsigned short f; + int overflow = 0; + + for(bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; + + tree[heap[heap_max]].Len = 0; + + for(h = heap_max+1; h < HEAP_SIZE; h++){ + n = heap[h]; + bits = tree[tree[n].Dad].Len + 1; + if(bits > max_length) bits = max_length, overflow++; + tree[n].Len = bits; + + if(n > max_code) continue; + + bl_count[bits]++; + xbits = 0; + if(n >= base) xbits = extra[n-base]; + f = tree[n].Freq; + opt_len += (unsigned int)f * (bits + xbits); + if(stree) static_len += (unsigned int)f * (stree[n].Len + xbits); + } + if(overflow == 0) return; + + do { + bits = max_length-1; + while(bl_count[bits] == 0) bits--; + bl_count[bits]--; + bl_count[bits+1] += 2; + bl_count[max_length]--; + overflow -= 2; + } while(overflow > 0); + + for(bits = max_length; bits != 0; bits--){ + n = bl_count[bits]; + while(n != 0){ + m = heap[--h]; + if(m > max_code) continue; + if(tree[m].Len != (unsigned) bits){ + opt_len += ((int)bits-(int)tree[m].Len)*(int)tree[m].Freq; + tree[m].Len = bits; + } + n--; + } + } +} + +static void gen_codes (ct_data* tree,int max_code) +{ + unsigned short next_code[MAX_BITS+1]; + unsigned short code = 0; + int bits; + int n; + + for(bits = 1; bits <= MAX_BITS; bits++){ + next_code[bits] = code = (code + bl_count[bits-1]) << 1; + } + for(n = 0; n <= max_code; n++){ + int len = tree[n].Len; + if(len == 0) continue; + tree[n].Code = bi_reverse(next_code[len]++, len); + } +} + +static void build_tree(tree_desc* desc) +{ + ct_data* tree = desc->dyn_tree; + ct_data* stree = desc->static_tree; + int elems = desc->elems; + int n, m; + int max_code = -1; + int node = elems; + + heap_len = 0, heap_max = HEAP_SIZE; + + for(n = 0; n < elems; n++){ + if(tree[n].Freq != 0){ + heap[++heap_len] = max_code = n; + depth[n] = 0; + } + else { + tree[n].Len = 0; + } + } + + while(heap_len < 2){ + int new_ = heap[++heap_len] = (max_code < 2 ? ++max_code : 0); + tree[new_].Freq = 1; + depth[new_] = 0; + opt_len--; + if(stree) + static_len -= stree[new_].Len; + } + desc->max_code = max_code; + + for(n = heap_len/2; n >= 1; n--) pqdownheap(tree, n); + + do { + pqremove(tree, n); + m = heap[SMALLEST]; + + heap[--heap_max] = n; + heap[--heap_max] = m; + + tree[node].Freq = tree[n].Freq + tree[m].Freq; + depth[node] = (uchar) (MAX(depth[n], depth[m]) + 1); + tree[n].Dad = tree[m].Dad = node; + heap[SMALLEST] = node++; + pqdownheap(tree, SMALLEST); + + } while(heap_len >= 2); + + heap[--heap_max] = heap[SMALLEST]; + gen_bitlen((tree_desc*)desc); + gen_codes ((ct_data*)tree, max_code); +} + +static void scan_tree (ct_data* tree,int max_code) +{ + int n; + int prevlen = -1; + int curlen; + int nextlen = tree[0].Len; + int count = 0; + int max_count = 7; + int min_count = 4; + + if(nextlen == 0) max_count = 138, min_count = 3; + tree[max_code+1].Len = (unsigned short)-1; + + for(n = 0; n <= max_code; n++){ + curlen = nextlen; nextlen = tree[n+1].Len; + if(++count < max_count && curlen == nextlen){ + continue; + } + else + if(count < min_count){ + bl_tree[curlen].Freq += count; + } + else + if(curlen != 0){ + if(curlen != prevlen) bl_tree[curlen].Freq++; + bl_tree[REP_3_6].Freq++; + } + else + if(count <= 10){ + bl_tree[REPZ_3_10].Freq++; + } + else { + bl_tree[REPZ_11_138].Freq++; + } + count = 0; prevlen = curlen; + if(nextlen == 0){ + max_count = 138, min_count = 3; + } else + if(curlen == nextlen){ + max_count = 6, min_count = 3; + } + else { + max_count = 7, min_count = 4; + } + } +} + +static void send_tree (ct_data* tree,int max_code) +{ + int n; + int prevlen = -1; + int curlen; + int nextlen = tree[0].Len; + int count = 0; + int max_count = 7; + int min_count = 4; + + if(nextlen == 0) max_count = 138, min_count = 3; + + for(n = 0; n <= max_code; n++){ + curlen = nextlen; nextlen = tree[n+1].Len; + if(++count < max_count && curlen == nextlen){ + continue; + } + else + if(count < min_count){ + do { send_code(curlen, bl_tree); } while(--count != 0); + + } + else + if(curlen != 0){ + if(curlen != prevlen){ + send_code(curlen, bl_tree); count--; + } + send_code(REP_3_6, bl_tree); send_bits(count-3, 2); + + } + else + if(count <= 10){ + send_code(REPZ_3_10, bl_tree); send_bits(count-3, 3); + + } + else { + send_code(REPZ_11_138, bl_tree); send_bits(count-11, 7); + } + count = 0; prevlen = curlen; + if(nextlen == 0){ + max_count = 138, min_count = 3; + } + else + if(curlen == nextlen){ + max_count = 6, min_count = 3; + } + else { + max_count = 7, min_count = 4; + } + } +} + +static int build_bl_tree() +{ + int max_blindex; + + scan_tree((ct_data*)dyn_ltree, l_desc.max_code); + scan_tree((ct_data*)dyn_dtree, d_desc.max_code); + + build_tree((tree_desc*)(&bl_desc)); + for(max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--){ + if(bl_tree[bl_order[max_blindex]].Len != 0) break; + } + opt_len += 3*(max_blindex+1) + 5+5+4; + + return max_blindex; +} + +static void send_all_trees(int lcodes,int dcodes,int blcodes) +{ + int rank; + + send_bits(lcodes-257, 5); + send_bits(dcodes-1, 5); + send_bits(blcodes-4, 4); + for(rank = 0; rank < blcodes; rank++){ + send_bits(bl_tree[bl_order[rank]].Len, 3); + } + + send_tree((ct_data*)dyn_ltree, lcodes-1); + send_tree((ct_data*)dyn_dtree, dcodes-1); +} + +unsigned int flush_block(char* buf,unsigned int stored_len,int eof) +{ + unsigned int opt_lenb, static_lenb; + int max_blindex; + + flag_buf[last_flags] = flags; + + if(*file_type == (unsigned short)UNKNOWN) set_file_type(); + + build_tree((tree_desc*)(&l_desc)); + + build_tree((tree_desc*)(&d_desc)); + max_blindex = build_bl_tree(); + + opt_lenb = (opt_len+3+7)>>3; + static_lenb = (static_len+3+7)>>3; + input_len += stored_len; + if(static_lenb <= opt_lenb) opt_lenb = static_lenb; + + if(stored_len <= opt_lenb && eof && compressed_len == 0L){ + //if(buf == NULL) ErrH.Abort(IErrMsg); + copy_block(buf,(unsigned)stored_len,0); + compressed_len = stored_len << 3; + *file_method = STORE; + } + else + if(stored_len+4 <= opt_lenb && buf != (char*)NULL){ + send_bits((STORED_BLOCK<<1)+eof, 3); + compressed_len = (compressed_len + 3 + 7) & ~7L; + compressed_len += (stored_len + 4) << 3; + + copy_block(buf, (unsigned)stored_len, 1); + } + else + if(static_lenb == opt_lenb){ + send_bits((STATIC_TREES<<1)+eof, 3); + compress_block((ct_data*)static_ltree, (ct_data*)static_dtree); + compressed_len += 3 + static_len; + } + else { + send_bits((DYN_TREES<<1)+eof, 3); + send_all_trees(l_desc.max_code+1, d_desc.max_code+1, max_blindex+1); + compress_block((ct_data*)dyn_ltree, (ct_data*)dyn_dtree); + compressed_len += 3 + opt_len; + } + init_block(); + if(eof){ +#ifdef DYN_ALLOC + extern uchar *window; +#else + extern uchar window[]; +#endif + memset(window, 0, (unsigned)(2*WSIZE-1)); + bi_windup(); + compressed_len += 7; + } + return compressed_len >> 3; +} + + +int ct_tally(int dist,int lc) +{ + l_buf[last_lit++] = (uchar)lc; + if(dist == 0){ + dyn_ltree[lc].Freq++; + } + else { + dist--; + + dyn_ltree[length_code[lc]+LITERALS+1].Freq++; + dyn_dtree[d_code(dist)].Freq++; + + d_buf[last_dist++] = dist; + flags |= flag_bit; + } + flag_bit <<= 1; + + if((last_lit & 7) == 0){ + flag_buf[last_flags++] = flags; + flags = 0, flag_bit = 1; + } + if(level > 2 && (last_lit & 0xfff) == 0){ + unsigned int out_length = (unsigned int)last_lit*8L; + unsigned int in_length = (unsigned int)strstart-block_start; + int dcode; + for(dcode = 0; dcode < D_CODES; dcode++){ + out_length += (unsigned int)dyn_dtree[dcode].Freq*(5L+extra_dbits[dcode]); + } + out_length >>= 3; + if(last_dist < last_lit/2 && out_length < in_length/2) return 1; + } + return (last_lit == LIT_BUFSIZE-1 || last_dist == DIST_BUFSIZE); +} + +static void compress_block(ct_data* ltree,ct_data* dtree) +{ + unsigned dist; + int lc; + unsigned lx = 0; + unsigned dx = 0; + unsigned fx = 0; + uchar flag = 0; + unsigned code; + int extra; + + if(last_lit != 0) do { + if((lx & 7) == 0) flag = flag_buf[fx++]; + lc = l_buf[lx++]; + if((flag & 1) == 0){ + send_code(lc, ltree); + } + else { + code = length_code[lc]; + send_code(code+LITERALS+1, ltree); + extra = extra_lbits[code]; + if(extra != 0){ + lc -= base_length[code]; + send_bits(lc, extra); + } + dist = d_buf[dx++]; + code = d_code(dist); + + send_code(code, dtree); + extra = extra_dbits[code]; + if(extra != 0){ + dist -= base_dist[code]; + send_bits(dist, extra); + } + } + flag >>= 1; + } while(lx < last_lit); + send_code(END_BLOCK, ltree); +} + +static void set_file_type() +{ + int n = 0; + unsigned ascii_freq = 0; + unsigned bin_freq = 0; + while(n < 7) bin_freq += dyn_ltree[n++].Freq; + while(n < 128) ascii_freq += dyn_ltree[n++].Freq; + while(n < LITERALS) bin_freq += dyn_ltree[n++].Freq; + *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII; +} + +void free_data(void) +{ +#ifdef DYN_ALLOC + delete l_buf; + delete d_buf; + lm_free(); +#endif +} diff --git a/MechoSoma/XTool/xbcnvin.cpp b/MechoSoma/XTool/xbcnvin.cpp new file mode 100644 index 00000000..d7712b74 --- /dev/null +++ b/MechoSoma/XTool/xbcnvin.cpp @@ -0,0 +1,85 @@ +#include "xtool.h" + +#include +#include + +#include "port.h" + +char _ConvertBuffer[_CONV_BUFFER_LEN + 1]; + +XBuffer& XBuffer::operator<= (char var) +{ + char* s = port_itoa(var,_ConvertBuffer,radix); + write(s,strlen(s),0); + return *this; +} + +XBuffer& XBuffer::operator<= (unsigned char var) +{ + char* s = port_itoa(var,_ConvertBuffer,radix); + write(s,strlen(s),0); + return *this; +} + +XBuffer& XBuffer::operator<= (short var) +{ + char* s = port_itoa(var,_ConvertBuffer,radix); + write(s,strlen(s),0); + return *this; +} + +XBuffer& XBuffer::operator<= (unsigned short var) +{ + char* s = port_ltoa(var,_ConvertBuffer,radix); + write(s,strlen(s),0); + return *this; +} + +XBuffer& XBuffer::operator<= (int var) +{ + char* s = port_itoa(var,_ConvertBuffer,radix); + write(s,strlen(s),0); + return *this; +} + +XBuffer& XBuffer::operator<= (unsigned var) +{ + char* s = port_ultoa(var,_ConvertBuffer,radix); + write(s,strlen(s),0); + return *this; +} + +XBuffer& XBuffer::operator<= (long var) +{ + char* s = port_ltoa(var,_ConvertBuffer,radix); + write(s,strlen(s),0); + return *this; +} + +XBuffer& XBuffer::operator<= (unsigned long var) +{ + char* s = port_ultoa(var,_ConvertBuffer,radix); + write(s,strlen(s),0); + return *this; +} + +XBuffer& XBuffer::operator<= (float var) +{ + int len = snprintf(_ConvertBuffer, _CONV_BUFFER_LEN, "%.*g", digits, var); + write(_ConvertBuffer,len,0); + return *this; +} + +XBuffer& XBuffer::operator<= (double var) +{ + int len = snprintf(_ConvertBuffer, _CONV_BUFFER_LEN, "%.*g", digits, var); + write(_ConvertBuffer,len,0); + return *this; +} + +XBuffer& XBuffer::operator<= (long double var) +{ + int len = snprintf(_ConvertBuffer, _CONV_BUFFER_LEN, "%.*Lg", digits, var); + write(_ConvertBuffer,len,0); + return *this; +} diff --git a/MechoSoma/XTool/xbcnvout.cpp b/MechoSoma/XTool/xbcnvout.cpp new file mode 100644 index 00000000..c20e6678 --- /dev/null +++ b/MechoSoma/XTool/xbcnvout.cpp @@ -0,0 +1,98 @@ +#include "xtool.h" + +#include +#include +#include + +#include "port.h" + +XBuffer& XBuffer::operator>= (char& var) +{ + char* p = buf + offset; + var = (char)strtol(p,&p,0); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (unsigned char& var) +{ + char* p = buf + offset; + var = (unsigned char)strtoul(p,&p,0); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (short& var) +{ + char* p = buf + offset; + var = (short)strtol(p,&p,0); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (unsigned short& var) +{ + char* p = buf + offset; + var = (unsigned short)strtoul(p,&p,0); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (int& var) +{ + char* p = buf + offset; + var = strtol(p,&p,0); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (unsigned& var) +{ + char* p = buf + offset; + var = strtoul(p,&p,0); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (long& var) +{ + char* p = buf + offset; + var = strtol(p, &p, 0); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (unsigned long& var) +{ + char* p = buf + offset; + var = strtoul(p, &p,0); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (double& var) +{ + char* p = buf + offset; + var = strtod(p, &p); + offset += p - (buf + offset); + + return *this; +} + +XBuffer& XBuffer::operator>= (long double& var) +{ + char* p = buf + offset; + var = strtod(p, &p); + offset += p - (buf + offset); + return *this; +} + +XBuffer& XBuffer::operator>= (float& var) +{ + char* p = buf + offset; + var = (float)strtod(p, &p); + offset += p - (buf + offset); + return *this; +} + + diff --git a/MechoSoma/XTool/xbcore.cpp b/MechoSoma/XTool/xbcore.cpp new file mode 100644 index 00000000..0771a3d9 --- /dev/null +++ b/MechoSoma/XTool/xbcore.cpp @@ -0,0 +1,102 @@ +#include "xtool.h" + +#include +#include + +void XBuffer::alloc(unsigned int sz) +{ + buf = new char[size = sz];; + offset = 0L; + radix = XB_DEFRADIX; + digits = XB_DEFDIGITS; + MakeFree = 1; + *buf = 0; +} + +XBuffer::XBuffer(unsigned int sz, int automatic_realloc_) +{ + alloc(sz); +} + +XBuffer::XBuffer(void* p,int sz) +{ + offset = 0L; + radix = XB_DEFRADIX; + digits = XB_DEFDIGITS; + MakeFree = 0; + size = sz; + buf = (char*)p; +} + +void XBuffer::free(void) +{ + if(MakeFree && buf){ + delete[] buf; + buf = NULL; + } +} + +void XBuffer::fill(char fc) { + memset(buf,fc,size); +} + +void XBuffer::set(int off,int mode) +{ + switch(mode){ + case XB_BEG: + offset = off; + break; + case XB_CUR: + offset+=off; + break; + case XB_END: + offset = size - off; + break; + } +} + +unsigned int XBuffer::read(void* s, unsigned int len) +{ + memcpy(s, buf + offset, len); + offset += len; + return len; +} + +void XBuffer::handleOutOfSize() +{ + if(automatic_realloc) + buf = (char*)realloc(buf, size *= 2); + else { + //xassert(0 && "Out of XBuffer"); + ErrH.Abort("Out of XBuffer"); + } +} + +unsigned int XBuffer::write(const void* s, unsigned int len, int bin_flag) +{ + while(offset + len >= size) + handleOutOfSize(); + + memcpy(buf + offset, s, len); + offset += len; + + if(!bin_flag) + buf[offset] = '\0'; + + return len; +} + +XBuffer& XBuffer::operator< (const char* v) +{ + if(v) + write(v, strlen(v), 0); + return *this; +} + +XBuffer& XBuffer::operator> (char* v) +{ + if(v) + read(v, strlen(buf + offset) + 1); + return *this; +} + diff --git a/MechoSoma/XTool/xbsearch.cpp b/MechoSoma/XTool/xbsearch.cpp new file mode 100644 index 00000000..bccf049b --- /dev/null +++ b/MechoSoma/XTool/xbsearch.cpp @@ -0,0 +1,58 @@ +#include "xtool.h" + +#include +#include +#include + +int XBuffer::search(char* what, int mode, int cs) +{ + int i,j; + unsigned int wlen = strlen(what) - 1; + if(mode == XB_GLOBAL) { i = 0; mode = XB_FORWARD; } else i = offset; + if(mode == XB_FORWARD){ + if(cs == XB_CASEON){ + while(buf[i]){ + if(buf[i] == *what){ + j = wlen; + while(buf[i + j] == what[j] && j) j--; + if(j <= 0) { offset = i; return 1; }; + } + i++; + } + } + else { + while(buf[i]){ + if(toupper(buf[i]) == toupper(*what)){ + j = wlen; + while(toupper(buf[i + j]) == toupper(what[j]) && j) j--; + if(j <= 0) { offset = i; return 1; }; + } + i++; + } + } + } + else { + i-=wlen + 1; + if(cs == XB_CASEON){ + while(i >= 0){ + if(buf[i] == *what){ + j = wlen; + while(buf[i + j] == what[j] && j) j--; + if(j <= 0) { offset = i; return 1; }; + } + i--; + } + } + else { + while(i >= 0){ + if(toupper(buf[i]) == toupper(*what)){ + j = wlen; + while(toupper(buf[i + j]) == toupper(what[j]) && j) j--; + if(j <= 0) { offset = i; return 1; }; + } + i--; + } + } + } + return 0; +} diff --git a/MechoSoma/XTool/xconsole.cpp b/MechoSoma/XTool/xconsole.cpp new file mode 100644 index 00000000..27c3db3a --- /dev/null +++ b/MechoSoma/XTool/xconsole.cpp @@ -0,0 +1,16 @@ +#include "xtool.h" + +XConsole XCon; + +XConsole::XConsole(void) +{ +} + +XConsole::~XConsole(void) +{ +} + +XConsole& XConsole::operator< (const char*) +{ + return *this; +} diff --git a/MechoSoma/XTool/xerrhand.cpp b/MechoSoma/XTool/xerrhand.cpp new file mode 100644 index 00000000..f824b310 --- /dev/null +++ b/MechoSoma/XTool/xerrhand.cpp @@ -0,0 +1,56 @@ +#include "xtool.h" + +#include + +XErrorHandler ErrH; + +// TODO +XErrorHandler::XErrorHandler(void) +{ +} + +XErrorHandler::~XErrorHandler(void) +{ +} + +void XErrorHandler::SetFlags(unsigned f) +{ +} + +void XErrorHandler::ClearFlags(unsigned f) +{ +} + +unsigned XErrorHandler::InfoFlags(unsigned f) +{ +} + +void XErrorHandler::SetPrefix(const char* s) +{ +} + +void XErrorHandler::SetPostfix(const char* s) +{ +} + +void XErrorHandler::SetRestore(void (*rf)(void)) +{ +} + +void XErrorHandler::Abort(const char* message, int code, int addval, const char* subj) +{ + abort(); +} + +void XErrorHandler::Exit(void) +{ + exit(0); +} + +void XErrorHandler::RTC(const char *file,unsigned int line, const char *expr) +{ +} + +void XErrorHandler::WriteLog(char* error, char* msg) +{ +} diff --git a/MechoSoma/XTool/xgraph.cpp b/MechoSoma/XTool/xgraph.cpp new file mode 100644 index 00000000..e6575d01 --- /dev/null +++ b/MechoSoma/XTool/xgraph.cpp @@ -0,0 +1,579 @@ +#include "xgraph.h" + +#include +#include +#include + +void xtRegisterSysMsgFnc(void (*fPtr)(void*),int id); + +void XGR_MouseFnc(void* p); + +XGR_Screen XGR_Obj; +XGR_Mouse XGR_MouseObj; + +int xgrScreenSizeX = 0; +int xgrScreenSizeY = 0; + +int XGR_InitFlag = 0; + +int XGR_MouseOffsX = 0; +int XGR_MouseOffsY = 0; + +int XGR_MASK_R = 0; +int XGR_MASK_G = 0; +int XGR_MASK_B = 0; + +int XGR_SHIFT_R = 0; +int XGR_SHIFT_G = 0; +int XGR_SHIFT_B = 0; + +int XGR_COLOR_MASK_R = 0; +int XGR_COLOR_MASK_G = 0; +int XGR_COLOR_MASK_B = 0; + +int XGR_HighColorMode = 0; +int XGR_SysMsgFlag = 0; + +#define XGR_MOUSE_DEFSIZE_X 12 +#define XGR_MOUSE_DEFSIZE_Y 20 +static unsigned char XGR_MouseDefFrame[240] = +{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static unsigned short XGR_MouseDefFrameHC[240] = +{ + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0xFF0, 0x000, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0xFF0, 0x000, 0x000, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0x000, + 0x000, 0xFF0, 0x000, 0x000, 0x000, 0x000, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, 0x000, + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0xFF0, 0xFF0, 0x000, 0x000, 0x000, + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0xFF0, 0xFF0, 0x000, 0x000, + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0xFF0, 0xFF0, 0x000, 0x000, + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 +}; + +XGR_Mouse::XGR_Mouse(void) +{ + flags = XGM_AUTOCLIP; + + BackBuf = FrameBuf = NULL; + CurFrame = 0; + CurAlpha = 0; + + BegSeqFrame = EndSeqFrame = SeqDelta = 0; + SeqMode = XGM_PLAY_ONCE; + + BegSeqAlpha = EndSeqAlpha = AlphaSeqDelta = 0; + AlphaSeqMode = XGM_NONE; + + MovementX = MovementY = 0; + + SizeX = SizeY = 0; + PosX = PosY = 0; + PosZ = LastPosZ = MovementZ = 0; + + PromptColor = 255; + PromptX = PromptY = 0; + PromptDeltaX = PromptDeltaY = 0; + PromptSizeX = PromptSizeY = 0; + PromptFon = NULL; + promptData = NULL; + AlphaData = NULL; +} + +void XGR_Mouse::Init(int x, int y, int sx, int sy, int num, void* p) +{ + PosX = x; + PosY = y; + SizeX = sx; + SizeY = sy; + PosZ = LastPosZ = MovementZ = 0; + + OffsX = XGR_MouseOffsX; + OffsY = XGR_MouseOffsY; + + if (XGR_Obj.flags & XGR_HICOLOR) + { + flags |= XGM_HICOLOR; + } + else + { + flags &= ~XGM_HICOLOR; + } + + if (!p) + { + SizeX = sx = XGR_MOUSE_DEFSIZE_X; + SizeY = sy = XGR_MOUSE_DEFSIZE_Y; + num = 1; + p = XGR_MouseDefFrame; + if (flags & XGM_HICOLOR) + { + p = XGR_MouseDefFrameHC; + } + } + + if (flags & XGM_AUTOCLIP) + { + SetClipAuto(); + } + + SetPos(x, y); + SetCursor(sx, sy, num, p); + + if (!XGR_SysMsgFlag) + { + // TODO xtRegisterSysMsgFnc(XGR_MouseFnc, 0); + XGR_SysMsgFlag = 1; + } + + flags |= (XGM_VISIBLE | XGM_INIT); +} + +void XGR_Mouse::InitPos(int x, int y) +{ + LastPosX = PosX; + LastPosY = PosY; + + LastSizeX = SizeX; + LastSizeY = SizeY; + + PosX = x; + PosY = y; + + AdjustPos(); +} + +void XGR_Mouse::Hide(void) +{ + if (flags & XGM_VISIBLE) + { + flags &= ~XGM_VISIBLE; + Redraw(); + } + + if (flags & XGM_PROMPT_ACTIVE) + { + flags &= ~XGM_PROMPT_ACTIVE; + XGR_Flush(PromptX, PromptY, PromptSizeX, PromptSizeY); + } +} + +void XGR_Mouse::Show(void) +{ + if (!(flags & XGM_VISIBLE)) + { + flags |= XGM_VISIBLE; + Redraw(); + } +} + +void XGR_Mouse::Redraw(void) +{ +} + +void XGR_Mouse::SetCursor(int sx, int sy, int num, void* p) +{ +} + +void XGR_Mouse::SetPos(int x, int y) +{ + // TODO +} + +void XGR_Mouse::SetClipAuto(void) +{ + ClipCoords[XGR_LEFT] = ClipCoords[XGR_TOP] = 0; + ClipCoords[XGR_RIGHT] = XGR_MAXX - SizeX + 1; + ClipCoords[XGR_BOTTOM] = XGR_MAXY - SizeY + 1; +} + +void XGR_Mouse::AdjustPos(void) +{ + if (PosX < ClipCoords[XGR_LEFT]) + { + PosX = ClipCoords[XGR_LEFT]; + } + + if (PosX >= ClipCoords[XGR_RIGHT]) + { + PosX = ClipCoords[XGR_RIGHT] - 1; + } + + if (PosY < ClipCoords[XGR_TOP]) + { + PosY = ClipCoords[XGR_TOP]; + } + + if (PosY >= ClipCoords[XGR_BOTTOM]) + { + PosY = ClipCoords[XGR_BOTTOM] - 1; + } +} + +void XGR_Mouse::SetPressHandler(int bt, XGR_MOUSE_HANDLER p) +{ + switch (bt) + { + case XGM_LEFT_BUTTON: + lBt.Press = p; + break; + + case XGM_RIGHT_BUTTON: + rBt.Press = p; + break; + + case XGM_MIDDLE_BUTTON: + mBt.Press = p; + break; + } +} + +void XGR_Mouse::SetUnPressHandler(int bt, XGR_MOUSE_HANDLER p) +{ + switch (bt) + { + case XGM_LEFT_BUTTON: + lBt.UnPress = p; + break; + + case XGM_RIGHT_BUTTON: + rBt.UnPress = p; + break; + + case XGM_MIDDLE_BUTTON: + mBt.UnPress = p; + break; + } +} + +void XGR_Mouse::SetDblHandler(int bt, XGR_MOUSE_HANDLER p) +{ + switch (bt) + { + case XGM_LEFT_BUTTON: + lBt.DblClick = p; + break; + + case XGM_RIGHT_BUTTON: + rBt.DblClick = p; + break; + + case XGM_MIDDLE_BUTTON: + mBt.DblClick = p; + break; + } +} + +void XGR_Mouse::Move(int fl, int x, int y) +{ + if (flags & XGM_PROMPT_ACTIVE) + { + flags &= ~XGM_PROMPT_ACTIVE; + XGR_Flush(PromptX, PromptY, PromptSizeX, PromptSizeY); + } + + if (promptData) + { + promptData->Timer = 0; + } + + if (MoveH) + { + (*MoveH)(fl, x + SpotX, y + SpotY); + } +} + +void XGR_Mouse::Press(int bt, int fl, int x, int y) +{ + switch (bt) + { + case XGM_LEFT_BUTTON: + if (lBt.Press) + { + (*lBt.Press)(fl, x + SpotX, y + SpotY); + } + lBt.Pressed = 1; + break; + + case XGM_RIGHT_BUTTON: + if (rBt.Press) + { + (*rBt.Press)(fl, x + SpotX, y + SpotY); + } + rBt.Pressed = 1; + break; + + case XGM_MIDDLE_BUTTON: + if (mBt.Press) + { + (*mBt.Press)(fl, x + SpotX, y + SpotY); + } + mBt.Pressed = 1; + break; + } +} + +void XGR_Mouse::UnPress(int bt, int fl, int x, int y) +{ + switch (bt) + { + case XGM_LEFT_BUTTON: + if (lBt.UnPress) + { + (*lBt.UnPress)(fl, x + SpotX, y + SpotY); + } + lBt.Pressed = 0; + break; + + case XGM_RIGHT_BUTTON: + if (rBt.UnPress) + { + (*rBt.UnPress)(fl, x + SpotX, y + SpotY); + } + rBt.Pressed = 0; + break; + + case XGM_MIDDLE_BUTTON: + if (mBt.UnPress) + { + (*mBt.UnPress)(fl, x + SpotX, y + SpotY); + } + mBt.Pressed = 0; + break; + } +} + +void XGR_Mouse::DblClick(int bt, int fl, int x, int y) +{ + switch (bt) + { + case XGM_LEFT_BUTTON: + if (lBt.DblClick) + { + (*lBt.DblClick)(fl, x + SpotX, y + SpotY); + } + break; + + case XGM_RIGHT_BUTTON: + if (rBt.DblClick) + { + (*rBt.DblClick)(fl, x + SpotX, y + SpotY); + } + break; + + case XGM_MIDDLE_BUTTON: + if (mBt.DblClick) + { + (*mBt.DblClick)(fl, x + SpotX, y + SpotY); + } + break; + } +} + +void XGR_Pal64K::prepare(void* p) +{ + int i,R,G,B; + unsigned char* ptr = (unsigned char*)p; + + for(i = 0; i < 256; i ++){ + if(XGR_MASK_R == XGR_MASK_R0){ + R = ptr[i * 3] >> 1; + G = ptr[i * 3 + 1]; + B = ptr[i * 3 + 2] >> 1; + } + else { + R = ptr[i * 3] >> 1; + G = ptr[i * 3 + 1] >> 1; + B = ptr[i * 3 + 2] >> 1; + } + data[i] = XGR_RGB64K(R,G,B); + } +} + +XGR_Screen::XGR_Screen(void) +{ +} + +void XGR_Screen::set_pitch(int p) +{ + int i; + for (i = 0; i <= ScreenY; i++) + { + yOffsTable[i] = i * p; + } + + yStrOffs = p; +} + +void XGR_Screen::set_clip(int left,int top,int right,int bottom) +{ +} + +void XGR_Screen::get_clip(int& left,int& top,int& right,int& bottom) +{ +} + +void XGR_Screen::setpixel(int x,int y,int col) +{ +} + +int XGR_Screen::getpixel(int x,int y) +{ +} + +void XGR_Screen::flush(int x,int y,int sx,int sy) +{ +} + +void XGR_Screen::flush625(int x,int y,int sx,int sy) +{ +} + +void XGR_Screen::fill(int col) +{ +} + +void XGR_Screen::erase(int x,int y,int sx,int sy,int col) +{ +} + +void XGR_Screen::rectangle(int x,int y,int sx,int sy,int outcol,int incol,int mode) +{ +} + +void XGR_Screen::line(int x1,int y1,int x2,int y2,int col) +{ +} + +void XGR_Screen::lineto(int x,int y,int len,int dir,int col) +{ +} + +int XGR_Screen::init(int x,int y,int flags,void *hWnd) +{ +} + +void XGR_Screen::close(void) +{ +} + +void XGR_Screen::finit(void) +{ +} + +void XGR_Screen::putspr(int x,int y,int sx,int sy,void* p,int mode) +{ +} + +void XGR_Screen::getspr(int x,int y,int sx,int sy,void* p) +{ +} + +void XGR_Screen::getpal(void* p) +{ +} + +void XGR_Screen::setpal(void* pal,int start,int count) +{ +} + +void XGR_Screen::set_entries(int start,int count) +{ +} + +void XGR_Screen::capture_screen(char* bmp_name,char* pal_name) +{ +} + +// HiColor functions... +void XGR_Screen::putspr16(int x,int y,int sx,int sy,void* p,int mode) +{ +} + +void XGR_Screen::putspr16a(int x,int y,int sx,int sy,void* p,int mode,int alpha) +{ +} + +void XGR_Screen::putspr16ap(int x,int y,int sx,int sy,void* p,int mode,void* alpha_ptr) +{ +} + +void XGR_Screen::getspr16(int x,int y,int sx,int sy,void* p) +{ +} + +void XGR_Screen::erase16(int x,int y,int sx,int sy,int col) +{ +} + +void XGR_Screen::fill16(int col) +{ + int i, j; + unsigned short* ptr = (unsigned short*)ScreenBuf; + for (i = 0; i < ScreenY; i++) + { + ptr = (unsigned short*)(ScreenBuf + yOffsTable[i]); + for (j = 0; j < ScreenX; j++) + { + ptr[j] = col; + } + } +} + +void XGR_Screen::setpixel16(int x,int y,int col) +{ +} + +void XGR_Screen::line16(int x1,int y1,int x2,int y2,int col) +{ +} + +void XGR_Screen::lineto16(int x,int y,int len,int dir,int col) +{ +} + +void XGR_Screen::rectangle16(int x,int y,int sx,int sy,int outcol,int incol,int mode) +{ +} + +void XGR_OutText(int x,int y,int col,void* text,int font,int hspace,int vspace,int pr_flag) +{ +} + +void XGR_MouseFnc(void* p) +{ + // TODO +} diff --git a/MechoSoma/XTool/xgraph.h b/MechoSoma/XTool/xgraph.h new file mode 100644 index 00000000..cd9d05c0 --- /dev/null +++ b/MechoSoma/XTool/xgraph.h @@ -0,0 +1,534 @@ +/* +******************************************************************************* +** ** +** Low-level debug-graphics library (Win32 compatible) ** +** (C) 1997 K-D Lab::Steeler ** +** Version 1.00 ** +** ** +******************************************************************************* +*/ + +#ifndef __XGRAPH_H__ +#define __XGRAPH_H__ + +#include "xtool.h" + +#include + +// Some defines for 64K modes... +const int XGR_MASK_R1 = 0x7C00; +const int XGR_MASK_G1 = 0x03E0; +const int XGR_MASK_B1 = 0x001F; + +const int XGR_MASK_R0 = 0xF800; +const int XGR_MASK_G0 = 0x07E0; +const int XGR_MASK_B0 = 0x001F; + +const int XGR_SHIFT_R1 = 10; +const int XGR_SHIFT_G1 = 5; +const int XGR_SHIFT_B1 = 0; + +const int XGR_SHIFT_R0 = 11; +const int XGR_SHIFT_G0 = 5; +const int XGR_SHIFT_B0 = 0; + +const int XGR_COLOR_MASK_R1 = 0x001F; +const int XGR_COLOR_MASK_G1 = 0x001F; +const int XGR_COLOR_MASK_B1 = 0x001F; + +const int XGR_COLOR_MASK_R0 = 0x001F; +const int XGR_COLOR_MASK_G0 = 0x003F; +const int XGR_COLOR_MASK_B0 = 0x001F; + +#define XGR_RGB64K(r,g,b) (((r) << XGR_SHIFT_R) + ((g) << XGR_SHIFT_G) + ((b) << XGR_SHIFT_B)) +#define XGR_64KR(c) (((c) >> XGR_SHIFT_R) & XGR_COLOR_MASK_R) +#define XGR_64KG(c) (((c) >> XGR_SHIFT_G) & XGR_COLOR_MASK_G) +#define XGR_64KB(c) (((c) >> XGR_SHIFT_B) & XGR_COLOR_MASK_B) + +// Directions for XGR_LineTo() +enum XGR_LINEDIR +{ + XGR_LEFT, + XGR_TOP, + XGR_RIGHT, + XGR_BOTTOM +}; + +// Modes for XGR_PutSpr() +#define XGR_HIDDEN_FON 0x01 +#define XGR_BLACK_FON 0x02 +#define XGR_CLIPPED 0x04 +#define XGR_NOCLIP 0x08 +#define XGR_BOTTOM_UP 0x10 + +// Modes for XGR_Rectangle() +#define XGR_FILLED 0x00 +#define XGR_OUTLINED 0x01 + +#define XGR_NUM_FONTS 0x02 + +typedef void (*XGR_OutTextHandler)(int x,int y,int col,void* text,int font,int hspace,int vspace); +typedef int (*XGR_TextWidthHandler)(void* text,int font,int hspace,int vspace); +typedef int (*XGR_TextHeightHandler)(void* text,int font,int hspace,int vspace); + +// XGR_Font IDs... +#define XGR_FONT0_8x16 0 +#define XGR_FONT0_8x8 1 + +struct XGR_Font +{ + int SizeX; + int SizeY; + + unsigned char* LeftOffs; + unsigned char* RightOffs; + + unsigned char* data; + + void init(int size,void* p); + + XGR_Font(void); +}; + +// XGR_Screen::flags... +#define XGR_EXCLUSIVE 0x01 +#define XGR_REINIT 0x02 +#define XGR_PALETTE 0x04 +#define XGR_INIT 0x08 +#define XGR_HICOLOR 0x10 + +// XGR_Screen::ClipMode values... +#define XGR_CLIP_PUTSPR 0x00 +#define XGR_CLIP_ALL 0x01 + +struct XGR_Pal64K +{ + int ID; + + unsigned* data; + void prepare(void* p); + + unsigned operator[](int ind) const { return data[ind]; } + unsigned& operator[](int ind){ return data[ind]; } + + XGR_Pal64K(void){ ID = 0; data = new unsigned[256]; } + ~XGR_Pal64K(void){ delete data; } +}; + +struct XGR_Screen +{ + int flags; + + int ScreenX; + int ScreenY; + + unsigned char* ScreenBuf; + + int ClipMode; + + int clipLeft; + int clipTop; + int clipRight; + int clipBottom; + + int yStrOffs; + int* yOffsTable; + + void set_pitch(int p); + void set_clip(int left,int top,int right,int bottom); + void get_clip(int& left,int& top,int& right,int& bottom); + void set_clip_mode(int mode){ ClipMode = mode; } + + void setpixel(int x,int y,int col); + int getpixel(int x,int y); + + void flush(int x,int y,int sx,int sy); + void flush625(int x,int y,int sx,int sy); + + void fill(int col); + void erase(int x,int y,int sx,int sy,int col); + + void rectangle(int x,int y,int sx,int sy,int outcol,int incol,int mode); + + void line(int x1,int y1,int x2,int y2,int col); + void lineto(int x,int y,int len,int dir,int col); + + int init(int x,int y,int flags,void *hWnd=0); + void close(void); + void finit(void); + + void putspr(int x,int y,int sx,int sy,void* p,int mode); + + void getspr(int x,int y,int sx,int sy,void* p); + + void getpal(void* p); + void setpal(void* pal,int start,int count); + void set_entries(int start,int count); + + void capture_screen(char* bmp_name,char* pal_name); + + // HiColor functions... + void putspr16(int x,int y,int sx,int sy,void* p,int mode); + void putspr16a(int x,int y,int sx,int sy,void* p,int mode,int alpha); + void putspr16ap(int x,int y,int sx,int sy,void* p,int mode,void* alpha_ptr); + void getspr16(int x,int y,int sx,int sy,void* p); + + void erase16(int x,int y,int sx,int sy,int col); + void fill16(int col); + + void setpixel16(int x,int y,int col); + + void line16(int x1,int y1,int x2,int y2,int col); + void lineto16(int x,int y,int len,int dir,int col); + + void rectangle16(int x,int y,int sx,int sy,int outcol,int incol,int mode); + + XGR_Screen(void); +}; + +// XGR_MousePromptData::flags... +#define XGR_PROMPT_ACTIVE 0x01 +#define XGR_PROMPT_MEM_ALLOC 0x02 + +struct XGR_MousePromptData : XListElement +{ + int ID; + + int StartX; + int StartY; + + int SizeX; + int SizeY; + + int font; + + int flags; + + int textSizeX; + int textSizeY; + char* textData; + + void init(void); + void init_text(char* p); + void set_text(char* p); + + int check_xy(int x,int y); + + XGR_MousePromptData(void); + XGR_MousePromptData(int x,int y,int sx,int sy,int fnt); + ~XGR_MousePromptData(void); +}; + +struct XGR_MousePromptScreen : XList +{ + int Timer; + int ActivateTimer; + + int curFont; + char* curText; + + XGR_MousePromptData* check_xy(int x,int y); + XGR_MousePromptData* getData(int id); + + XGR_MousePromptScreen(void); + ~XGR_MousePromptScreen(void); +}; + +typedef void (*XGR_MOUSE_HANDLER)(int, int, int); + +struct XGR_MouseButton +{ + XGR_MOUSE_HANDLER Press; + XGR_MOUSE_HANDLER UnPress; + XGR_MOUSE_HANDLER DblClick; + unsigned int Pressed; + + void SetPress(XGR_MOUSE_HANDLER p){ Press = p; } + void SetUnPress(XGR_MOUSE_HANDLER p){ UnPress = p; } + void SetDblClick(XGR_MOUSE_HANDLER p){ DblClick = p; } + + XGR_MouseButton(void){ Press = UnPress = DblClick = NULL; Pressed = 0; } +}; + +#define XGM_LEFT_BUTTON 0x01 +#define XGM_RIGHT_BUTTON 0x02 +#define XGM_MIDDLE_BUTTON 0x03 + +// XGR_Mouse::flags... +#define XGM_INIT 0x01 +#define XGM_VISIBLE 0x02 +#define XGM_AUTOCLIP 0x04 +#define XGM_PROMPT_ACTIVE 0x08 +#define XGM_HICOLOR 0x10 +#define XGM_DISABLE_PROMPT 0x20 + +// XGR_Mouse::SeqMode values... +#define XGM_NONE 0 +#define XGM_PLAY_ONCE 1 +#define XGM_PLAY_INFINITE 2 + +struct XGR_Mouse +{ + int flags; + + int ClipCoords[4]; + + int SizeX; + int SizeY; + + int MovementX; // � ������� ��������� �� ������������, ����� �� ������������ + int MovementY; + int MovementZ; + + int NumFrames; + unsigned char* FrameBuf; + unsigned char* BackBuf; + + int CurFrame; + + int BegSeqFrame; + int EndSeqFrame; + int SeqDelta; + int SeqMode; + + int CurAlpha; + unsigned char* AlphaData; + + int BegSeqAlpha; + int EndSeqAlpha; + int AlphaSeqDelta; + int AlphaSeqMode; + + int PosX; + int PosY; + int PosZ; // Wheel + + int OffsX; + int OffsY; + + int LastPosX; + int LastPosY; + int LastPosZ; + int LastSizeX; + int LastSizeY; + + int SpotX; + int SpotY; + + XGR_MouseButton lBt; + XGR_MouseButton rBt; + XGR_MouseButton mBt; + + XGR_MOUSE_HANDLER MoveH; + + int PromptDeltaX; + int PromptDeltaY; + + int PromptX; + int PromptY; + + int PromptColor; + + int PromptSizeX; + int PromptSizeY; + + int PromptFonBufSize; + char* PromptFon; + + XGR_MousePromptScreen* promptData; + + void Init(int x,int y,int sx,int sy,int num,void* p); + + void SetClipAuto(void); + void SetClip(int l,int t,int r,int b){ + ClipCoords[XGR_LEFT] = l; ClipCoords[XGR_TOP] = t; + ClipCoords[XGR_RIGHT] = r; ClipCoords[XGR_BOTTOM] = b; + } + void SetCursor(int sx,int sy,int num,void* p); + void SetSpot(int x,int y){ SpotX = x; SpotY = y; } + void SetSeq(int beg,int end,int mode,int delta); + void SetAlphaSeq(int beg,int end,int mode,int delta); + + void InitPos(int x,int y); + void SetPos(int x,int y); + + void Hide(void); + void Show(void); + + void Redraw(void); + void PutFrame(void); + void PutFon(void); + void GetFon(void); + int NextFrame(void); + int NextPromptFrame(void); + + void InitPrompt(void); + void RedrawPrompt(void); + void PutPrompt(void); + void PutPromptFon(void); + void GetPromptFon(void); + void DisablePrompt(void){ flags |= XGM_DISABLE_PROMPT; } + void EnablePrompt(void){ flags &= ~XGM_DISABLE_PROMPT; } + + void SetPromptData(XGR_MousePromptScreen* p){ promptData = p; } + + void AdjustPos(void); + + int Visible(void){ return (flags & XGM_VISIBLE); } + int CheckRedraw(int x,int y,int sx,int sy); + int CheckPromptRedraw(int x,int y,int sx,int sy); + + void SetMoveHandler(XGR_MOUSE_HANDLER p){ MoveH = p; } + + void SetPressHandler(int bt,XGR_MOUSE_HANDLER p); + void SetUnPressHandler(int bt,XGR_MOUSE_HANDLER p); + void SetDblHandler(int bt,XGR_MOUSE_HANDLER p); + + void Move(int fl,int x,int y); + + void Press(int bt,int fl,int x,int y); + void UnPress(int bt,int fl,int x,int y); + void DblClick(int bt,int fl,int x,int y); + + XGR_Mouse(void); +}; + +#define XGR_Init(x,y,fl) XGR_Obj.init(x,y,fl) +#define XGR_ReInit(x,y,fl) XGR_Obj.init(x,y,fl | XGR_REINIT) +#define XGR_Finit() XGR_Obj.finit() +#define XGR_SetClip(left,top,right,bottom) XGR_Obj.set_clip(left,top,right,bottom) +#define XGR_GetClip(left,top,right,bottom) XGR_Obj.get_clip(left,top,right,bottom) +#define XGR_SetClipMode(mode) XGR_Obj.set_clip_mode(mode) + +#define XGR_Flush(x,y,sx,sy) XGR_Obj.flush(x,y,sx,sy) +#define XGR_Flush625(x,y,sx,sy) XGR_Obj.flush625(x,y,sx,sy) +#define XGR_Fill(col) XGR_Obj.fill(col) +#define XGR_Erase(x,y,sx,sy,col) XGR_Obj.erase(x,y,sx,sy,col) +#define XGR_Rectangle(x,y,sx,sy,outcol,incol,mode) XGR_Obj.rectangle(x,y,sx,sy,outcol,incol,mode) + +#define XGR_SetPixel(x,y,col) XGR_Obj.setpixel(x,y,col) +#define XGR_GetPixel(x,y) XGR_Obj.getpixel(x,y) + +#define XGR_Line(x1,y1,x2,y2,col) XGR_Obj.line(x1,y1,x2,y2,col) +#define XGR_LineTo(x,y,len,dir,col) XGR_Obj.lineto(x,y,len,dir,col) + +#define XGR_SetPal(ptr,st,cnt) XGR_Obj.setpal(ptr,st,cnt) +#define XGR_GetPal(ptr) XGR_Obj.getpal(ptr) + +#define XGR_PutSpr(x,y,sx,sy,p,mode) XGR_Obj.putspr(x,y,sx,sy,p,mode) +#define XGR_GetSpr(x,y,sx,sy,p) XGR_Obj.getspr(x,y,sx,sy,p) + +#define XGR_WriteScreen(bmp_name,pal_name) XGR_Obj.capture_screen(bmp_name,pal_name) + +#ifdef XGR_SUPPRESS_HICOLOR +#define XGR_PutSpr16(x,y,sx,sy,p,mode) XGR_Obj.putspr(x,y,sx,sy,p,mode) +#define XGR_GetSpr16(x,y,sx,sy,p) XGR_Obj.getspr(x,y,sx,sy,p) +#define XGR_PutSpr16a(x,y,sx,sy,p,mode,alpha) XGR_Obj.putspr(x,y,sx,sy,p,mode) +#define XGR_PutSpr16ap(x,y,sx,sy,p,mode,alpha) XGR_Obj.putspr(x,y,sx,sy,p,mode) +#define XGR_Erase16(x,y,sx,sy,col) XGR_Obj.erase(x,y,sx,sy,col) +#define XGR_Fill16(col) XGR_Obj.fill(col) +#define XGR_SetPixel16(x,y,col) XGR_Obj.setpixel(x,y,col) +#define XGR_Line16(x1,y1,x2,y2,col) XGR_Obj.line(x1,y1,x2,y2,col) +#define XGR_LineTo16(x,y,len,dir,col) XGR_Obj.lineto(x,y,len,dir,col) +#define XGR_Rectangle16(x,y,sx,sy,outcol,incol,mode) XGR_Obj.rectangle(x,y,sx,sy,outcol,incol,mode) +#else +#define XGR_PutSpr16(x,y,sx,sy,p,mode) XGR_Obj.putspr16(x,y,sx,sy,p,mode) +#define XGR_GetSpr16(x,y,sx,sy,p) XGR_Obj.getspr16(x,y,sx,sy,p) +#define XGR_PutSpr16a(x,y,sx,sy,p,mode,alpha) XGR_Obj.putspr16a(x,y,sx,sy,p,mode,alpha) +#define XGR_PutSpr16ap(x,y,sx,sy,p,mode,alpha) XGR_Obj.putspr16ap(x,y,sx,sy,p,mode,alpha) +#define XGR_Erase16(x,y,sx,sy,col) XGR_Obj.erase16(x,y,sx,sy,col) +#define XGR_Fill16(col) XGR_Obj.fill16(col) +#define XGR_SetPixel16(x,y,col) XGR_Obj.setpixel16(x,y,col) +#define XGR_Line16(x1,y1,x2,y2,col) XGR_Obj.line16(x1,y1,x2,y2,col) +#define XGR_LineTo16(x,y,len,dir,col) XGR_Obj.lineto16(x,y,len,dir,col) +#define XGR_Rectangle16(x,y,sx,sy,outcol,incol,mode) XGR_Obj.rectangle16(x,y,sx,sy,outcol,incol,mode) +#endif + +#define XGR_MouseInit(x,y,sx,sy,num,p) XGR_MouseObj.Init(x,y,sx,sy,num,p) +#define XGR_MouseSetCursor(sx,sy,num,p) XGR_MouseObj.SetCursor(sx,sy,num,p) +#define XGR_MouseSetSpot(x,y) XGR_MouseObj.SetSpot(x,y) +#define XGR_MouseInitPos(x,y) XGR_MouseObj.InitPos(x,y) +#define XGR_MouseVisible() XGR_MouseObj.Visible() + +#define XGR_MouseCheckRedraw(x,y,sx,sy) XGR_MouseObj.CheckRedraw(x,y,sx,sy) +#define XGR_MouseNextFrame() XGR_MouseObj.NextFrame() +#define XGR_MouseSetSeq(beg,end,mode,delta) XGR_MouseObj.SetSeq(beg,end,mode,delta) +#define XGR_MouseSetAlphaSeq(beg,end,mode,delta) XGR_MouseObj.SetAlphaSeq(beg,end,mode,delta) + +#define XGR_MouseRedraw() XGR_MouseObj.Redraw() +#define XGR_MousePutFrame() XGR_MouseObj.PutFrame() +#define XGR_MousePutFon() XGR_MouseObj.PutFon() +#define XGR_MouseGetFon() XGR_MouseObj.GetFon() + +#define XGR_MouseSetPressHandler(bt,p) XGR_MouseObj.SetPressHandler(bt,p) +#define XGR_MouseSetUnPressHandler(bt,p) XGR_MouseObj.SetUnPressHandler(bt,p) +#define XGR_MouseSetDblHandler(bt,p) XGR_MouseObj.SetDblHandler(bt,p) +#define XGR_MouseSetMoveHandler(p) XGR_MouseObj.SetMoveHandler(p) + +#define XGR_MousePress(bt,fl,x,y) XGR_MouseObj.Press(bt,fl,x,y) +#define XGR_MouseUnPress(bt,fl,x,y) XGR_MouseObj.UnPress(bt,fl,x,y) +#define XGR_MouseDblClick(bt,fl,x,y) XGR_MouseObj.DblClick(bt,fl,x,y) +#define XGR_MouseMove(fl,x,y) XGR_MouseObj.Move(fl,x,y) + +#define XGR_MouseHide() XGR_MouseObj.Hide() +#define XGR_MouseShow() XGR_MouseObj.Show() + +#define XGR_MouseSetPos(x,y) XGR_MouseObj.SetPos(x,y) +#define XGR_MouseSetPromptData(p) XGR_MouseObj.SetPromptData(p) + +#define XGR_MouseCurFrame XGR_MouseObj.CurFrame +#define XGR_MouseNumFrames XGR_MouseObj.NumFrames + +extern int xgrScreenSizeX; +extern int xgrScreenSizeY; + +#define XGR_MAXX xgrScreenSizeX +#define XGR_MAXY xgrScreenSizeY + +#define XGR_VIDEOBUF XGR_Obj.ScreenBuf + +extern XGR_Screen XGR_Obj; +extern XGR_Mouse XGR_MouseObj; + +void XGR_OutString(int x,int y,int col,void* str,int font = 0,int space = 1,int pr_flag = 1); +int XGR_StrLen(void* str,int font = 0,int space = 1); + +void XGR_OutText(int x,int y,int col,void* text,int font = 0,int hspace = 1,int vspace = 1,int pr_flag = 1); +int XGR_TextHeight(void* text,int font = 0,int hspace = 1,int vspace = 1); +int XGR_TextWidth(void* text,int font = 0,int hspace = 1,int vspace = 1); + +inline unsigned char* XGR_GetVideoLine(int y){ return (XGR_Obj.ScreenBuf + XGR_Obj.yOffsTable[y]); } + +inline void XGR_SetPixelFast(int x,int y,int col){ XGR_Obj.ScreenBuf[XGR_Obj.yOffsTable[y] + x] = col; } +inline void XGR_SetPixel16Fast(int x,int y,int col){ + unsigned short* p = (unsigned short*)(XGR_Obj.ScreenBuf + XGR_Obj.yOffsTable[y]); + p[x] = col; +} + +// Convert 8bit sprite into 16bit sprite... +void XGR_PrepareSprite(int sx,int sy,void* dst_buf,void* src_buf,XGR_Pal64K* pal); + +// Set text output handlers... +void XGR_SetTextOutFnc(XGR_OutTextHandler p); +void XGR_SetTextXFnc(XGR_TextWidthHandler p); +void XGR_SetTextYFnc(XGR_TextHeightHandler p); + +extern int XGR_MASK_R; +extern int XGR_MASK_G; +extern int XGR_MASK_B; + +extern int XGR_SHIFT_R; +extern int XGR_SHIFT_G; +extern int XGR_SHIFT_B; + +extern int XGR_COLOR_MASK_R; +extern int XGR_COLOR_MASK_G; +extern int XGR_COLOR_MASK_B; + +extern char* XGraphWndID; + +extern int XGR_HighColorMode; + +#endif /* __XGRAPH_H */ + + diff --git a/MechoSoma/XTool/xkey.cpp b/MechoSoma/XTool/xkey.cpp new file mode 100644 index 00000000..d09b262b --- /dev/null +++ b/MechoSoma/XTool/xkey.cpp @@ -0,0 +1,130 @@ +#include "xtool.h" + +#include + +XKeyStruct XKey; + +XKeyStruct::XKeyStruct() +{ + memset(keyStates, 0, XKEY_MAXCODE); + for (int i = 0; i < XKEY_MAXCODE; i++) + { + keyPressFnc[i] = NULL; + keyUnpressFnc[i] = NULL; + } + + pressHandler = NULL; + unpressHandler = NULL; +} + +XKeyStruct::~XKeyStruct() +{ +} + +void XKeyStruct::init(void* pH, void* upH) +{ + pressHandler = pH; + unpressHandler = upH; +} + +void XKeyStruct::setPress(int key, void (*keyFunction)(void), int repeat) +{ + keyPressFnc[key] = keyFunction; + if (repeat) + { + keyStates[key] |= XKEY_REPEAT; + } +} + +void XKeyStruct::setUnpress(int key, void (*keyFunction)(void)) +{ + keyUnpressFnc[key] = keyFunction; +} + +void XKeyStruct::clear(void) +{ + memset(keyStates, 0, XKEY_MAXCODE); +} + +int XKeyStruct::Pressed(int key) +{ + return (keyStates[key] & XKEY_PRESSED); +} + +int XKeyStruct::wasPressed(int key) +{ + if (keyStates[key] & XKEY_WASPRESSED) + { + if (!(keyStates[key] & XKEY_PRESSED)) + { + keyStates[key] &= ~XKEY_WASPRESSED; + } + return 1; + } + return 0; +} + +void XKeyStruct::PressFnc(int vkey, int key) +{ + int rptCount = key & 0xFFFF; + + LastScanCode = key; + + keyStates[vkey] |= (XKEY_PRESSED | XKEY_WASPRESSED); + if (keyPressFnc[vkey]) + { + if (!(keyStates[vkey] & XKEY_REPEAT)) + { + rptCount = 1; + } + + for (int i = 0; i < rptCount; i++) + { + (*(PFK)(keyPressFnc[vkey]))(); + } + } + else + { + if (pressHandler) + { + for (int i = 0; i < rptCount; i++) + { + (*(PFN)(pressHandler))(vkey); + } + } + } +} + +void XKeyStruct::UnPressFnc(int vkey, int key) +{ + int rptCount = key & 0xFFFF; + + LastScanCode = key; + + keyStates[vkey] &= ~XKEY_PRESSED; + + if (keyUnpressFnc[vkey]) + { + (*(PFK)(keyUnpressFnc[vkey]))(); + } + else + { + if (unpressHandler) + { + for (int i = 0; i < rptCount; i++) + { + (*(PFN)(unpressHandler))(vkey); + } + } + } +} + +int xtGetKeyName(int vkey,int shift,int russian) +{ + return 0; +} + +char* xtGetKeyNameText(int key) +{ + return nullptr; +} diff --git a/MechoSoma/XTool/xmath.h b/MechoSoma/XTool/xmath.h new file mode 100644 index 00000000..19486ddc --- /dev/null +++ b/MechoSoma/XTool/xmath.h @@ -0,0 +1,5262 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// All 3D-functionality +// +// Configuration: +// Define _XMATH_NO_IOSTREAM to disable iostream using +// +/////////////////////////////////////////////////////////////////////////////// +#ifndef __XMATH_H__ +#define __XMATH_H__ + +#include + +#ifndef _XMATH_NO_IOSTREAM +#include +using std::istream; +using std::ostream; +using std::endl; +#endif + +/////////////////////////////////////////////////////////////////////////////// +// Structures predefenition +/////////////////////////////////////////////////////////////////////////////// + +class Vect2f; +class Vect2i; +class Vect2s; +class Vect3f; +class Vect3d; +class Mat3f; +class Mat3d; +class MatXf; +class MatXd; +class QuatF; +class QuatD; +class Se3f; +class Se3d; + +class Vect4f; +class Mat4f; + +struct XStream; +struct XBuffer; + +/////////////////////////////////////////////////////////////////////////////// +// Axes +/////////////////////////////////////////////////////////////////////////////// +enum eAxis { X_AXIS, Y_AXIS, Z_AXIS, W_AXIS }; + + +/////////////////////////////////////////////////////////////////////////////// +// Constants +/////////////////////////////////////////////////////////////////////////////// +#undef M_PI +#define M_PI 3.14159265358979323846f + +const double DBL_EPS = 1.e-15; +const double DBL_INF = 1.e+100; +const double DBL_COMPARE_TOLERANCE = 1.e-10; + +const float FLT_EPS = 1.e-7f; +const float FLT_INF = 1.e+30f; +const float FLT_COMPARE_TOLERANCE = 1.e-5f; + +const int INT_INF = 0x7fffffff; + +#if _MSC_VER == 1100 /* if MSVisual C++ 5.0 */ +#define xm_inline inline +#else +#define xm_inline __forceinline +#endif //_MSC_VER + +/////////////////////////////////////////////////////////////////////////////// +// +// Scalar Functions +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef __ROUND__ +#define __ROUND__ + +xm_inline int round(double x) +{ + int a; + _asm { + fld x + fistp dword ptr a + } + return a; +} + +xm_inline int round(float x) +{ + int a; + _asm { + fld x + fistp dword ptr a + } + return a; +} + +template +xm_inline T sqr(const T& x){ return x*x; } + +template +xm_inline int SIGN(const T& x) { return x ? (x > 0 ? 1 : -1 ) : 0; } + +#endif // __ROUND__ + +xm_inline double SIGN(double a, double b) { return b >= 0.0 ? fabs(a) : -fabs(a); } +xm_inline float SIGN(float a, float b) { return b >= 0.0f ? fabsf(a) : -fabsf(a); } + +class RandomGenerator +{ + enum { max_value = 0x7fff }; + int value; +public: + RandomGenerator(int val = 1) { set(val); } + void set(int val) { value = val; } + int get() const { return value; } + int operator()(); // Generates random value [0..max_value], non-inline due to some bugs with optimization + xm_inline int operator()(int m) { return m ? (*this)() % m : 0; } // May by used in random_shuffle + xm_inline float frnd(float x = 1.f){ return (float)((*this)()*2 - max_value)*x/(float)max_value; } + xm_inline float fabsRnd(float x = 1.f){ return (float)((*this)())*x/(float)max_value; } + xm_inline float frand(){ return (*this)()/(float)max_value; } +}; + +#undef random +extern RandomGenerator xm_random_generator; +xm_inline unsigned random(unsigned m){ return xm_random_generator(m); } +xm_inline float frnd(float x){ return xm_random_generator.frnd(x); } +xm_inline float fabsRnd(float x){ return xm_random_generator.fabsRnd(x); } + + +#define NOMINMAX +#undef min +#undef max + +xm_inline int min(int x,int y){ return x < y ? x : y; } +xm_inline float min(float x,float y){ return x < y ? x : y; } +xm_inline double min(double x,double y){ return x < y ? x : y; } + +xm_inline int max(int x,int y){ return x > y ? x : y; } +xm_inline float max(float x,float y){ return x > y ? x : y; } +xm_inline double max(double x,double y){ return x > y ? x : y; } + + +template xm_inline T min(const T& a, const T& b, const T& c) { return min(min(a, b), c); } +template xm_inline T max(const T& a, const T& b, const T& c) { return max(max(a, b), c); } + +xm_inline int mina(int x,int y){ return abs(x) < abs(y) ? x : y; } +xm_inline int mina(int x,int y,int z){ return mina(mina(x,y),z); } + +xm_inline int maxa(int x,int y){ return abs(x) > abs(y) ? x : y; } +xm_inline int maxa(int x,int y,int z){ return maxa(maxa(x,y),z); } + +xm_inline double mina(double x,double y){ return fabs(x) < fabs(y) ? x : y; } +xm_inline double mina(double x,double y,double z){ return mina(mina(x,y),z); } + +xm_inline double maxa(double x,double y){ return fabs(x) > fabs(y) ? x : y; } +xm_inline double maxa(double x,double y,double z){ return maxa(maxa(x,y),z); } + +xm_inline int minAbs(int x,int y){ return abs(x) < abs(y) ? abs(x) : abs(y); } +xm_inline int minAbs(int x,int y,int z){ return minAbs(minAbs(x,y),z); } + +xm_inline int maxAbs(int x,int y){ return abs(x) > abs(y) ? abs(x) : abs(y); } +xm_inline int maxAbs(int x,int y,int z){ return maxAbs(maxAbs(x,y),z); } + +xm_inline double minAbs(double x,double y){ return fabs(x) < fabs(y) ? fabs(x) : fabs(y); } +xm_inline double minAbs(double x,double y,double z){ return minAbs(minAbs(x,y),z); } + +xm_inline double maxAbs(double x,double y){ return fabs(x) > fabs(y) ? fabs(x) : fabs(y); } +xm_inline double maxAbs(double x,double y,double z){ return maxAbs(maxAbs(x,y),z); } + + +xm_inline void average(double& x_avr, double x, double tau){ x_avr = x_avr*(1. - tau) + tau*x; } +xm_inline void average(double& x_avr, double x, double tau, double factor){ tau = pow(tau, factor); x_avr = x_avr*(1. - tau) + tau*x; } +xm_inline void average(float& x_avr, float x, float tau){ x_avr = x_avr*(1.f - tau) + tau*x; } +xm_inline void average(float& x_avr, float x, float tau, float factor){ tau = (float)pow(tau, factor); x_avr = x_avr*(1.f - tau) + tau*x; } + +#define G2R(x) ((x)*M_PI/180.f) +#define R2G(x) ((x)*180.f/M_PI) + +xm_inline float Acos(float x){ return x > 1.f ? 0 : (x < -1.f ? M_PI : acosf(x)); } +xm_inline double Acos(double x){ return x > 1. ? 0 : (x < -1. ? M_PI : acos(x)); } + +template +xm_inline T clamp(const T& x, const T1& xmin, const T2& xmax) { if(x < xmin) return xmin; if(x > xmax) return xmax; return x; } + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Vect2f +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Vect2f +{ +public: + float x,y; + + xm_inline Vect2f() { } + xm_inline Vect2f(float x_,float y_) { x = x_; y = y_; } + + typedef float float2[2]; + xm_inline Vect2f(const float2& v) { x = v[0]; y = v[1]; } + + xm_inline Vect2f(const Vect3f& v); + xm_inline Vect2f(const Vect2i& v); + xm_inline Vect2f(const Vect2s& v); + + xm_inline Vect2f& set(float x_, float y_) { x = x_; y = y_; return *this; } + xm_inline Vect2f operator - () const { return Vect2f(-x,-y); } + + xm_inline int xi() const { return round(x); } + xm_inline int yi() const { return round(y); } + + xm_inline const float& operator[](int i) const { return *(&x + i); } + xm_inline float& operator[](int i) { return *(&x + i); } + + xm_inline Vect2f& operator += (const Vect2f &v) { x += v.x; y += v.y; return *this; } + xm_inline Vect2f& operator -= (const Vect2f &v) { x -= v.x; y -= v.y; return *this; } + xm_inline Vect2f& operator *= (const Vect2f &v) { x *= v.x; y *= v.y; return *this; } + xm_inline Vect2f& operator /= (const Vect2f &v) { x /= v.x; y /= v.y; return *this; } + xm_inline Vect2f& operator *= (float f) { x *= f; y *= f; return *this; } + xm_inline Vect2f& operator /= (float f) { if(f != 0.f) f = 1/f; else f = 0.0001f; x *= f; y *= f; return *this; } + + xm_inline Vect2f operator + (const Vect2f &v) const { return Vect2f(*this) += v; } + xm_inline Vect2f operator - (const Vect2f &v) const { return Vect2f(*this) -= v; } + xm_inline Vect2f operator * (const Vect2f &v) const { return Vect2f(*this) *= v; } + xm_inline Vect2f operator * (float f) const { return Vect2f(*this) *= f; } + xm_inline Vect2f operator / (float f) const { return Vect2f(*this) /= f; } + + xm_inline int operator== (const Vect2f &v) const { return v.x == x && v.y==y; } + + xm_inline float dot(const Vect2f& v) const { return x*v.x + y*v.y; } + xm_inline friend float dot(const Vect2f& u, const Vect2f& v) { return u.dot(v); } + + xm_inline float operator % (const Vect2f &v) const { return x*v.y - y*v.x; } + + xm_inline float norm() const { return sqrtf(x*x + y*y); } + xm_inline float norm2() const { return x*x + y*y; } + xm_inline void normalize(float norma) { float f = norma/sqrtf(x*x + y*y); x *= f; y *= f; } + xm_inline float distance(const Vect2f &v) const { return sqrtf(distance2(v)); } + xm_inline float distance2(const Vect2f &v) const { float dx = x - v.x, dy = y - v.y; return dx*dx + dy*dy; } + + xm_inline void swap(Vect2f &v) { Vect2f tmp = v; v = *this; *this = tmp; } + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Vect2f& v); + friend istream& operator>> (istream& is, Vect2f& v); + + friend XStream& operator<= (XStream& s,const Vect2f& v); + friend XStream& operator>= (XStream& s,Vect2f& v); + friend XStream& operator< (XStream& s,const Vect2f& v); + friend XStream& operator> (XStream& s,Vect2f& v); + + friend XBuffer& operator<= (XBuffer& b,const Vect2f& v); + friend XBuffer& operator>= (XBuffer& b,Vect2f& v); + friend XBuffer& operator< (XBuffer& b,const Vect2f& v); + friend XBuffer& operator> (XBuffer& b,Vect2f& v); + + static const Vect2f ZERO; + static const Vect2f ID; +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Vect2i +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Vect2i +{ +public: + int x,y; + + xm_inline Vect2i() { } + xm_inline Vect2i(int x_, int y_) { x = x_; y = y_; } + xm_inline Vect2i(float x_, float y_) { x = round(x_); y = round(y_); } + + xm_inline Vect2i(const Vect2f& v) { x = round(v.x); y = round(v.y); } + xm_inline Vect2i(const Vect2s& v); + + xm_inline void set(int x_, int y_) { x = x_; y=y_; } + xm_inline void set(float x_, float y_) { x = round(x_); y = round(y_); } + xm_inline Vect2i operator - () const { return Vect2i(-x, -y); } + + xm_inline const int& operator[](int i) const { return *(&x + i); } + xm_inline int& operator[](int i) { return *(&x + i); } + + xm_inline Vect2i& operator += (const Vect2i& v) { x += v.x; y += v.y; return *this; } + xm_inline Vect2i& operator -= (const Vect2i& v) { x -= v.x; y -= v.y; return *this; } + xm_inline Vect2i& operator *= (const Vect2i& v) { x *= v.x; y *= v.y; return *this; } + xm_inline Vect2i& operator /= (const Vect2i& v) { x /= v.x; y /= v.y; return *this; } + + xm_inline Vect2i operator + (const Vect2i& v) const { return Vect2i(*this) += v; } + xm_inline Vect2i operator - (const Vect2i& v) const { return Vect2i(*this) -= v; } + xm_inline Vect2i operator * (const Vect2i& v) const { return Vect2i(*this) *= v; } + + xm_inline Vect2i& operator *= (int f) { x *= f; y *= f; return *this; } + xm_inline Vect2i operator * (int f) const { return Vect2i(*this) *= f; } + + xm_inline Vect2i& operator >>= (int n) { x >>= n; y >>= n; return *this; } + xm_inline Vect2i operator >> (int n) const { return Vect2i(*this) >>= n; } + + xm_inline Vect2i& operator *= (float f) { x = round(x*f); y = round(y*f); return *this; } + xm_inline Vect2i& operator /= (float f) { return *this *= 1.f/f; } + xm_inline Vect2i operator * (float f) const { return Vect2i(*this) *= f; } + xm_inline Vect2i operator / (float f) const { return Vect2i(*this) /= f; } + + xm_inline int dot(const Vect2i& v) const { return x*v.x + y*v.y; } + xm_inline friend int dot(const Vect2i& u, const Vect2i& v) { return u.dot(v); } + + xm_inline int operator % (const Vect2i &v) const { return x*v.y - y*v.x; } + + xm_inline int norm() const { return round(sqrtf(float(x*x+y*y))); } + xm_inline int norm2() const { return x*x+y*y; } + + xm_inline int operator == (const Vect2i& v) const { return x == v.x && y == v.y; } + xm_inline int operator != (const Vect2i& v) const { return x != v.x || y != v.y; } + + xm_inline void swap(Vect2i &v) { Vect2i tmp = v; v = *this; *this = tmp; } + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Vect2i& v); + friend istream& operator>> (istream& is, Vect2i& v); + + friend XStream& operator<= (XStream& s,const Vect2i& v); + friend XStream& operator>= (XStream& s,Vect2i& v); + friend XStream& operator< (XStream& s,const Vect2i& v); + friend XStream& operator> (XStream& s,Vect2i& v); + + friend XBuffer& operator<= (XBuffer& b,const Vect2i& v); + friend XBuffer& operator>= (XBuffer& b,Vect2i& v); + friend XBuffer& operator< (XBuffer& b,const Vect2i& v); + friend XBuffer& operator> (XBuffer& b,Vect2i& v); + + static const Vect2i ZERO; + static const Vect2i ID; +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Vect2s +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Vect2s +{ +public: + short x,y; + + xm_inline Vect2s() { } + xm_inline Vect2s(int x_,int y_) { x = x_; y = y_; } + + xm_inline Vect2s(const Vect2f& v) { x = round(v.x); y = round(v.y); } + xm_inline Vect2s(const Vect2i& v) { x = v.x; y = v.y; } + + xm_inline void set(int x_, int y_) { x = x_; y = y_; } + xm_inline Vect2s operator - () const { return Vect2s(-x,-y); } + + xm_inline const short& operator[](int i) const { return *(&x + i); } + xm_inline short& operator[](int i) { return *(&x + i); } + + xm_inline Vect2s& operator += (const Vect2s& v) { x += v.x; y += v.y; return *this; } + xm_inline Vect2s& operator -= (const Vect2s& v) { x -= v.x; y -= v.y; return *this; } + xm_inline Vect2s& operator *= (const Vect2s& v) { x *= v.x; y *= v.y; return *this; } + xm_inline Vect2s& operator *= (float f) { x = round(x*f); y = round(y*f); return *this; } + xm_inline Vect2s& operator /= (float f) { if(f!=0.f) f=1/f; else f=0.0001f; x=round(x*f); y=round(y*f); return *this; } + xm_inline Vect2s operator - (const Vect2s& v) const { return Vect2s(x - v.x, y - v.y); } + xm_inline Vect2s operator + (const Vect2s& v) const { return Vect2s(x + v.x, y + v.y); } + xm_inline Vect2s operator * (const Vect2s& v) const { return Vect2s(x*v.x, y*v.y); } + xm_inline Vect2s operator * (float f) const { Vect2s tmp(round(x*f),round(y*f)); return tmp; } + xm_inline Vect2s operator / (float f) const { if(f!=0.f) f=1/f; else f=0.0001f; Vect2s tmp(round(x*f),round(y*f)); return tmp; } + + xm_inline int operator == (const Vect2s& v) const { return x == v.x && y == v.y; } + + xm_inline int norm() const { return round(sqrtf((float)(x*x+y*y))); } + xm_inline int norm2() const { return x*x+y*y; } + xm_inline int distance(const Vect2s& v) const { int dx=v.x-x,dy=v.y-y; return round(sqrtf((float)(dx*dx+dy*dy))); } + xm_inline void normalize(int norma) { float f=(float)norma/(float)sqrtf((float)(x*x+y*y)); x=round(x*f); y=round(y*f); } + + xm_inline void swap(Vect2s &v) { Vect2s tmp = v; v = *this; *this = tmp; } + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Vect2s& v); + friend istream& operator>> (istream& is, Vect2s& v); + + friend XStream& operator<= (XStream& s,const Vect2s& v); + friend XStream& operator>= (XStream& s,Vect2s& v); + friend XStream& operator< (XStream& s,const Vect2s& v); + friend XStream& operator> (XStream& s,Vect2s& v); + + friend XBuffer& operator<= (XBuffer& b,const Vect2s& v); + friend XBuffer& operator>= (XBuffer& b,Vect2s& v); + friend XBuffer& operator< (XBuffer& b,const Vect2s& v); + friend XBuffer& operator> (XBuffer& b,Vect2s& v); +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Mat2f +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Mat2f +{ + float xx, xy, + yx, yy; +public: + Mat2f(){} + explicit Mat2f(float angle) { set(angle); } + Mat2f(float xx_, float xy_, float yx_, float yy_) { xx = xx_; xy = xy_; yx = yx_; yy = yy_; } + void set(float angle){ xx = yy = cosf(angle); yx = sinf(angle); xy = -yx; } + + // Rows + xm_inline const Vect2f& operator[](int i) const { return ((Vect2f*)&xx)[i]; } + xm_inline Vect2f& operator[](int i) { return ((Vect2f*)&xx)[i]; } + + // Columns + xm_inline Vect2f xcol() const { return Vect2f(xx, yx); } + xm_inline Vect2f ycol() const { return Vect2f(xy, yy); } + xm_inline Vect2f col(int axis) const { return axis == X_AXIS ? Vect2f(xx, yx) : Vect2f(xy, yy); } + + void invert(){ float t = xy; xy = yx; yx = t; } + + xm_inline Mat2f& operator*= (const Mat2f& m) { return (*this) = Mat2f(xx*m.xx+xy*m.yx, xx*m.xy+xy*m.yy, yx*m.xx+yy*m.yx, yx*m.xy+yy*m.yy); } + xm_inline const Mat2f operator* (const Mat2f& m) const { return Mat2f(*this) *= m; } + + // forward transform + xm_inline friend Vect2f& operator*= (Vect2f& v, const Mat2f& m) { float x = v.x*m.xx + v.y*m.xy; v.y = v.x*m.yx + v.y*m.yy; v.x = x; return v; } + // backward transform + xm_inline Vect2f invXform(const Vect2f& v) const { return Vect2f(v.x*xx + v.y*yx, v.x*xy + v.y*yy); } + + static const Mat2f ID; +}; +// forward transform +xm_inline const Vect2f operator* (const Mat2f& m, const Vect2f& v) { return Vect2f(v) *= m; } + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class MatX2f +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class MatX2f +{ +public: + Mat2f rot; + Vect2f trans; + + MatX2f(){} + MatX2f(const Mat2f& r, const Vect2f& t) : rot(r), trans(t) {} + void set(const Mat2f& r, const Vect2f& t) { rot = r; trans = t; } + + void invert() { rot.invert(); trans = -rot.invXform(trans); } + + // forward transform + friend Vect2f& operator *=(Vect2f& v, const MatX2f& m) { v *= m.rot; v += m.trans; return v; } + // backward transform + Vect2f invXform(const Vect2f& v) const { return rot.invXform(v - trans); } + + static const MatX2f ID; +}; +// forward transform +xm_inline const Vect2f operator* (const MatX2f& m, const Vect2f& v) { return Vect2f(v) *= m; } + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Vect3f +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Vect3f +{ + +public: + + float x, y, z; + + // constructors ////////////////////////////////////////////////////////////// + + xm_inline Vect3f() {} + xm_inline Vect3f(float x_, float y_, float z_) {x = x_; y = y_; z = z_;} + + typedef float float3[3]; + xm_inline Vect3f(const float3& v) {x = v[0]; y = v[1]; z = v[2];} + xm_inline Vect3f(const float v) {x = v; y = v; z = v;} + + xm_inline operator Vect3d () const; + + xm_inline operator const float* () const { return &x; } + xm_inline operator float* () { return &x; } + + // setters / accessors / translators ///////////////////////////////////////// + + xm_inline Vect3f& set(float x_, float y_, float z_) { x = x_; y = y_; z = z_; return *this; } + xm_inline Vect3f& set(const float3& v) {x = v[0]; y = v[1]; z = v[2]; return *this; } + xm_inline Vect3f& set(const float v) {x = v; y = v; z = v; return *this; } + + xm_inline Vect3f& setSpherical(float psi,float theta,float radius); + + // index-based access: 0=x, 1=y, 2=z. + xm_inline const float& operator[](int i) const {return *(&x + i);} + xm_inline float& operator[](int i) {return *(&x + i);} + + // Fortran index-based access: 1=x, 2=y, 3=z. + xm_inline const float& operator()(int i) const {return *(&x + i - 1);} + xm_inline float& operator()(int i) {return *(&x + i - 1);} + + // Convertion to int /////// + xm_inline int xi() const { return round(x); } + xm_inline int yi() const { return round(y); } + xm_inline int zi() const { return round(z); } + + // Negate //////////////////////////////////// + xm_inline Vect3f operator- () const; + xm_inline Vect3f& negate(const Vect3f& v); + xm_inline Vect3f& negate(); + + // Logical operations //////////////////////////////// + xm_inline int operator== (const Vect3f& v) const; + xm_inline int operator!= (const Vect3f& v) const; + + // Addition and substruction //////////////////// + xm_inline Vect3f& add(const Vect3f& u, const Vect3f& v); + xm_inline Vect3f& add(const Vect3f& v); + xm_inline Vect3f& sub(const Vect3f& u, const Vect3f& v); + xm_inline Vect3f& sub(const Vect3f& v); + xm_inline Vect3f& operator+= (const Vect3f& v) { return add(v); } + xm_inline Vect3f& operator-= (const Vect3f& v) { return sub(v); } + xm_inline Vect3f operator+ (const Vect3f& v) const { Vect3f u; return u.add(*this,v); } + xm_inline Vect3f operator- (const Vect3f& v) const { Vect3f u; return u.sub(*this,v); } + + // Component-wise multiplication and division //////////////// + xm_inline Vect3f& mult(const Vect3f& u, const Vect3f& v); + xm_inline Vect3f& mult(const Vect3f& v); + xm_inline Vect3f& div(const Vect3f& u, const Vect3f& v); + xm_inline Vect3f& div(const Vect3f& v); + xm_inline Vect3f& operator*= (const Vect3f& v) { return mult(v); } + xm_inline Vect3f& operator/= (const Vect3f& v) { return div(v); } + xm_inline Vect3f operator* (const Vect3f& v) const { Vect3f u; return u.mult(*this, v); } + xm_inline Vect3f operator/ (const Vect3f& v) const { Vect3f u; return u.div(*this, v); } + + // Cross product ////////////////////// + xm_inline Vect3f& cross(const Vect3f& u, const Vect3f& v);// u x v [!] + xm_inline Vect3f& precross(const Vect3f& v); // v x this [!] + xm_inline Vect3f& postcross(const Vect3f& v); // this x v [!] + xm_inline Vect3f& operator%= (const Vect3f& v) { return postcross(v); } // this x v [!] + xm_inline Vect3f operator% (const Vect3f& v) const { Vect3f u; return u.cross(*this, v); } + + // Dot product ////////////////////// + xm_inline float dot(const Vect3f& other) const; + xm_inline friend float dot(const Vect3f& u, const Vect3f& v) { return u.dot(v); } + + // Multiplication & division by scalar /////////// + xm_inline Vect3f& scale(const Vect3f& v, float s); + xm_inline Vect3f& scale(float s); + xm_inline Vect3f& operator*= (float s) { return scale(s); } + xm_inline Vect3f& operator/= (float s) { return scale(1/s); } + xm_inline Vect3f operator* (float s) const { Vect3f u; return u.scale(*this, s); } + xm_inline Vect3f operator/ (float s) const { Vect3f u; return u.scale(*this, 1/s); } + xm_inline friend Vect3f operator* (float s,const Vect3f& v) { Vect3f u; return u.scale(v, s); } + + // Normalize /////////////////////////// + xm_inline Vect3f& normalize(float r = 1.0); + xm_inline Vect3f& normalize(const Vect3f& v, float r = 1.0); + xm_inline friend Vect3f normalize(const Vect3f& v, float r = 1.0) { Vect3f u; return u.normalize(v, r); } + + // Safe Normalize (0 -> 0) //////////////////// + xm_inline Vect3f& Normalize(float r = 1.0); + xm_inline Vect3f& Normalize(const Vect3f& v, float r = 1.0); + xm_inline friend Vect3f Normalize(const Vect3f& v, float r = 1.0) { Vect3f u; return u.Normalize(v, r); } + + // Operation returning scalar //////////// + xm_inline float norm() const; + xm_inline float norm2() const; // norm^2 + xm_inline float distance(const Vect3f& other) const; + xm_inline float distance2(const Vect3f& other) const; // distance^2 + + xm_inline float psi() const; + xm_inline float theta() const; + + xm_inline float min() const; + xm_inline float max() const; + xm_inline float minAbs() const; + xm_inline float maxAbs() const; + xm_inline float sumAbs() const; // |x| + |y| + |z| + + + // Composite functions //////////////////////////////// + xm_inline Vect3f& crossAdd(const Vect3f& u, const Vect3f& v, const Vect3f& w); // u x v + w [!] this must be distinct from u and v, but not necessarily from w. + xm_inline Vect3f& crossAdd(const Vect3f& u, const Vect3f& v); // u x v + this [!] + xm_inline Vect3f& scaleAdd(const Vect3f& v, const Vect3f& u, float lambda); // v + lambda * u + xm_inline Vect3f& scaleAdd(const Vect3f& u, float lambda);// this + lambda * u + xm_inline Vect3f& interpolate(const Vect3f& u, const Vect3f& v, float lambda); // (1-lambda)*u + lambda*v + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Vect3f& v); + friend istream& operator>> (istream& is, Vect3f& v); + + friend XStream& operator<= (XStream& s,const Vect3f& v); + friend XStream& operator>= (XStream& s,Vect3f& v); + friend XStream& operator< (XStream& s,const Vect3f& v); + friend XStream& operator> (XStream& s,Vect3f& v); + + friend XBuffer& operator<= (XBuffer& b,const Vect3f& v); + friend XBuffer& operator>= (XBuffer& b,Vect3f& v); + friend XBuffer& operator< (XBuffer& b,const Vect3f& v); + friend XBuffer& operator> (XBuffer& b,Vect3f& v); + + // Swap ///////////////////////// + xm_inline void swap(Vect3f& other); + xm_inline friend void swap(Vect3f& u, Vect3f& v) { u.swap(v);} + + + // Vect3f constants /////////////////////////////////////////////////////////// + + static const Vect3f ZERO; + static const Vect3f ID; + static const Vect3f I; // unit vector along +x axis + static const Vect3f J; // unit vector along +y axis + static const Vect3f K; // unit vector along +z axis + static const Vect3f I_; // unit vector along -x axis + static const Vect3f J_; // unit vector along -y axis + static const Vect3f K_; // unit vector along -z axis + +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Vect3d +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Vect3d +{ + +public: + + double x, y, z; + + // constructors ////////////////////////////////////////////////////////////// + + xm_inline Vect3d() {} + xm_inline Vect3d(double x_, double y_, double z_) { x = x_; y = y_; z = z_; } + + typedef float double3[3]; + xm_inline Vect3d(const double3& v) {x = v[0]; y = v[1]; z = v[2];} + + xm_inline operator Vect3f () const; + + xm_inline operator const double* () const { return &x; } + xm_inline operator double* () { return &x; } + + // setters / accessors / translators ///////////////////////////////////////// + + xm_inline Vect3d& set(double x_, double y_, double z_) { x = x_; y = y_; z = z_; return *this; } + xm_inline Vect3d& set(const double v[3]) {x = v[0]; y = v[1]; z = v[2]; return *this; } + + xm_inline Vect3d& setSpherical(double psi,double theta,double radius); + + // index-based access: 0=x, 1=y, 2=z. + xm_inline const double& operator[](int i) const {return *(&x + i);} + xm_inline double& operator[](int i) {return *(&x + i);} + + // Convertion to int /////// + xm_inline int xi() const { return round(x); } + xm_inline int yi() const { return round(y); } + xm_inline int zi() const { return round(z); } + + // Negate //////////////////////////////////// + xm_inline Vect3d operator- () const; + xm_inline Vect3d& negate(const Vect3d& v); + xm_inline Vect3d& negate(); + + // Logical operations //////////////////////////////// + xm_inline int operator== (const Vect3d& v) const; + xm_inline int operator!= (const Vect3d& v) const; + + // Addition and substruction //////////////////// + xm_inline Vect3d& add(const Vect3d& u, const Vect3d& v); + xm_inline Vect3d& add(const Vect3d& v); + xm_inline Vect3d& sub(const Vect3d& u, const Vect3d& v); + xm_inline Vect3d& sub(const Vect3d& v); + xm_inline Vect3d& operator+= (const Vect3d& v) { return add(v); } + xm_inline Vect3d& operator-= (const Vect3d& v) { return sub(v); } + xm_inline Vect3d operator+ (const Vect3d& v) const { Vect3d u; return u.add(*this,v); } + xm_inline Vect3d operator- (const Vect3d& v) const { Vect3d u; return u.sub(*this,v); } + + // Component-wise multiplication and division //////////////// + xm_inline Vect3d& mult(const Vect3d& u, const Vect3d& v); + xm_inline Vect3d& mult(const Vect3d& v); + xm_inline Vect3d& div(const Vect3d& u, const Vect3d& v); + xm_inline Vect3d& div(const Vect3d& v); + xm_inline Vect3d& operator*= (const Vect3d& v) { return mult(v); } + xm_inline Vect3d& operator/= (const Vect3d& v) { return div(v); } + xm_inline Vect3d operator* (const Vect3d& v) const { Vect3d u; return u.mult(*this, v); } + xm_inline Vect3d operator/ (const Vect3d& v) const { Vect3d u; return u.div(*this, v); } + + // Cross product ////////////////////// + xm_inline Vect3d& cross(const Vect3d& u, const Vect3d& v);// u x v [!] + xm_inline Vect3d& precross(const Vect3d& v); // v x this [!] + xm_inline Vect3d& postcross(const Vect3d& v); // this x v [!] + xm_inline Vect3d& operator%= (const Vect3d& v) { return postcross(v); } // this x v [!] + xm_inline Vect3d operator% (const Vect3d& v) const { Vect3d u; return u.cross(*this, v); } + + // Dot product ////////////////////// + xm_inline double dot(const Vect3d& other) const; + xm_inline friend double dot(const Vect3d& u, const Vect3d& v) { return u.dot(v); } + + // Multiplication & division by scalar /////////// + xm_inline Vect3d& scale(const Vect3d& v, double s); + xm_inline Vect3d& scale(double s); + xm_inline Vect3d& operator*= (double s) { return scale(s); } + xm_inline Vect3d& operator/= (double s) { return scale(1/s); } + xm_inline Vect3d operator* (double s) const { Vect3d u; return u.scale(*this, s); } + xm_inline Vect3d operator/ (double s) const { Vect3d u; return u.scale(*this, 1/s); } + xm_inline friend Vect3d operator* (double s,const Vect3d& v) { Vect3d u; return u.scale(v, s); } + + // Normalize /////////////////////////// + xm_inline Vect3d& normalize(double r = 1.0); + xm_inline Vect3d& normalize(const Vect3d& v, double r = 1.0); + xm_inline friend Vect3d normalize(const Vect3d& v, double r = 1.0) { Vect3d u; return u.normalize(v, r); } + + // Safe Normalize (0 -> 0) //////////////////// + xm_inline Vect3d& Normalize(double r = 1.0); + xm_inline Vect3d& Normalize(const Vect3d& v, double r = 1.0); + xm_inline friend Vect3d Normalize(const Vect3d& v, double r = 1.0) { Vect3d u; return u.Normalize(v, r); } + + // Operation returning scalar //////////// + xm_inline double norm() const; + xm_inline double norm2() const; // norm^2 + xm_inline double distance(const Vect3d& other) const; + xm_inline double distance2(const Vect3d& other) const; // distance^2 + + xm_inline double psi() const; + xm_inline double theta() const; + + xm_inline double min() const; + xm_inline double max() const; + xm_inline double minAbs() const; + xm_inline double maxAbs() const; + xm_inline double sumAbs() const; // |x| + |y| + |z| + + + // Composite functions //////////////////////////////// + xm_inline Vect3d& crossAdd(const Vect3d& u, const Vect3d& v, const Vect3d& w); // u x v + w [!] this must be distinct from u and v, but not necessarily from w. + xm_inline Vect3d& crossAdd(const Vect3d& u, const Vect3d& v); // u x v + this [!] + xm_inline Vect3d& scaleAdd(const Vect3d& v, const Vect3d& u, double lambda); // v + lambda * u + xm_inline Vect3d& scaleAdd(const Vect3d& u, double lambda);// this + lambda * u + xm_inline Vect3d& interpolate(const Vect3d& u, const Vect3d& v, double lambda); // (1-lambda)*u + lambda*v + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Vect3d& v); + friend istream& operator>> (istream& is, Vect3d& v); + + friend XStream& operator<= (XStream& s,const Vect3d& v); + friend XStream& operator>= (XStream& s,Vect3d& v); + friend XStream& operator< (XStream& s,const Vect3d& v); + friend XStream& operator> (XStream& s,Vect3d& v); + + friend XBuffer& operator<= (XBuffer& b,const Vect3d& v); + friend XBuffer& operator>= (XBuffer& b,Vect3d& v); + friend XBuffer& operator< (XBuffer& b,const Vect3d& v); + friend XBuffer& operator> (XBuffer& b,Vect3d& v); + + // Swap ///////////////////////// + xm_inline void swap(Vect3d& other); + xm_inline friend void swap(Vect3d& u, Vect3d& v) { u.swap(v);} + + + // Vect3d constants /////////////////////////////////////////////////////////// + + static const Vect3d ZERO; + static const Vect3d ID; + static const Vect3d I; // unit vector along +x axis + static const Vect3d J; // unit vector along +y axis + static const Vect3d K; // unit vector along +z axis + static const Vect3d I_; // unit vector along -x axis + static const Vect3d J_; // unit vector along -y axis + static const Vect3d K_; // unit vector along -z axis + +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Mat3f +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Mat3f +{ + + friend class MatXf; + friend class Mat4f; + friend class QuatF; + +private: + + // (stored in row-major order) + float xx, xy, xz, + yx, yy, yz, + zx, zy, zz; + +public: + + // constructors ////////////////////////////////////////////////////////////// + + Mat3f() {} + + xm_inline Mat3f(float xx,float xy,float xz, + float yx,float yy,float yz, + float zx,float zy,float zz); + + Mat3f(float angle, eAxis axis) { set(angle, axis); } + + Mat3f(const Vect3f& diag, const Vect3f& sym) {set(diag, sym);} + + Mat3f(const Vect3f& axis, float angle, int normalizeAxis = 1) + {set(axis, angle, normalizeAxis);} + + Mat3f(const QuatF& q) {set(q);} + + Mat3f(const Vect3f& x_from, const Vect3f& y_from, const Vect3f& z_from, + const Vect3f& x_to = Vect3f::I, const Vect3f& y_to = Vect3f::J, const Vect3f& z_to = Vect3f::K) + { set(x_from, y_from, z_from, x_to, y_to, z_to); } + + xm_inline operator Mat3d () const; + + + // setters / accessors /////////////////////////////////////////////////////// + + // Rotation around 'axis' by radians-angle + xm_inline Mat3f& set(float angle, eAxis axis); + + // make a symmetric matrix, given the diagonal and symmetric + // (off-diagonal) elements in canonical order + xm_inline Mat3f& set(const Vect3f& diag, const Vect3f& sym); + + // set Mat3f as a rotation of 'angle' radians about 'axis' + // axis is automatically normalized unless normalizeAxis = 0 + Mat3f& set(const Vect3f& axis, float angle, int normalizeAxis = 1); + + Mat3f& set(const QuatF& q); + + // Convertion "from"-basis -> "to"-basis + Mat3f& set(const Vect3f& x_from, const Vect3f& y_from, const Vect3f& z_from, + const Vect3f& x_to = Vect3f::I, const Vect3f& y_to = Vect3f::J, const Vect3f& z_to = Vect3f::K); + + // index-based access: 0=xrow, 1=yrow, 2=zrow. + xm_inline const Vect3f& operator[](int i) const {return *(((Vect3f *) &xx) + i);} + xm_inline Vect3f& operator[](int i) {return *(((Vect3f *) &xx) + i);} + + // set matrix to the skew symmetric matrix corresponding to 'v X' + xm_inline Mat3f& setSkew(const Vect3f& v); + + // for reading rows + xm_inline const Vect3f& xrow() const {return *((Vect3f *) &xx);} + xm_inline const Vect3f& yrow() const {return *((Vect3f *) &yx);} + xm_inline const Vect3f& zrow() const {return *((Vect3f *) &zx);} + // for writing to rows + xm_inline Vect3f& xrow() {return *((Vect3f *) &xx);} + xm_inline Vect3f& yrow() {return *((Vect3f *) &yx);} + xm_inline Vect3f& zrow() {return *((Vect3f *) &zx);} + + // for reading columns + xm_inline const Vect3f xcol() const {return Vect3f(xx, yx, zx);} + xm_inline const Vect3f ycol() const {return Vect3f(xy, yy, zy);} + xm_inline const Vect3f zcol() const {return Vect3f(xz, yz, zz);} + xm_inline const Vect3f col(int axis) const { return axis == X_AXIS ? Vect3f(xx, yx, zx) : (axis == Y_AXIS ? Vect3f(xy, yy, zy) : Vect3f(xz, yz, zz) ); } + // for writing to columns + xm_inline Mat3f& setXcol(const Vect3f& v); + xm_inline Mat3f& setYcol(const Vect3f& v); + xm_inline Mat3f& setZcol(const Vect3f& v); + xm_inline Mat3f& setCol(int axis, const Vect3f& v) { if(axis == X_AXIS) setXcol(v); else if(axis == Y_AXIS) setYcol(v); else setZcol(v); return *this; } + + + // for reading a symmetric matrix + xm_inline Vect3f diag() const {return Vect3f(xx, yy, zz);} + xm_inline Vect3f sym() const {return Vect3f(yz, zx, xy);} + + + // Access to elements for Mapple-like notation (numerating from 1): + // 1,1 1,2 1,3 + // 2,1 2,2 2,3 + // 3,1 3,2 3,3 + xm_inline const float& operator ()(int i,int j) const { return (&xx)[(i - 1)*3 + j - 1]; } + xm_inline float& operator ()(int i,int j){ return (&xx)[(i - 1)*3 + j - 1]; } + + // Determinant of matrix ///////// + xm_inline float det() const; + + // Negate /////////////////// + xm_inline Mat3f operator- () const; + xm_inline Mat3f& negate(); // -this + xm_inline Mat3f& negate(const Mat3f& M); // -M + + // Addition & substruction ///////////////////////// + xm_inline Mat3f& add(const Mat3f& M, const Mat3f& N); // M + N + xm_inline Mat3f& add(const Mat3f& M); // this + M + xm_inline Mat3f& sub(const Mat3f& M, const Mat3f& N); // M - N + xm_inline Mat3f& sub(const Mat3f& M); // this - M + xm_inline Mat3f& operator+= (const Mat3f& M) { return add(M); } + xm_inline Mat3f& operator-= (const Mat3f& M) { return sub(M); } + xm_inline Mat3f operator+ (const Mat3f& M) const { Mat3f N; return N.add(*this,M); } + xm_inline Mat3f operator- (const Mat3f& M) const { Mat3f N; return N.sub(*this,M); } + + // Mat3f - Mat3f multiplication /////////// + Mat3f& mult(const Mat3f& M, const Mat3f& N); // M * N [!] + Mat3f& premult(const Mat3f& M); // M * this [!] + Mat3f& postmult(const Mat3f& M); // this * M [!] + xm_inline Mat3f& operator*= (const Mat3f& M) { return postmult(M); } + xm_inline Mat3f operator* (const Mat3f& M) const { Mat3f N; return N.mult(*this, M); } + + // Scalar multiplication ///////////// + xm_inline Mat3f& scale(const Mat3f& M, float s); // s * M + xm_inline Mat3f& scale(const Vect3f &s); // s * this + xm_inline Mat3f& scale(float s); // s * this + xm_inline Mat3f& operator*= (float s) { return scale(s); } + xm_inline Mat3f& operator/= (float s) { return scale(1/s); } + xm_inline Mat3f operator* (float s) const { Mat3f N; return N.scale(*this, s); } + xm_inline Mat3f operator/ (float s) const { Mat3f N; return N.scale(*this, 1/s); } + xm_inline friend Mat3f operator* (float s,const Mat3f& M) { Mat3f N; return N.scale(M, s); } + + // Multiplication by Vect3f as diagonal matrix ///////////// + xm_inline Mat3f& preScale(const Mat3f& M, const Vect3f& v); // Mat3f(v) * M + xm_inline Mat3f& preScale(const Vect3f& v); // Mat3f(v) * this + xm_inline Mat3f& postScale(const Mat3f& M, const Vect3f& v); // M * Mat3f(v) + xm_inline Mat3f& postScale(const Vect3f& v); // this * Mat3f(v) + + // Transposition //////////////// + xm_inline Mat3f& xpose(); // this^T + xm_inline Mat3f& xpose(const Mat3f& M); // M^T [!] + xm_inline friend Mat3f xpose(const Mat3f& M) { Mat3f N; return N.xpose(M); } + + // Invertion //////////////////// + int invert(); // this^-1, returns one if the matrix was not invertible, otherwise zero. + int invert(const Mat3f& M); // M^-1 [!] + xm_inline friend Mat3f invert(const Mat3f& M) { Mat3f N; N.invert(M); return N; } + + // Simmetrize ///////////// + xm_inline Mat3f& symmetrize(const Mat3f& M); // M + M^T + xm_inline Mat3f& symmetrize(); // this + this^T + + + + // Transforming Vect3d /////////////////////////////////////////////////////// + // return reference to converted vector + xm_inline Vect3d& xform(const Vect3d& v, Vect3d& xv) const; // (this)(v) => xv [!] + xm_inline Vect3d& xform(Vect3d& v) const; // (this)(v) => v + + // These are exactly like the above methods, except the inverse + // transform this^-1 (= this^T) is used. This can be thought of as + // a row vector transformation, e.g.: (v^T)(this) => xv^T + xm_inline Vect3d& invXform(const Vect3d& v, Vect3d& xv) const; // [!] + xm_inline Vect3d& invXform(Vect3d& v) const; + + // Transforming operators /////////////// + xm_inline friend Vect3d& operator*= (Vect3d& v, const Mat3f& M) { return M.xform(v); } + xm_inline friend Vect3d operator* (const Vect3d& v, const Mat3f& M) { Vect3d xv; return M.xform(v, xv); } + xm_inline friend Vect3d operator* (const Mat3f& M, const Vect3d& v) { Vect3d xv; return M.xform(v, xv); } + + + // Transforming Vect3f /////////////////////////////////////////////////////// + + // return reference to converted vector + xm_inline Vect3f& xform(const Vect3f& v, Vect3f& xv) const; // (this)(v) => xv [!] + xm_inline Vect3f& xform(Vect3f& v) const; // (this)(v) => v + + // These are exactly like the above methods, except the inverse + // transform this^-1 (= this^T) is used. This can be thought of as + // a row vector transformation, e.g.: (v^T)(this) => xv^T + xm_inline Vect3f& invXform(const Vect3f& v, Vect3f& xv) const; // [!] + xm_inline Vect3f& invXform(Vect3f& v) const; + + // Transforming operators /////////////// + xm_inline friend Vect3f& operator*= (Vect3f& v, const Mat3f& M) { return M.xform(v); } + xm_inline friend Vect3f operator* (const Vect3f& v, const Mat3f& M) { Vect3f xv; return M.xform(v, xv); } + xm_inline friend Vect3f operator* (const Mat3f& M, const Vect3f& v) { Vect3f xv; return M.xform(v, xv); } + + + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Mat3f& M); + friend istream& operator>> (istream& is, Mat3f& M); + + friend XStream& operator<= (XStream& s,const Mat3f& M); + friend XStream& operator>= (XStream& s,Mat3f& M); + friend XStream& operator< (XStream& s,const Mat3f& M); + friend XStream& operator> (XStream& s,Mat3f& M); + + friend XBuffer& operator<= (XBuffer& b,const Mat3f& M); + friend XBuffer& operator>= (XBuffer& b,Mat3f& M); + friend XBuffer& operator< (XBuffer& b,const Mat3f& M); + friend XBuffer& operator> (XBuffer& b,Mat3f& M); + + + // Mat3f constants //////////////////////////////////////////////////////////// + + static const Mat3f ZERO; // zero matrix + static const Mat3f ID; // identity matrix + +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Mat3d +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Mat3d +{ + + friend class QuatD; + friend class MatXd; + +private: + + // (stored in row-major order) + double xx, xy, xz, + yx, yy, yz, + zx, zy, zz; + +public: + + // constructors ////////////////////////////////////////////////////////////// + + Mat3d() {} + + xm_inline Mat3d(double xx,double xy,double xz, + double yx,double yy,double yz, + double zx,double zy,double zz); + + Mat3d(double angle, eAxis axis) { set(angle, axis); } + + Mat3d(const Vect3d& diag, const Vect3d& sym) {set(diag, sym);} + + Mat3d(const Vect3d& axis, double angle, int normalizeAxis = 1) + {set(axis, angle, normalizeAxis);} + + Mat3d(const QuatD& q) {set(q);} + + Mat3d(const Vect3d& x_from, const Vect3d& y_from, const Vect3d& z_from, + const Vect3d& x_to = Vect3d::I, const Vect3d& y_to = Vect3d::J, const Vect3d& z_to = Vect3d::K) + { set(x_from, y_from, z_from, x_to, y_to, z_to); } + + xm_inline operator Mat3f () const; + + // setters / accessors /////////////////////////////////////////////////////// + + // Rotation around 'axis' by radians-angle + xm_inline Mat3d& set(double angle, eAxis axis); + + // make a symmetric matrix, given the diagonal and symmetric + // (off-diagonal) elements in canonical order + xm_inline Mat3d& set(const Vect3d& diag, const Vect3d& sym); + + // set Mat3d as a rotation of 'angle' radians about 'axis' + // axis is automatically normalized unless normalizeAxis = 0 + Mat3d& set(const Vect3d& axis, double angle, int normalizeAxis = 1); + + Mat3d& set(const QuatD& q); + + // Convertion "from"-basis -> "to"-basis + Mat3d& set(const Vect3d& x_from, const Vect3d& y_from, const Vect3d& z_from, + const Vect3d& x_to = Vect3d::I, const Vect3d& y_to = Vect3d::J, const Vect3d& z_to = Vect3d::K); + + // index-based access: 0=xrow, 1=yrow, 2=zrow. + const Vect3d& operator[](int i) const {return *(((Vect3d *) &xx) + i);} + Vect3d& operator[](int i) {return *(((Vect3d *) &xx) + i);} + + // set matrix to the skew symmetric matrix corresponding to 'v X' + xm_inline Mat3d& setSkew(const Vect3d& v); + + // for reading rows + const Vect3d& xrow() const {return *((Vect3d *) &xx);} + const Vect3d& yrow() const {return *((Vect3d *) &yx);} + const Vect3d& zrow() const {return *((Vect3d *) &zx);} + // for writing to rows + Vect3d& xrow() {return *((Vect3d *) &xx);} + Vect3d& yrow() {return *((Vect3d *) &yx);} + Vect3d& zrow() {return *((Vect3d *) &zx);} + + // for reading columns + Vect3d xcol() const {return Vect3d(xx, yx, zx);} + Vect3d ycol() const {return Vect3d(xy, yy, zy);} + Vect3d zcol() const {return Vect3d(xz, yz, zz);} + Vect3d col(int axis) const { return axis == X_AXIS ? Vect3d(xx, yx, zx) : (axis == Y_AXIS ? Vect3d(xy, yy, zy) : Vect3d(xz, yz, zz) ); } + // for writing to columns + xm_inline Mat3d& setXcol(const Vect3d& v); + xm_inline Mat3d& setYcol(const Vect3d& v); + xm_inline Mat3d& setZcol(const Vect3d& v); + Mat3d& setCol(int axis, const Vect3d& v) { if(axis == X_AXIS) setXcol(v); else if(axis == Y_AXIS) setYcol(v); else setZcol(v); return *this; } + + // for reading a symmetric matrix + Vect3d diag() const {return Vect3d(xx, yy, zz);} + Vect3d sym() const {return Vect3d(yz, zx, xy);} + + + // Access to elements for Mapple-like notation (numerating from 1): + // 1,1 1,2 1,3 + // 2,1 2,2 2,3 + // 3,1 3,2 3,3 + const double& operator ()(int i,int j) const { return (&xx)[(i - 1)*3 + j - 1]; } + double& operator ()(int i,int j){ return (&xx)[(i - 1)*3 + j - 1]; } + + // Determinant of matrix ///////// + xm_inline double det() const; + + // Negate /////////////////// + xm_inline Mat3d operator- () const; + xm_inline Mat3d& negate(); // -this + xm_inline Mat3d& negate(const Mat3d& M); // -M + + // Addition & substruction ///////////////////////// + xm_inline Mat3d& add(const Mat3d& M, const Mat3d& N); // M + N + xm_inline Mat3d& add(const Mat3d& M); // this + M + xm_inline Mat3d& sub(const Mat3d& M, const Mat3d& N); // M - N + xm_inline Mat3d& sub(const Mat3d& M); // this - M + Mat3d& operator+= (const Mat3d& M) { return add(M); } + Mat3d& operator-= (const Mat3d& M) { return sub(M); } + Mat3d operator+ (const Mat3d& M) const { Mat3d N; return N.add(*this,M); } + Mat3d operator- (const Mat3d& M) const { Mat3d N; return N.sub(*this,M); } + + // Mat3d - Mat3d multiplication /////////// + Mat3d& mult(const Mat3d& M, const Mat3d& N); // M * N [!] + Mat3d& premult(const Mat3d& M); // M * this [!] + Mat3d& postmult(const Mat3d& M); // this * M [!] + Mat3d& operator*= (const Mat3d& M) { return postmult(M); } + Mat3d operator* (const Mat3d& M) const { Mat3d N; return N.mult(*this, M); } + + // Scalar multiplication ///////////// + xm_inline Mat3d& scale(const Mat3d& M, double s); // s * M + xm_inline Mat3d& scale(double s); // s * this + Mat3d& operator*= (double s) { return scale(s); } + Mat3d& operator/= (double s) { return scale(1/s); } + Mat3d operator* (double s) const { Mat3d N; return N.scale(*this, s); } + Mat3d operator/ (double s) const { Mat3d N; return N.scale(*this, 1/s); } + friend Mat3d operator* (double s,const Mat3d& M) { Mat3d N; return N.scale(M, s); } + + // Multiplication by Vect3d as diagonal matrix ///////////// + xm_inline Mat3d& preScale(const Mat3d& M, const Vect3d& v); // Mat3d(v) * M + xm_inline Mat3d& preScale(const Vect3d& v); // Mat3d(v) * this + xm_inline Mat3d& postScale(const Mat3d& M, const Vect3d& v); // M * Mat3d(v) + xm_inline Mat3d& postScale(const Vect3d& v); // this * Mat3d(v) + + // Transposition //////////////// + xm_inline Mat3d& xpose(); // this^T + xm_inline Mat3d& xpose(const Mat3d& M); // M^T [!] + friend Mat3d xpose(const Mat3d& M) { Mat3d N; return N.xpose(M); } + + // Invertion //////////////////// + int invert(); // this^-1, returns one if the matrix was not invertible, otherwise zero. + int invert(const Mat3d& M); // M^-1 [!] + friend Mat3d invert(const Mat3d& M) { Mat3d N; N.invert(M); return N; } + + // Simmetrize ///////////// + xm_inline Mat3d& symmetrize(const Mat3d& M); // M + M^T + xm_inline Mat3d& symmetrize(); // this + this^T + + + + // Transforming Vect3d /////////////////////////////////////////////////////// + + // return reference to converted vector + xm_inline Vect3d& xform(const Vect3d& v, Vect3d& xv) const; // (this)(v) => xv [!] + xm_inline Vect3d& xform(Vect3d& v) const; // (this)(v) => v + + // These are exactly like the above methods, except the inverse + // transform this^-1 (= this^T) is used. This can be thought of as + // a row vector transformation, e.g.: (v^T)(this) => xv^T + xm_inline Vect3d& invXform(const Vect3d& v, Vect3d& xv) const; // [!] + xm_inline Vect3d& invXform(Vect3d& v) const; + + // Transforming operators /////////////// + friend Vect3d& operator*= (Vect3d& v, const Mat3d& M) { return M.xform(v); } + friend Vect3d operator* (const Vect3d& v, const Mat3d& M) { Vect3d xv; return M.xform(v, xv); } + friend Vect3d operator* (const Mat3d& M, const Vect3d& v) { Vect3d xv; return M.xform(v, xv); } + + + + // Transforming Vect3f /////////////////////////////////////////////////////// + // return reference to converted vector + xm_inline Vect3f& xform(const Vect3f& v, Vect3f& xv) const; // (this)(v) => xv [!] + xm_inline Vect3f& xform(Vect3f& v) const; // (this)(v) => v + + // These are exactly like the above methods, except the inverse + // transform this^-1 (= this^T) is used. This can be thought of as + // a row vector transformation, e.g.: (v^T)(this) => xv^T + xm_inline Vect3f& invXform(const Vect3f& v, Vect3f& xv) const; // [!] + xm_inline Vect3f& invXform(Vect3f& v) const; + + // Transforming operators /////////////// + friend Vect3f& operator*= (Vect3f& v, const Mat3d& M) { return M.xform(v); } + friend Vect3f operator* (const Vect3f& v, const Mat3d& M) { Vect3f xv; return M.xform(v, xv); } + friend Vect3f operator* (const Mat3d& M, const Vect3f& v) { Vect3f xv; return M.xform(v, xv); } + + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Mat3d& M); + friend istream& operator>> (istream& is, Mat3d& M); + + friend XStream& operator<= (XStream& s,const Mat3d& M); + friend XStream& operator>= (XStream& s,Mat3d& M); + friend XStream& operator< (XStream& s,const Mat3d& M); + friend XStream& operator> (XStream& s,Mat3d& M); + + friend XBuffer& operator<= (XBuffer& b,const Mat3d& M); + friend XBuffer& operator>= (XBuffer& b,Mat3d& M); + friend XBuffer& operator< (XBuffer& b,const Mat3d& M); + friend XBuffer& operator> (XBuffer& b,Mat3d& M); + + + // Mat3d constants //////////////////////////////////////////////////////////// + + static const Mat3d ZERO; // zero matrix + static const Mat3d ID; // identity matrix + +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class MatXf +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class MatXf +{ +private: + + Mat3f R; + Vect3f d; + +public: + + // constructors ////////////////////////////////////////////////////////////// + + xm_inline MatXf() {} + xm_inline MatXf(const Mat3f& R_, const Vect3f& d_) {set(R_, d_);} + xm_inline MatXf(const Se3f& T) {set(T);} + + typedef float float16[16]; + xm_inline MatXf(const float16& T); + + xm_inline operator MatXd () const; + + // setters / accessors / translators ///////////////////////////////////////// + + xm_inline MatXf& set(const Mat3f& R_, const Vect3f& d_) {R = R_; d = d_; return *this; } + xm_inline MatXf& set(const Se3f& T); + + xm_inline const Mat3f& rot() const {return R;} + xm_inline const Vect3f& trans() const {return d;} + xm_inline Mat3f& rot() {return R;} + xm_inline Vect3f& trans() {return d;} + + + // MatXf - MatXf multiplication //////////// + MatXf& mult(const MatXf& M, const MatXf& N); // M * N [!] + MatXf& premult(const MatXf& M); // M * this [!] + MatXf& postmult(const MatXf& M); // this * M [!] + xm_inline MatXf& operator*= (const MatXf& M) { return postmult(M); } + xm_inline MatXf operator* (const MatXf& N) const { MatXf M; return M.mult(*this, N); } + + + // Doesn't really invert the 3x3-matrix, but only transpose one. + // That is, works for non-scaled matrix !!! + MatXf& invert(const MatXf& M); // M^-1 [!] + MatXf& invert(); // this^-1 + + // Really inverts 3x3-matrix. + MatXf& Invert(const MatXf& M); // M^-1 [!] + MatXf& Invert(); // this^-1 + + // Transforming Vect3d /////////////////////////////////////////////////////// + + // MatXs can transform elements of R^3 either as vectors or as + // points. The [!] indicates that the operands must be distinct. + xm_inline Vect3d& xformVect(const Vect3d& v, Vect3d& xv) const; // this*(v 0)=>xv [!] + xm_inline Vect3d& xformVect(Vect3d& v) const; // this*(v 0)=>v + xm_inline Vect3d& xformPoint(const Vect3d& p, Vect3d& xp) const;// this*(p 1)=>xp [!] + xm_inline Vect3d& xformPoint(Vect3d& p) const; // this*(p 1)=>p + + // These are exactly like the above methods, except the inverse + // transform this^-1 is used. + xm_inline Vect3d& invXformVect(const Vect3d& v, Vect3d& xv) const; + xm_inline Vect3d& invXformVect(Vect3d& v) const; + xm_inline Vect3d& invXformPoint(const Vect3d& p, Vect3d& xp) const; + xm_inline Vect3d& invXformPoint(Vect3d& p) const; + + + // Transforming Vect3f /////////////////////////////////////////////////////// + + // MatXs can transform elements of R^3 either as vectors or as + // points. The [!] indicates that the operands must be distinct. + + xm_inline Vect3f& xformVect(const Vect3f& v, Vect3f& xv) const; // this*(v 0)=>xv [!] + xm_inline Vect3f& xformVect(Vect3f& v) const; // this*(v 0)=>v + xm_inline Vect3f& xformPoint(const Vect3f& p, Vect3f& xp) const;// this*(p 1)=>xp [!] + xm_inline Vect3f& xformPoint(Vect3f& p) const; // this*(p 1)=>p + + // These are exactly like the above methods, except the inverse + // transform this^-1 is used. + xm_inline Vect3f& invXformVect(const Vect3f& v, Vect3f& xv) const; + xm_inline Vect3f& invXformVect(Vect3f& v) const; + xm_inline Vect3f& invXformPoint(const Vect3f& p, Vect3f& xp) const; + xm_inline Vect3f& invXformPoint(Vect3f& p) const; + + + + // I/O operations ////////////////////////////////////// + friend ostream& operator<<(ostream& os, const MatXf& M); + friend istream& operator>>(istream& is, MatXf& M); + + // MatXf constants //////////////////////////////////////////////////////////// + + static const MatXf ID; // identity matrix + +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class MatXd +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class MatXd +{ +private: + + Mat3d R; + Vect3d d; + +public: + + // constructors ////////////////////////////////////////////////////////////// + + xm_inline MatXd() {} + xm_inline MatXd(const Mat3d& R_, const Vect3d& d_) {set(R_, d_);} + xm_inline MatXd(const Se3d& T) {set(T);} + + typedef double double16[16]; + xm_inline MatXd(const double16& T); + + xm_inline operator MatXf () const; + + // setters / accessors / translators ///////////////////////////////////////// + + xm_inline MatXd& set(const Mat3d& R_, const Vect3d& d_) {R = R_; d = d_; return *this; } + xm_inline MatXd& set(const Se3d& T); + + xm_inline const Mat3d& rot() const {return R;} + xm_inline const Vect3d& trans() const {return d;} + xm_inline Mat3d& rot() {return R;} + xm_inline Vect3d& trans() {return d;} + + + // MatXd - MatXd multiplication //////////// + MatXd& mult(const MatXd& M, const MatXd& N); // M * N [!] + MatXd& premult(const MatXd& M); // M * this [!] + MatXd& postmult(const MatXd& M); // this * M [!] + xm_inline MatXd& operator*= (const MatXd& M) { return postmult(M); } + xm_inline MatXd operator* (const MatXd& N) const { MatXd M; return M.mult(*this, N); } + + + // Doesn't really invert the 3x3-matrix, but only transpose one. + // That is, works for non-scaled matrix !!! + MatXd& invert(const MatXd& M); // M^-1 [!] + MatXd& invert(); // this^-1 + + // Really inverts 3x3-matrix. + MatXd& Invert(const MatXd& M); // M^-1 [!] + MatXd& Invert(); // this^-1 + + + // Transforming Vect3d /////////////////////////////////////////////////////// + + // MatXs can transform elements of R^3 either as vectors or as + // points. The [!] indicates that the operands must be distinct. + + xm_inline Vect3d& xformVect(const Vect3d& v, Vect3d& xv) const; // this*(v 0)=>xv [!] + xm_inline Vect3d& xformVect(Vect3d& v) const; // this*(v 0)=>v + xm_inline Vect3d& xformPoint(const Vect3d& p, Vect3d& xp) const;// this*(p 1)=>xp [!] + xm_inline Vect3d& xformPoint(Vect3d& p) const; // this*(p 1)=>p + + // These are exactly like the above methods, except the inverse + // transform this^-1 is used. + xm_inline Vect3d& invXformVect(const Vect3d& v, Vect3d& xv) const; + xm_inline Vect3d& invXformVect(Vect3d& v) const; + xm_inline Vect3d& invXformPoint(const Vect3d& p, Vect3d& xp) const; + xm_inline Vect3d& invXformPoint(Vect3d& p) const; + + + + // Transforming Vect3f /////////////////////////////////////////////////////// + + // MatXs can transform elements of R^3 either as vectors or as + // points. The [!] indicates that the operands must be distinct. + xm_inline Vect3f& xformVect(const Vect3f& v, Vect3f& xv) const; // this*(v 0)=>xv [!] + xm_inline Vect3f& xformVect(Vect3f& v) const; // this*(v 0)=>v + xm_inline Vect3f& xformPoint(const Vect3f& p, Vect3f& xp) const;// this*(p 1)=>xp [!] + xm_inline Vect3f& xformPoint(Vect3f& p) const; // this*(p 1)=>p + + // These are exactly like the above methods, except the inverse + // transform this^-1 is used. + xm_inline Vect3f& invXformVect(const Vect3f& v, Vect3f& xv) const; + xm_inline Vect3f& invXformVect(Vect3f& v) const; + xm_inline Vect3f& invXformPoint(const Vect3f& p, Vect3f& xp) const; + xm_inline Vect3f& invXformPoint(Vect3f& p) const; + + + // I/O operations ////////////////////////////////////// + friend ostream& operator<<(ostream& os, const MatXd& M); + friend istream& operator>>(istream& is, MatXd& M); + + // MatXd constants //////////////////////////////////////////////////////////// + + static const MatXd ID; // identity matrix + +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class QuatF +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class QuatF +{ + friend class Mat3f; + friend class Se3f; + +private: + + float s_, x_, y_, z_; + + +public: + + // constructors ////////////////////////////////////////////////////////////// + + xm_inline QuatF() {} + + xm_inline QuatF(float s, float x, float y, float z) {set(s, x, y, z);} + + xm_inline QuatF(float angle, const Vect3f& axis, int normalizeAxis = 1) {set(angle, axis, normalizeAxis);} + + xm_inline QuatF(const Mat3f& R) {set(R);} + + xm_inline operator QuatD () const; + + // setters / accessors / translators ///////////////////////////////////////// + + xm_inline QuatF& set(float s, float x, float y, float z) { s_=s; x_=x; y_=y; z_=z; return *this; } + + // set a quaternion to a rotation of 'angle' radians about 'axis' + // the axis passed is automatically normalized unless normalizeAxis = 0 + QuatF& set(float angle, const Vect3f& axis, int normalizeAxis = 1); + + QuatF& set(const Mat3f& R); + + xm_inline operator const float* () const { return &s_; } + xm_inline operator float* () { return &s_; } + + xm_inline const float& operator[](int i) const {return *(&s_ + i);} + xm_inline float& operator[](int i) {return *(&s_ + i);} + + float s() const {return s_;} + float x() const {return x_;} + float y() const {return y_;} + float z() const {return z_;} + + float& s() {return s_;} + float& x() {return x_;} + float& y() {return y_;} + float& z() {return z_;} + + xm_inline Vect3f axis() const; // normalized axis of rotation + xm_inline float angle() const; // angle of rotation in radians, in range [0, 2pi) + + + // Logical operations /////////////// + xm_inline int operator== (const QuatF& other) const; + xm_inline int operator!= (const QuatF& other) const; + + // Negate //////////////////////////////////// + xm_inline QuatF operator- () const { return QuatF(-s_, -x_, -y_, -z_); } + xm_inline QuatF& negate(const QuatF& q){ s_ = -q.s_; x_ = -q.x_; y_ = -q.y_; z_ = -q.z_; return *this; } + xm_inline QuatF& negate(){ s_ = -s_; x_ = -x_; y_ = -y_; z_ = -z_; return *this; } + + // Normalization /////////////////////// + xm_inline QuatF& normalize(const QuatF& q); // q/|q| + xm_inline QuatF& normalize(); // this/|this| + xm_inline friend QuatF normalize(const QuatF& q); + xm_inline float norm() const { return sqrtf(x_*x_ + y_*y_ + z_*z_ + s_*s_); } + + // Invertion ///////////////////////// + xm_inline QuatF& invert(const QuatF& q); // q^-1 + xm_inline QuatF& invert(); // this^-1 + + + // QuatF - QuatF operations /////////////// + xm_inline QuatF& operator+= (const QuatF& q); + xm_inline QuatF& operator-= (const QuatF& q); + xm_inline QuatF operator+ (const QuatF& q) const; + xm_inline QuatF operator- (const QuatF& q) const; + + // Cross product ///////////////// + QuatF& mult(const QuatF& p, const QuatF& q); // p * q [!] + QuatF& premult(const QuatF& q); // q * this [!] + QuatF& postmult(const QuatF& q); // this * q [!] + xm_inline QuatF& operator%= (const QuatF& q){ return postmult(q); } + xm_inline QuatF operator% (const QuatF& q) const { QuatF u; return u.mult(*this, q); } + + // Dot product //////////////////// + xm_inline float dot(const QuatF& other) const; + xm_inline friend float dot(const QuatF& u, const QuatF& v) { return u.dot(v); } + + // Scalar multiplication & division ////////// + xm_inline QuatF& operator*= (float s); + xm_inline QuatF& operator/= (float s); + xm_inline QuatF operator* (float s) const; + xm_inline QuatF operator/ (float s) const; + xm_inline friend QuatF operator* (float s,const QuatF& q); + + + // Transforming Vect3f /////////////////////////////////////////////////////// + + Vect3f& xform(const Vect3f& u, Vect3f& v) const; // this (v 0) this^-1 => xv + Vect3f& xform(Vect3f& v) const; // this (v 0) this^-1 => v + + // These are exactly like the above methods, except the inverse + // transform is used (i.e. the factors this and this^-1 are swapped). + Vect3f& invXform(const Vect3f& v, Vect3f& xv) const; + Vect3f& invXform(Vect3f& v) const; + + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const QuatF& q); + friend istream& operator>> (istream& is, QuatF& q); + + friend XStream& operator<= (XStream& s,const QuatF& q); + friend XStream& operator>= (XStream& s,QuatF& q); + friend XStream& operator< (XStream& s,const QuatF& q); + friend XStream& operator> (XStream& s,QuatF& q); + + friend XBuffer& operator<= (XBuffer& b,const QuatF& q); + friend XBuffer& operator>= (XBuffer& b,QuatF& q); + friend XBuffer& operator< (XBuffer& b,const QuatF& q); + friend XBuffer& operator> (XBuffer& b,QuatF& q); + + + // miscellaneous ///////////////////////////////////////////////////////////// + xm_inline void slerp(const QuatF &a,const QuatF &b,float t); + + // QuatF constants //////////////////////////////////////////////////////////// + + static const QuatF ID; // identity quaternion + +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class QuatD +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class QuatD +{ + friend class Mat3d; + friend class Se3d; + +private: + + double s_, x_, y_, z_; + + +public: + + // constructors ////////////////////////////////////////////////////////////// + + QuatD() {} + + QuatD(double s, double x, double y, double z) {set(s, x, y, z);} + + QuatD(double angle, const Vect3d& axis, int normalizeAxis = 1) + {set(angle, axis, normalizeAxis);} + + QuatD(const Mat3d& R) {set(R);} + + xm_inline operator QuatF () const; + + // setters / accessors / translators ///////////////////////////////////////// + + QuatD& set(double s, double x, double y, double z) { s_=s; x_=x; y_=y; z_=z; return *this; } + + // set a quaternion to a rotation of 'angle' radians about 'axis' + // the axis passed is automatically normalized unless normalizeAxis = 0 + QuatD& set(double angle, const Vect3d& axis, int normalizeAxis = 1); + + QuatD& set(const Mat3d& R); + + xm_inline operator const double* () const { return &s_; } + xm_inline operator double* () { return &s_; } + + xm_inline const double& operator[](int i) const {return *(&s_ + i);} + xm_inline double& operator[](int i) {return *(&s_ + i);} + + double s() const {return s_;} + double x() const {return x_;} + double y() const {return y_;} + double z() const {return z_;} + + double& s() {return s_;} + double& x() {return x_;} + double& y() {return y_;} + double& z() {return z_;} + + xm_inline Vect3d axis() const; // normalized axis of rotation + xm_inline double angle() const; // angle of rotation in radians, in range [0, 2pi) + + + // Logical operations /////////////// + xm_inline int operator== (const QuatD& other) const; + xm_inline int operator!= (const QuatD& other) const; + + // Negate //////////////////////////////////// + xm_inline QuatD operator- () const { return QuatD(-s_, -x_, -y_, -z_); } + xm_inline QuatD& negate(const QuatD& q){ s_ = -q.s_; x_ = -q.x_; y_ = -q.y_; z_ = -q.z_; return *this; } + xm_inline QuatD& negate(){ s_ = -s_; x_ = -x_; y_ = -y_; z_ = -z_; return *this; } + + // Normalization /////////////////////// + xm_inline QuatD& normalize(const QuatD& q); // q/|q| + xm_inline QuatD& normalize(); // this/|this| + xm_inline friend QuatD normalize(const QuatD& q); + xm_inline double norm() const { return sqrt(x_*x_ + y_*y_ + z_*z_ + s_*s_); } + + // Invertion ///////////////////////// + xm_inline QuatD& invert(const QuatD& q); // q^-1 + xm_inline QuatD& invert(); // this^-1 + + + // QuatD - QuatD operations /////////////// + xm_inline QuatD& operator+= (const QuatD& q); + xm_inline QuatD& operator-= (const QuatD& q); + xm_inline QuatD operator+ (const QuatD& q) const; + xm_inline QuatD operator- (const QuatD& q) const; + + // Cross product ///////////////// + QuatD& mult(const QuatD& p, const QuatD& q); // p * q [!] + QuatD& premult(const QuatD& q); // q * this [!] + QuatD& postmult(const QuatD& q); // this * q [!] + xm_inline QuatD& operator%= (const QuatD& q){ return postmult(q); } + xm_inline QuatD operator% (const QuatD& q) const { QuatD u; return u.mult(*this, q); } + + // Dot product //////////////////// + xm_inline double dot(const QuatD& other) const; + friend double dot(const QuatD& u, const QuatD& v) { return u.dot(v); } + + // Scalar multiplication & division ////////// + xm_inline QuatD& operator*= (double s); + xm_inline QuatD& operator/= (double s); + xm_inline QuatD operator* (double s) const; + xm_inline QuatD operator/ (double s) const; + xm_inline friend QuatD operator* (double s,const QuatD& q); + + + + // Transforming Vect3d /////////////////////////////////////////////////////// + + Vect3d& xform(const Vect3d& u, Vect3d& v) const; // this (v 0) this^-1 => xv + Vect3d& xform(Vect3d& v) const; // this (v 0) this^-1 => v + + // These are exactly like the above methods, except the inverse + // transform is used (i.e. the factors this and this^-1 are swapped). + Vect3d& invXform(const Vect3d& v, Vect3d& xv) const; + Vect3d& invXform(Vect3d& v) const; + + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const QuatD& q); + friend istream& operator>> (istream& is, QuatD& q); + + friend XStream& operator<= (XStream& s,const QuatD& q); + friend XStream& operator>= (XStream& s,QuatD& q); + friend XStream& operator< (XStream& s,const QuatD& q); + friend XStream& operator> (XStream& s,QuatD& q); + + friend XBuffer& operator<= (XBuffer& b,const QuatD& q); + friend XBuffer& operator>= (XBuffer& b,QuatD& q); + friend XBuffer& operator< (XBuffer& b,const QuatD& q); + friend XBuffer& operator> (XBuffer& b,QuatD& q); + + // miscellaneous ///////////////////////////////////////////////////////////// + xm_inline void slerp(const QuatD &a,const QuatD &b, double t); + + // QuatD constants //////////////////////////////////////////////////////////// + + static const QuatD ID; // identity quaternion +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Se3f +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +class Se3f +{ +private: + + QuatF q; // rotation component + Vect3f d; // translation component + +public: + + // constructors ////////////////////////////////////////////////////////////// + + + Se3f() {} + Se3f(const QuatF& q_, const Vect3f& d_) { set(q_, d_); } + Se3f(const MatXf& X) { set(X); } + + xm_inline operator Se3d () const; + + // setters / accessors / translators ///////////////////////////////////////// + + Se3f& set(const QuatF& q_, const Vect3f& d_) { q = q_; d = d_; return *this; } + Se3f& set(const MatXf& X) { q.set(X.rot()); d = X.trans(); return *this; } + + const QuatF& rot() const {return q;} + const Vect3f& trans() const {return d;} + QuatF& rot() {return q;} + Vect3f& trans() {return d;} + + + // Se3f - Se3f multiplication //////////// + xm_inline Se3f& mult(const Se3f& T, const Se3f& U); // T * U [!] + xm_inline Se3f& premult(const Se3f& T); // T * this [!] + xm_inline Se3f& postmult(const Se3f& T); // this * T [!] + xm_inline Se3f& operator*= (const Se3f& T) { return postmult(T); } + xm_inline Se3f operator* (const Se3f& U) const { Se3f T; return T.mult(*this, U); } + + // Invertion /////////////////// + xm_inline Se3f& invert(const Se3f& T); // T^-1 + xm_inline Se3f& invert(); // this^-1 + + + // Transforming Vect3d /////////////////////////////////////////////////////// + + // Se3s can transform elements of R^3 either as vectors or as + // points. Multiple operands need not be distinct. + + xm_inline Vect3f& xformVect(const Vect3f& v, Vect3f& xv) const; // this * (v 0) => xv + xm_inline Vect3f& xformVect(Vect3f& v) const; // this * (v 0) => v + xm_inline Vect3f& xformPoint(const Vect3f& p, Vect3f& xp) const; // this * (p 1) => xp + xm_inline Vect3f& xformPoint(Vect3f& p) const; // this * (p 1) => p + + // These are exactly like the above methods, except the inverse + // transform this^-1 is used. + xm_inline Vect3f& invXformVect(const Vect3f& v, Vect3f& xv) const; + xm_inline Vect3f& invXformVect(Vect3f& v) const; + xm_inline Vect3f& invXformPoint(const Vect3f& p, Vect3f& xp) const; + xm_inline Vect3f& invXformPoint(Vect3f& p) const; + + + // I/O operations ////////////////////////////////////// + + friend ostream& operator<<(ostream& os, const Se3f& se3); + friend istream& operator>>(istream& is, Se3f& se3); + + + // Se3f constants ///////////////////////////////////////////////////////////// + + static const Se3f ID; // identity Se3f +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Se3d +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Se3d +{ +private: + + QuatD q; // rotation component + Vect3d d; // translation component + +public: + + // constructors ////////////////////////////////////////////////////////////// + + + Se3d() {} + Se3d(const QuatD& q_, const Vect3d& d_) { set(q_, d_); } + Se3d(const MatXd& X) { set(X); } + + xm_inline operator Se3f () const; + + // setters / accessors / translators ///////////////////////////////////////// + + Se3d& set(const QuatD& q_, const Vect3d& d_) { q = q_; d = d_; return *this; } + Se3d& set(const MatXd& X) { q.set(X.rot()); d = X.trans(); return *this; } + + const QuatD& rot() const {return q;} + const Vect3d& trans() const {return d;} + QuatD& rot() {return q;} + Vect3d& trans() {return d;} + + + // Se3d - Se3d multiplication //////////// + xm_inline Se3d& mult(const Se3d& T, const Se3d& U); // T * U [!] + xm_inline Se3d& premult(const Se3d& T); // T * this [!] + xm_inline Se3d& postmult(const Se3d& T); // this * T [!] + Se3d& operator*= (const Se3d& T) { return postmult(T); } + Se3d operator* (const Se3d& U) const { Se3d T; return T.mult(*this, U); } + + // Invertion /////////////////// + xm_inline Se3d& invert(const Se3d& T); // T^-1 + xm_inline Se3d& invert(); // this^-1 + + + // Transforming Vect3d /////////////////////////////////////////////////////// + + // Se3s can transform elements of R^3 either as vectors or as + // points. Multiple operands need not be distinct. + + xm_inline Vect3d& xformVect(const Vect3d& v, Vect3d& xv) const; // this * (v 0) => xv + xm_inline Vect3d& xformVect(Vect3d& v) const; // this * (v 0) => v + xm_inline Vect3d& xformPoint(const Vect3d& p, Vect3d& xp) const; // this * (p 1) => xp + xm_inline Vect3d& xformPoint(Vect3d& p) const; // this * (p 1) => p + + // These are exactly like the above methods, except the inverse + // transform this^-1 is used. + xm_inline Vect3d& invXformVect(const Vect3d& v, Vect3d& xv) const; + xm_inline Vect3d& invXformVect(Vect3d& v) const; + xm_inline Vect3d& invXformPoint(const Vect3d& p, Vect3d& xp) const; + xm_inline Vect3d& invXformPoint(Vect3d& p) const; + + + // I/O operations ////////////////////////////////////// + + friend ostream& operator<<(ostream& os, const Se3d& se3); + friend istream& operator>>(istream& is, Se3d& se3); + + + // Se3d constants ///////////////////////////////////////////////////////////// + + static const Se3d ID; // identity Se3d +}; + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Vect4f +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Vect4f +{ + +public: + + float x, y, z, w; + + // constructors ////////////////////////////////////////////////////////////// + + xm_inline Vect4f() {} + xm_inline Vect4f(float x_, float y_, float z_, float w_ = 1.0f) { x = x_; y = y_; z = z_; w = w_; } + + xm_inline operator Vect3f () const { return Vect3f(x, y, z); } + + // setters / accessors / translators ///////////////////////////////////////// + + Vect4f& set(float x_, float y_, float z_, float w_ = 1.0f) { x = x_; y = y_; z = z_; w = w_; return *this; } + + // index-based access: 0=x, 1=y, 2=z, 3 = w. + xm_inline const float& operator[](int i) const {return *(&x + i);} + xm_inline float& operator[](int i) {return *(&x + i);} + + // Convertion to int /////// + xm_inline int xi() const { return round(x); } + xm_inline int yi() const { return round(y); } + xm_inline int zi() const { return round(z); } + xm_inline int wi() const { return round(w); } + + // Logical operations //////////////////////////////// + xm_inline int operator== (const Vect4f& v) const; + xm_inline int operator!= (const Vect4f& v) const; + + // Addition and substruction //////////////////// + xm_inline Vect4f& add(const Vect4f& u, const Vect4f& v); + xm_inline Vect4f& add(const Vect4f& v); + xm_inline Vect4f& sub(const Vect4f& u, const Vect4f& v); + xm_inline Vect4f& sub(const Vect4f& v); + xm_inline Vect4f& operator+= (const Vect4f& v) { return add(v); } + xm_inline Vect4f& operator-= (const Vect4f& v) { return sub(v); } + xm_inline Vect4f operator+ (const Vect4f& v) const { Vect4f u; return u.add(*this,v); } + xm_inline Vect4f operator- (const Vect4f& v) const { Vect4f u; return u.sub(*this,v); } + + // Component-wise multiplication and division //////////////// + xm_inline Vect4f& mult(const Vect4f& u, const Vect4f& v); + xm_inline Vect4f& mult(const Vect4f& v); + xm_inline Vect4f& div(const Vect4f& u, const Vect4f& v); + xm_inline Vect4f& div(const Vect4f& v); + xm_inline Vect4f& operator*= (const Vect4f& v) { return mult(v); } + xm_inline Vect4f& operator/= (const Vect4f& v) { return div(v); } + xm_inline Vect4f operator* (const Vect4f& v) const { Vect4f u; return u.mult(*this, v); } + xm_inline Vect4f operator/ (const Vect4f& v) const { Vect4f u; return u.div(*this, v); } + + // Multiplication & division by scalar /////////// + xm_inline Vect4f& scale(const Vect4f& v, float s); + xm_inline Vect4f& scale(float s); + xm_inline Vect4f& operator*= (float s) { return scale(s); } + xm_inline Vect4f& operator/= (float s) { return scale(1/s); } + xm_inline Vect4f operator* (float s) const { Vect4f u; return u.scale(*this, s); } + xm_inline Vect4f operator/ (float s) const { Vect4f u; return u.scale(*this, 1/s); } + xm_inline friend Vect4f operator* (float s,const Vect4f& v) { Vect4f u; return u.scale(v, s); } + + // Projection: x /= w, y /= w, z /= w, w = 1/w + xm_inline Vect4f& project(); + xm_inline Vect4f& project(const Vect4f& v); + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Vect4f& v); + friend istream& operator>> (istream& is, Vect4f& v); + + friend XStream& operator<= (XStream& s,const Vect4f& v); + friend XStream& operator>= (XStream& s,Vect4f& v); + friend XStream& operator< (XStream& s,const Vect4f& v); + friend XStream& operator> (XStream& s,Vect4f& v); + + friend XBuffer& operator<= (XBuffer& b,const Vect4f& v); + friend XBuffer& operator>= (XBuffer& b,Vect4f& v); + friend XBuffer& operator< (XBuffer& b,const Vect4f& v); + friend XBuffer& operator> (XBuffer& b,Vect4f& v); + + // Swap ///////////////////////// + xm_inline void swap(Vect4f& other); + xm_inline friend void swap(Vect4f& u, Vect4f& v) { u.swap(v);} + + + // Vect4f constants /////////////////////////////////////////////////////////// + + static const Vect4f ZERO; + static const Vect4f ID; + +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// class Mat4f +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class Mat4f +{ + + // (stored in row-major order) + float xx, xy, xz, xw, + yx, yy, yz, yw, + zx, zy, zz, zw, + wx, wy, wz, ww; + +public: + + // constructors ////////////////////////////////////////////////////////////// + + xm_inline Mat4f() {} + + xm_inline Mat4f(float xx,float xy,float xz, float xw, + float yx,float yy,float yz, float yw, + float zx,float zy,float zz, float zw, + float wx,float wy,float wz, float ww); + + xm_inline Mat4f(const Mat3f& rot) { set(rot); } + xm_inline Mat4f(const Mat3f& rot, const Vect3f& trans) { set(rot, trans); } + xm_inline Mat4f(const MatXf& X) { set(X); } + + // setters / accessors /////////////////////////////////////////////////////// + + xm_inline Mat4f& set(const Mat3f& rot); + xm_inline Mat4f& set(const Mat3f& rot, const Vect3f& trans); + xm_inline Mat4f& set(const MatXf& X); + + // index-based access: 0=xrow, 1=yrow, 2=zrow, 3=wrow. + xm_inline const Vect4f& operator[](int i) const {return *(((Vect4f *) &xx) + i);} + xm_inline Vect4f& operator[](int i) {return *(((Vect4f *) &xx) + i);} + + + // for reading rows + xm_inline const Vect4f& xrow() const {return *((Vect4f *) &xx);} + xm_inline const Vect4f& yrow() const {return *((Vect4f *) &yx);} + xm_inline const Vect4f& zrow() const {return *((Vect4f *) &zx);} + xm_inline const Vect4f& wrow() const {return *((Vect4f *) &wx);} + // for writing to rows + xm_inline Vect4f& xrow() {return *((Vect4f *) &xx);} + xm_inline Vect4f& yrow() {return *((Vect4f *) &yx);} + xm_inline Vect4f& zrow() {return *((Vect4f *) &zx);} + xm_inline Vect4f& wrow() {return *((Vect4f *) &wx);} + + // for reading columns + xm_inline Vect4f xcol() const {return Vect4f(xx, yx, zx, wx);} + xm_inline Vect4f ycol() const {return Vect4f(xy, yy, zy, wy);} + xm_inline Vect4f zcol() const {return Vect4f(xz, yz, zz, wz);} + xm_inline Vect4f wcol() const {return Vect4f(xw, yw, zw, ww);} + // for writing to columns + xm_inline Mat4f& setXcol(const Vect4f& v); + xm_inline Mat4f& setYcol(const Vect4f& v); + xm_inline Mat4f& setZcol(const Vect4f& v); + xm_inline Mat4f& setWcol(const Vect4f& v); + + // for reading a symmetric matrix + xm_inline Vect4f diag() const {return Vect4f(xx, yy, zz, ww); } + + + // Access to elements for Mapple-like notation (numerating from 1): + // 1,1 1,2 1,3 1,4 + // 2,1 2,2 2,3 2,4 + // 3,1 3,2 3,3 3,4 + // 4,1 4,2 4,3 4,4 + xm_inline const float& operator ()(int i,int j) const { return (&xx)[(i - 1)*4 + j - 1]; } + xm_inline float& operator ()(int i,int j){ return (&xx)[(i - 1)*4 + j - 1]; } + + // Determinant of matrix ///////// + xm_inline float det() const; + + // Mat4f - Mat4f multiplication /////////// + Mat4f& mult(const Mat4f& M, const Mat4f& N); // M * N [!] + Mat4f& premult(const Mat4f& M); // M * this [!] + Mat4f& postmult(const Mat4f& M); // this * M [!] + Mat4f& operator*= (const Mat4f& M) { return postmult(M); } + Mat4f operator* (const Mat4f& M) const { Mat4f N; return N.mult(*this, M); } + + // Transposition //////////////// + xm_inline Mat4f& xpose(); // this^T + xm_inline Mat4f& xpose(const Mat4f& M); // M^T [!] + xm_inline friend Mat4f xpose(const Mat4f& M) { Mat4f N; return N.xpose(M); } + + // Invertion //////////////////// + int invert(); // this^-1, returns one if the matrix was not invertible, otherwise zero. + int invert(const Mat4f& M); // M^-1 [!] + xm_inline friend Mat4f invert(const Mat4f& M) { Mat4f N; N.invert(M); return N; } + + + // Transforming Vect4f /////////////////////////////////////////////////////// + + // return reference to converted vector + xm_inline Vect4f& xform(const Vect4f& v, Vect4f& xv) const; // (this)(v) => xv [!] + xm_inline Vect4f& xform(Vect4f& v) const; // (this)(v) => v + + // Transforming operators /////////////// + xm_inline friend Vect4f& operator*= (Vect4f& v, const Mat4f& M) { return M.xform(v); } + xm_inline friend Vect4f operator* (const Vect4f& v, const Mat4f& M) { Vect4f xv; return M.xform(v, xv); } + xm_inline friend Vect4f operator* (const Mat4f& M, const Vect4f& v) { Vect4f xv; return M.xform(v, xv); } + + // Transforming Vect3f -> Vect4f /////////////////////////////////////////////////////// + xm_inline Vect4f& xform(const Vect3f& v, Vect4f& xv) const; // (this)(v) => xv [!] + + // Transforming operators /////////////// + xm_inline friend Vect4f operator* (const Vect3f& v, const Mat4f& M) { Vect4f xv; return M.xform(v, xv); } + xm_inline friend Vect4f operator* (const Mat4f& M, const Vect3f& v) { Vect4f xv; return M.xform(v, xv); } + + + + // I/O operations ////////////////////////////////////// + friend ostream& operator<< (ostream& os, const Mat4f& M); + friend istream& operator>> (istream& is, Mat4f& M); + + friend XStream& operator<= (XStream& s,const Mat4f& M); + friend XStream& operator>= (XStream& s,Mat4f& M); + friend XStream& operator< (XStream& s,const Mat4f& M); + friend XStream& operator> (XStream& s,Mat4f& M); + + friend XBuffer& operator<= (XBuffer& b,const Mat4f& M); + friend XBuffer& operator>= (XBuffer& b,Mat4f& M); + friend XBuffer& operator< (XBuffer& b,const Mat4f& M); + friend XBuffer& operator> (XBuffer& b,Mat4f& M); + + + // Mat4f constants //////////////////////////////////////////////////////////// + + static const Mat4f ZERO; // zero matrix + static const Mat4f ID; // identity matrix + +}; + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Miscellaneous functions +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Decomposition //////////////////////////////// +xm_inline void decomposition(const Vect3f& axis, const Vect3f& v, Vect3f& v_normal, Vect3f& v_tangent) +{ + // axis - axis of decomposition, v_normal - collinear to axis, v_tangent - perpendicular to axis + v_normal.scale(axis, dot(axis, v)/((axis).norm2())); + v_tangent.sub(v,v_normal); +} +xm_inline void decomposition(const Vect3d& axis, const Vect3d& v, Vect3d& v_normal, Vect3d& v_tangent) +{ + // axis - axis of decomposition, v_normal - collinear to axis, v_tangent - perpendicular to axis + v_normal.scale(axis, dot(axis, v)/((axis).norm2())); + v_tangent.sub(v,v_normal); +} + + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//// +//// DEFINITIONS +//// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// +// Vect2 definitions +// +/////////////////////////////////////////////////////////////////////////////// +xm_inline Vect2i::Vect2i(const Vect2s& v) { x = v.x; y = v.y; } +xm_inline Vect2f::Vect2f(const Vect3f& v) { x = v.x; y = v.y; } +xm_inline Vect2f::Vect2f(const Vect2i& v) { x = float(v.x); y = float(v.y); } +xm_inline Vect2f::Vect2f(const Vect2s& v) { x = v.x; y = v.y; } + + +/////////////////////////////////////////////////////////////////////////////// +// +// Vect3f xm_inline definitions +// +/////////////////////////////////////////////////////////////////////////////// +Vect3d::operator Vect3f () const +{ + return Vect3f((float)x, (float)y, (float)z); +} +Vect3f::operator Vect3d () const +{ + return Vect3d(x, y, z); +} +// Dot product ////////////////////// +//xm_inline double dot(const Vect3d& u, const Vect3f& v) { return u.dot(v); } +//xm_inline float dot(const Vect3f& u, const Vect3d& v) { return u.dot(v); } + +int Vect3f::operator== (const Vect3f& other) const +{ + return fabs(x - other.x) < FLT_COMPARE_TOLERANCE && + fabs(y - other.y) < FLT_COMPARE_TOLERANCE && + fabs(z - other.z) < FLT_COMPARE_TOLERANCE; +} + +int Vect3f::operator!= (const Vect3f& v) const +{ + return fabs(x - v.x) > FLT_COMPARE_TOLERANCE || + fabs(y - v.y) > FLT_COMPARE_TOLERANCE || + fabs(z - v.z) > FLT_COMPARE_TOLERANCE; +} + +Vect3f Vect3f::operator- () const +{ + return Vect3f(-x,-y,-z); +} + +// Norm operations ///////// +float Vect3f::sumAbs() const +{ + return (float)(fabs(x) + fabs(y) + fabs(z)); +} + + +// Descart - spherical function ////////////// +float Vect3f::psi() const +{ + return (float)atan2(y,x); +} +float Vect3f::theta() const +{ + return (float)acos(z/(norm() + FLT_EPS)); +} +Vect3f& Vect3f::setSpherical(float psi,float theta,float radius) +{ + x = radius*(float)sin(theta); + y = x*(float)sin(psi); + x = x*(float)cos(psi); + z = radius*(float)cos(theta); + return *this; +} + +float Vect3f::dot (const Vect3f& other) const +{ + return x * other.x + y * other.y + z * other.z; +} + + +float Vect3f::norm() const +{ + return (float)sqrt(x * x + y * y + z * z); +} + + +float Vect3f::norm2() const +{ + return (x * x + y * y + z * z); +} + + +float Vect3f::distance(const Vect3f& other) const +{ + Vect3f w; + + w.sub(other, *this); + return w.norm(); +} + + +float Vect3f::distance2(const Vect3f& other) const +{ + Vect3f w; + + w.sub(other, *this); + return w.norm2(); +} + + +float Vect3f::min() const +{ + return (x <= y) ? ((x <= z) ? x : z) : ((y <= z) ? y : z); +} + + +float Vect3f::max() const +{ + return (x >= y) ? ((x >= z) ? x : z) : ((y >= z) ? y : z); +} + + +float Vect3f::minAbs() const +{ + float ax, ay, az; + + ax = (float)fabs(x); + ay = (float)fabs(y); + az = (float)fabs(z); + return (ax <= ay) ? ((ax <= az) ? ax : az) : ((ay <= az) ? ay : az); +} + + +float Vect3f::maxAbs() const +{ + float ax, ay, az; + + ax = (float)fabs(x); + ay = (float)fabs(y); + az = (float)fabs(z); + return (ax >= ay) ? ((ax >= az) ? ax : az) : ((ay >= az) ? ay : az); +} + + +void Vect3f::swap(Vect3f& other) +{ + Vect3f tmp; + + tmp = *this; + *this = other; + other = tmp; +} + + +Vect3f& Vect3f::normalize(const Vect3f& v, float r) +{ + float s = r / (float)sqrt(v.x * v.x + v.y * v.y + v.z * v.z); + x = s * v.x; + y = s * v.y; + z = s * v.z; + return *this; +} + + +Vect3f& Vect3f::normalize(float r) +{ + float s = r / (float)sqrt(x * x + y * y + z * z); + x *= s; + y *= s; + z *= s; + return *this; +} + + +Vect3f& Vect3f::Normalize(const Vect3f& v, float r) +{ + float s = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); + if(s > FLT_EPS){ + s = r/s; + x = s * v.x; + y = s * v.y; + z = s * v.z; + } + return *this; +} + + +Vect3f& Vect3f::Normalize(float r) +{ + float s = sqrtf(x * x + y * y + z * z); + if(s > FLT_EPS){ + s = r/s; + x *= s; + y *= s; + z *= s; + } + return *this; +} + + + +Vect3f& Vect3f::negate(const Vect3f& v) +{ + x = - v.x; + y = - v.y; + z = - v.z; + return *this; +} + + +Vect3f& Vect3f::negate() +{ + x = - x; + y = - y; + z = - z; + return *this; +} + + +Vect3f& Vect3f::add(const Vect3f& u, const Vect3f& v) +{ + x = u.x + v.x; + y = u.y + v.y; + z = u.z + v.z; + return *this; +} + + +Vect3f& Vect3f::add(const Vect3f& v) +{ + x += v.x; + y += v.y; + z += v.z; + return *this; +} + + +Vect3f& Vect3f::sub(const Vect3f& u, const Vect3f& v) +{ + x = u.x - v.x; + y = u.y - v.y; + z = u.z - v.z; + return *this; +} + + +Vect3f& Vect3f::sub(const Vect3f& v) +{ + x -= v.x; + y -= v.y; + z -= v.z; + return *this; +} + + +Vect3f& Vect3f::mult(const Vect3f& u, const Vect3f& v) +{ + x = u.x * v.x; + y = u.y * v.y; + z = u.z * v.z; + return *this; +} + + +Vect3f& Vect3f::mult(const Vect3f& v) +{ + x *= v.x; + y *= v.y; + z *= v.z; + return *this; +} + +Vect3f& Vect3f::div(const Vect3f& u, const Vect3f& v) +{ + x = u.x / v.x; + y = u.y / v.y; + z = u.z / v.z; + return *this; +} + + +Vect3f& Vect3f::div(const Vect3f& v) +{ + x /= v.x; + y /= v.y; + z /= v.z; + return *this; +} + + + +Vect3f& Vect3f::scale(const Vect3f& v, float s) +{ + x = s * v.x; + y = s * v.y; + z = s * v.z; + return *this; +} + + +Vect3f& Vect3f::scale(float s) +{ + x *= s; + y *= s; + z *= s; + return *this; +} + + + +Vect3f& Vect3f::cross(const Vect3f& u, const Vect3f& v) +{ + x = u.y * v.z - u.z * v.y; + y = u.z * v.x - u.x * v.z; + z = u.x * v.y - u.y * v.x; + return *this; +} + + +Vect3f& Vect3f::precross(const Vect3f& v) +{ + float ox, oy; + + ox = x; + oy = y; + x = v.y * z - v.z * oy; + y = v.z * ox - v.x * z; + z = v.x * oy - v.y * ox; + return *this; +} + + +Vect3f& Vect3f::postcross(const Vect3f& v) +{ + float ox, oy; + + ox = x; + oy = y; + x = oy * v.z - z * v.y; + y = z * v.x - ox * v.z; + z = ox * v.y - oy * v.x; + return *this; +} + + +Vect3f& Vect3f::crossAdd(const Vect3f& u, const Vect3f& v, const Vect3f& w) +{ + x = u.y * v.z - u.z * v.y + w.x; + y = u.z * v.x - u.x * v.z + w.y; + z = u.x * v.y - u.y * v.x + w.z; + return *this; +} + + +Vect3f& Vect3f::crossAdd(const Vect3f& u, const Vect3f& v) +{ + x += u.y * v.z - u.z * v.y; + y += u.z * v.x - u.x * v.z; + z += u.x * v.y - u.y * v.x; + return *this; +} + + +Vect3f& Vect3f::scaleAdd(const Vect3f& v, const Vect3f& u, float lambda) +{ + x = v.x + lambda * u.x; + y = v.y + lambda * u.y; + z = v.z + lambda * u.z; + return *this; +} + + +Vect3f& Vect3f::scaleAdd(const Vect3f& u, float lambda) +{ + x += lambda * u.x; + y += lambda * u.y; + z += lambda * u.z; + return *this; +} + + +Vect3f& Vect3f::interpolate(const Vect3f& u, const Vect3f& v, float lambda) +{ + float lambda2 = 1.0f - lambda; + + x = lambda2 * u.x + lambda * v.x; + y = lambda2 * u.y + lambda * v.y; + z = lambda2 * u.z + lambda * v.z; + return *this; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// Vect3d xm_inline definitions +// +/////////////////////////////////////////////////////////////////////////////// + +int Vect3d::operator== (const Vect3d& other) const +{ + return fabs(x - other.x) < DBL_COMPARE_TOLERANCE && + fabs(y - other.y) < DBL_COMPARE_TOLERANCE && + fabs(z - other.z) < DBL_COMPARE_TOLERANCE; +} + +int Vect3d::operator!= (const Vect3d& v) const +{ + return fabs(x - v.x) > DBL_COMPARE_TOLERANCE || + fabs(y - v.y) > DBL_COMPARE_TOLERANCE || + fabs(z - v.z) > DBL_COMPARE_TOLERANCE; +} + +Vect3d Vect3d::operator- () const +{ + return Vect3d(-x,-y,-z); +} + +// Norm operations ///////// +double Vect3d::sumAbs() const +{ + return fabs(x) + fabs(y) + fabs(z); +} + + +// Descart - spherical function ////////////// +double Vect3d::psi() const +{ + return atan2(y,x); +} +double Vect3d::theta() const +{ + return acos(z/(norm() + DBL_EPS)); +} +Vect3d& Vect3d::setSpherical(double psi,double theta,double radius) +{ + x = radius*sin(theta); + y = x*sin(psi); + x = x*cos(psi); + z = radius*cos(theta); + return *this; +} + +double Vect3d::dot (const Vect3d& other) const +{ + return x * other.x + y * other.y + z * other.z; +} + + +double Vect3d::norm() const +{ + return sqrt(x * x + y * y + z * z); +} + + +double Vect3d::norm2() const +{ + return (x * x + y * y + z * z); +} + + +double Vect3d::distance(const Vect3d& other) const +{ + Vect3d w; + + w.sub(other, *this); + return w.norm(); +} + + +double Vect3d::distance2(const Vect3d& other) const +{ + Vect3d w; + + w.sub(other, *this); + return w.norm2(); +} + + +double Vect3d::min() const +{ + return (x <= y) ? ((x <= z) ? x : z) : ((y <= z) ? y : z); +} + + +double Vect3d::max() const +{ + return (x >= y) ? ((x >= z) ? x : z) : ((y >= z) ? y : z); +} + + +double Vect3d::minAbs() const +{ + double ax, ay, az; + + ax = fabs(x); + ay = fabs(y); + az = fabs(z); + return (ax <= ay) ? ((ax <= az) ? ax : az) : ((ay <= az) ? ay : az); +} + + +double Vect3d::maxAbs() const +{ + double ax, ay, az; + + ax = fabs(x); + ay = fabs(y); + az = fabs(z); + return (ax >= ay) ? ((ax >= az) ? ax : az) : ((ay >= az) ? ay : az); +} + + +void Vect3d::swap(Vect3d& other) +{ + Vect3d tmp; + + tmp = *this; + *this = other; + other = tmp; +} + + +Vect3d& Vect3d::normalize(const Vect3d& v, double r) +{ + double s = r / sqrt(v.x * v.x + v.y * v.y + v.z * v.z); + x = s * v.x; + y = s * v.y; + z = s * v.z; + return *this; +} + + +Vect3d& Vect3d::normalize(double r) +{ + double s = r / sqrt(x * x + y * y + z * z); + x *= s; + y *= s; + z *= s; + return *this; +} + + +Vect3d& Vect3d::Normalize(const Vect3d& v, double r) +{ + double s = sqrt(v.x * v.x + v.y * v.y + v.z * v.z); + if(s > DBL_EPS){ + s = r/s; + x = s * v.x; + y = s * v.y; + z = s * v.z; + } + return *this; +} + + +Vect3d& Vect3d::Normalize(double r) +{ + double s = sqrt(x * x + y * y + z * z); + if(s > DBL_EPS){ + s = r/s; + x *= s; + y *= s; + z *= s; + } + return *this; +} + + + +Vect3d& Vect3d::negate(const Vect3d& v) +{ + x = - v.x; + y = - v.y; + z = - v.z; + return *this; +} + + +Vect3d& Vect3d::negate() +{ + x = - x; + y = - y; + z = - z; + return *this; +} + + +Vect3d& Vect3d::add(const Vect3d& u, const Vect3d& v) +{ + x = u.x + v.x; + y = u.y + v.y; + z = u.z + v.z; + return *this; +} + + +Vect3d& Vect3d::add(const Vect3d& v) +{ + x += v.x; + y += v.y; + z += v.z; + return *this; +} + + +Vect3d& Vect3d::sub(const Vect3d& u, const Vect3d& v) +{ + x = u.x - v.x; + y = u.y - v.y; + z = u.z - v.z; + return *this; +} + + +Vect3d& Vect3d::sub(const Vect3d& v) +{ + x -= v.x; + y -= v.y; + z -= v.z; + return *this; +} + + +Vect3d& Vect3d::mult(const Vect3d& u, const Vect3d& v) +{ + x = u.x * v.x; + y = u.y * v.y; + z = u.z * v.z; + return *this; +} + + +Vect3d& Vect3d::mult(const Vect3d& v) +{ + x *= v.x; + y *= v.y; + z *= v.z; + return *this; +} + +Vect3d& Vect3d::div(const Vect3d& u, const Vect3d& v) +{ + x = u.x / v.x; + y = u.y / v.y; + z = u.z / v.z; + return *this; +} + + +Vect3d& Vect3d::div(const Vect3d& v) +{ + x /= v.x; + y /= v.y; + z /= v.z; + return *this; +} + + + +Vect3d& Vect3d::scale(const Vect3d& v, double s) +{ + x = s * v.x; + y = s * v.y; + z = s * v.z; + return *this; +} + + +Vect3d& Vect3d::scale(double s) +{ + x *= s; + y *= s; + z *= s; + return *this; +} + + + +Vect3d& Vect3d::cross(const Vect3d& u, const Vect3d& v) +{ + x = u.y * v.z - u.z * v.y; + y = u.z * v.x - u.x * v.z; + z = u.x * v.y - u.y * v.x; + return *this; +} + + +Vect3d& Vect3d::precross(const Vect3d& v) +{ + double ox, oy; + + ox = x; + oy = y; + x = v.y * z - v.z * oy; + y = v.z * ox - v.x * z; + z = v.x * oy - v.y * ox; + return *this; +} + + +Vect3d& Vect3d::postcross(const Vect3d& v) +{ + double ox, oy; + + ox = x; + oy = y; + x = oy * v.z - z * v.y; + y = z * v.x - ox * v.z; + z = ox * v.y - oy * v.x; + return *this; +} + + +Vect3d& Vect3d::crossAdd(const Vect3d& u, const Vect3d& v, const Vect3d& w) +{ + x = u.y * v.z - u.z * v.y + w.x; + y = u.z * v.x - u.x * v.z + w.y; + z = u.x * v.y - u.y * v.x + w.z; + return *this; +} + + +Vect3d& Vect3d::crossAdd(const Vect3d& u, const Vect3d& v) +{ + x += u.y * v.z - u.z * v.y; + y += u.z * v.x - u.x * v.z; + z += u.x * v.y - u.y * v.x; + return *this; +} + + +Vect3d& Vect3d::scaleAdd(const Vect3d& v, const Vect3d& u, double lambda) +{ + x = v.x + lambda * u.x; + y = v.y + lambda * u.y; + z = v.z + lambda * u.z; + return *this; +} + + +Vect3d& Vect3d::scaleAdd(const Vect3d& u, double lambda) +{ + x += lambda * u.x; + y += lambda * u.y; + z += lambda * u.z; + return *this; +} + + +Vect3d& Vect3d::interpolate(const Vect3d& u, const Vect3d& v, double lambda) +{ + double lambda2 = 1.0 - lambda; + + x = lambda2 * u.x + lambda * v.x; + y = lambda2 * u.y + lambda * v.y; + z = lambda2 * u.z + lambda * v.z; + return *this; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// Mat3f xm_inline definitions +// +/////////////////////////////////////////////////////////////////////////////// + +Mat3f::Mat3f(float xx_,float xy_,float xz_, + float yx_,float yy_,float yz_, + float zx_,float zy_,float zz_) +{ + xx = xx_; xy = xy_; xz = xz_; + yx = yx_; yy = yy_; yz = yz_; + zx = zx_; zy = zy_; zz = zz_; +} + +Mat3f& Mat3f::set(float angle, eAxis axis) +{ +// ------ Calculate Matrix for ROTATE point an angle ------ + float calpha = (float)cos(angle); + float salpha = (float)sin(angle); + switch(axis){ + case Z_AXIS: + xx = calpha; xy = -salpha; xz = 0; + yx = salpha; yy = calpha; yz = 0; + zx = 0; zy = 0; zz = 1; + break; + case X_AXIS: + xx = 1; xy = 0; xz = 0; + yx = 0; yy = calpha; yz = -salpha; + zx = 0; zy = salpha; zz = calpha; + break; + case Y_AXIS: + xx = calpha; xy = 0; xz = salpha; + yx = 0; yy = 1; yz = 0; + zx = -salpha; zy = 0; zz = calpha; + break; + } + return *this; +} + +Mat3f& Mat3f::set(const Vect3f& diag, const Vect3f& sym) +{ + xx = diag.x; + yy = diag.y; + zz = diag.z; + yz = zy = sym.x; + zx = xz = sym.y; + xy = yx = sym.z; + return *this; +} + + +Mat3f& Mat3f::setXcol(const Vect3f& v) +{ + xx = v.x; + yx = v.y; + zx = v.z; + return *this; +} + + +Mat3f& Mat3f::setYcol(const Vect3f& v) +{ + xy = v.x; + yy = v.y; + zy = v.z; + return *this; +} + + +Mat3f& Mat3f::setZcol(const Vect3f& v) +{ + xz = v.x; + yz = v.y; + zz = v.z; + return *this; +} + + +Mat3f& Mat3f::setSkew(const Vect3f& v) +{ + xx = yy = zz = 0.0; + zy = v.x; + yz = -v.x; + xz = v.y; + zx = -v.y; + yx = v.z; + xy = -v.z; + return *this; +} + + +float Mat3f::det() const +{ + return xx * (yy * zz - yz * zy) + + xy * (yz * zx - yx * zz) + + xz * (yx * zy - yy * zx); +} + + +Mat3f& Mat3f::xpose(const Mat3f& M) +{ + xx = M.xx; + xy = M.yx; + xz = M.zx; + + yx = M.xy; + yy = M.yy; + yz = M.zy; + + zx = M.xz; + zy = M.yz; + zz = M.zz; + return *this; +} + + +Mat3f& Mat3f::xpose() +{ + float tmp; + + tmp = xy; + xy = yx; + yx = tmp; + + tmp = yz; + yz = zy; + zy = tmp; + + tmp = zx; + zx = xz; + xz = tmp; + return *this; +} + + +Mat3f& Mat3f::symmetrize(const Mat3f& M) +{ + xx = 2 * M.xx; + yy = 2 * M.yy; + zz = 2 * M.zz; + xy = yx = M.xy + M.yx; + yz = zy = M.yz + M.zy; + zx = xz = M.zx + M.xz; + return *this; +} + + +Mat3f& Mat3f::symmetrize() +{ + xx = 2 * xx; + yy = 2 * yy; + zz = 2 * zz; + xy = yx = xy + yx; + yz = zy = yz + zy; + zx = xz = zx + xz; + return *this; +} + +Mat3f Mat3f::operator- () const +{ + Mat3f M; + M.xx = - xx; + M.xy = - xy; + M.xz = - xz; + + M.yx = - yx; + M.yy = - yy; + M.yz = - yz; + + M.zx = - zx; + M.zy = - zy; + M.zz = - zz; + return M; +} + +Mat3f& Mat3f::negate(const Mat3f& M) +{ + xx = - M.xx; + xy = - M.xy; + xz = - M.xz; + + yx = - M.yx; + yy = - M.yy; + yz = - M.yz; + + zx = - M.zx; + zy = - M.zy; + zz = - M.zz; + + return *this; +} + + +Mat3f& Mat3f::negate() +{ + xx = - xx; + xy = - xy; + xz = - xz; + + yx = - yx; + yy = - yy; + yz = - yz; + + zx = - zx; + zy = - zy; + zz = - zz; + + return *this; +} + + +Mat3f& Mat3f::add(const Mat3f& M, const Mat3f& N) +{ + xx = M.xx + N.xx; + xy = M.xy + N.xy; + xz = M.xz + N.xz; + + yx = M.yx + N.yx; + yy = M.yy + N.yy; + yz = M.yz + N.yz; + + zx = M.zx + N.zx; + zy = M.zy + N.zy; + zz = M.zz + N.zz; + + return *this; +} + + +Mat3f& Mat3f::add(const Mat3f& M) +{ + xx += M.xx; + xy += M.xy; + xz += M.xz; + + yx += M.yx; + yy += M.yy; + yz += M.yz; + + zx += M.zx; + zy += M.zy; + zz += M.zz; + + return *this; +} + + +Mat3f& Mat3f::sub(const Mat3f& M, const Mat3f& N) +{ + xx = M.xx - N.xx; + xy = M.xy - N.xy; + xz = M.xz - N.xz; + + yx = M.yx - N.yx; + yy = M.yy - N.yy; + yz = M.yz - N.yz; + + zx = M.zx - N.zx; + zy = M.zy - N.zy; + zz = M.zz - N.zz; + + return *this; +} + + +Mat3f& Mat3f::sub(const Mat3f& M) +{ + xx -= M.xx; + xy -= M.xy; + xz -= M.xz; + + yx -= M.yx; + yy -= M.yy; + yz -= M.yz; + + zx -= M.zx; + zy -= M.zy; + zz -= M.zz; + + return *this; +} + + +Mat3f& Mat3f::scale(const Mat3f& M, float s) +{ + xx = s * M.xx; + xy = s * M.xy; + xz = s * M.xz; + yx = s * M.yx; + yy = s * M.yy; + yz = s * M.yz; + zx = s * M.zx; + zy = s * M.zy; + zz = s * M.zz; + + return *this; +} + + +Mat3f& Mat3f::scale(const Vect3f &s) +{ + xx *= s.x; + xy *= s.y; + xz *= s.z; + yx *= s.x; + yy *= s.y; + yz *= s.z; + zx *= s.x; + zy *= s.y; + zz *= s.z; + + return *this; +} + +Mat3f& Mat3f::scale(float s) +{ + xx *= s; + xy *= s; + xz *= s; + yx *= s; + yy *= s; + yz *= s; + zx *= s; + zy *= s; + zz *= s; + + return *this; +} + +Mat3f& Mat3f::preScale(const Mat3f& M, const Vect3f& v) +{ // Mat3f(v) * M + xx = M.xx*v.x; + xy = M.xy*v.x; + xz = M.xz*v.x; + + yx = M.yx*v.y; + yy = M.yy*v.y; + yz = M.yz*v.y; + + zx = M.zx*v.z; + zy = M.zy*v.z; + zz = M.zz*v.z; + return *this; +} + +Mat3f& Mat3f::preScale(const Vect3f& v) +{ // Mat3f(s) * this + xx *= v.x; + xy *= v.x; + xz *= v.x; + + yx *= v.y; + yy *= v.y; + yz *= v.y; + + zx *= v.z; + zy *= v.z; + zz *= v.z; + return *this; +} + +Mat3f& Mat3f::postScale(const Mat3f& M, const Vect3f& v) +{ // M * Mat3f(v) + xx = M.xx*v.x; + xy = M.xy*v.y; + xz = M.xz*v.z; + + yx = M.yx*v.x; + yy = M.yy*v.y; + yz = M.yz*v.z; + + zx = M.zx*v.x; + zy = M.zy*v.y; + zz = M.zz*v.z; + return *this; +} + +Mat3f& Mat3f::postScale(const Vect3f& v) +{ // this * Mat3f(v) + xx *= v.x; + xy *= v.y; + xz *= v.z; + + yx *= v.x; + yy *= v.y; + yz *= v.z; + + zx *= v.x; + zy *= v.y; + zz *= v.z; + return *this; +} + + + +// Vect3d transforming ///////////////////// +Vect3d& Mat3f::xform(const Vect3d& v, Vect3d& xv) const +{ + xv.x = xx * v.x + xy * v.y + xz * v.z; + xv.y = yx * v.x + yy * v.y + yz * v.z; + xv.z = zx * v.x + zy * v.y + zz * v.z; + return xv; +} + + +Vect3d& Mat3f::xform(Vect3d& v) const +{ + double ox, oy; + + ox = v.x; oy= v.y; + v.x = xx * ox + xy * oy + xz * v.z; + v.y = yx * ox + yy * oy + yz * v.z; + v.z = zx * ox + zy * oy + zz * v.z; + return v; +} + + +Vect3d& Mat3f::invXform(const Vect3d& v, Vect3d& xv) const +{ + xv.x = xx * v.x + yx * v.y + zx * v.z; + xv.y = xy * v.x + yy * v.y + zy * v.z; + xv.z = xz * v.x + yz * v.y + zz * v.z; + return xv; +} + + +Vect3d& Mat3f::invXform(Vect3d& v) const +{ + double ox, oy; + + ox = v.x; oy= v.y; + v.x = xx * ox + yx * oy + zx * v.z; + v.y = xy * ox + yy * oy + zy * v.z; + v.z = xz * ox + yz * oy + zz * v.z; + return v; +} + +// Vect3f transforming ///////////////////// +Vect3f& Mat3f::xform(const Vect3f& v, Vect3f& xv) const +{ + xv.x = (float)(xx * v.x + xy * v.y + xz * v.z); + xv.y = (float)(yx * v.x + yy * v.y + yz * v.z); + xv.z = (float)(zx * v.x + zy * v.y + zz * v.z); + return xv; +} + + +Vect3f& Mat3f::xform(Vect3f& v) const +{ + float ox, oy; + + ox = v.x; oy= v.y; + v.x = (float)(xx * ox + xy * oy + xz * v.z); + v.y = (float)(yx * ox + yy * oy + yz * v.z); + v.z = (float)(zx * ox + zy * oy + zz * v.z); + return v; +} + + +Vect3f& Mat3f::invXform(const Vect3f& v, Vect3f& xv) const +{ + xv.x = (float)(xx * v.x + yx * v.y + zx * v.z); + xv.y = (float)(xy * v.x + yy * v.y + zy * v.z); + xv.z = (float)(xz * v.x + yz * v.y + zz * v.z); + return xv; +} + + +Vect3f& Mat3f::invXform(Vect3f& v) const +{ + float ox, oy; + + ox = v.x; oy= v.y; + v.x = (float)(xx * ox + yx * oy + zx * v.z); + v.y = (float)(xy * ox + yy * oy + zy * v.z); + v.z = (float)(xz * ox + yz * oy + zz * v.z); + return v; +} + +Mat3f::operator Mat3d () const +{ + return Mat3d( xx, xy, xz, yx, yy, yz, zx, zy, zz ); +} + +Mat3d::operator Mat3f () const +{ + return Mat3f( (float)xx, (float)xy, (float)xz, + (float)yx, (float)yy, (float)yz, + (float)zx, (float)zy, (float)zz ); +} + + + +/////////////////////////////////////////////////////////////////////////////// +// +// Mat3d xm_inline definitions +// +/////////////////////////////////////////////////////////////////////////////// +Mat3d::Mat3d(double xx_,double xy_,double xz_, + double yx_,double yy_,double yz_, + double zx_,double zy_,double zz_) +{ + xx = xx_; xy = xy_; xz = xz_; + yx = yx_; yy = yy_; yz = yz_; + zx = zx_; zy = zy_; zz = zz_; +} + +Mat3d& Mat3d::set(double angle, eAxis axis) +{ +// ------ Calculate Matrix for ROTATE point an angle ------ + double calpha = cos(angle); + double salpha = sin(angle); + switch(axis){ + case Z_AXIS: + xx = calpha; xy = -salpha; xz = 0; + yx = salpha; yy = calpha; yz = 0; + zx = 0; zy = 0; zz = 1; + break; + case X_AXIS: + xx = 1; xy = 0; xz = 0; + yx = 0; yy = calpha; yz = -salpha; + zx = 0; zy = salpha; zz = calpha; + break; + case Y_AXIS: + xx = calpha; xy = 0; xz = salpha; + yx = 0; yy = 1; yz = 0; + zx = -salpha; zy = 0; zz = calpha; + break; + } + return *this; +} + +Mat3d& Mat3d::set(const Vect3d& diag, const Vect3d& sym) +{ + xx = diag.x; + yy = diag.y; + zz = diag.z; + yz = zy = sym.x; + zx = xz = sym.y; + xy = yx = sym.z; + return *this; +} + +Mat3d& Mat3d::setXcol(const Vect3d& v) +{ + xx = v.x; + yx = v.y; + zx = v.z; + return *this; +} + + +Mat3d& Mat3d::setYcol(const Vect3d& v) +{ + xy = v.x; + yy = v.y; + zy = v.z; + return *this; +} + + +Mat3d& Mat3d::setZcol(const Vect3d& v) +{ + xz = v.x; + yz = v.y; + zz = v.z; + return *this; +} + + +Mat3d& Mat3d::setSkew(const Vect3d& v) +{ + xx = yy = zz = 0.0; + zy = v.x; + yz = -v.x; + xz = v.y; + zx = -v.y; + yx = v.z; + xy = -v.z; + return *this; +} + + +double Mat3d::det() const +{ + return xx * (yy * zz - yz * zy) + + xy * (yz * zx - yx * zz) + + xz * (yx * zy - yy * zx); +} + + +Mat3d& Mat3d::xpose(const Mat3d& M) +{ + xx = M.xx; + xy = M.yx; + xz = M.zx; + + yx = M.xy; + yy = M.yy; + yz = M.zy; + + zx = M.xz; + zy = M.yz; + zz = M.zz; + return *this; +} + + +Mat3d& Mat3d::xpose() +{ + double tmp; + + tmp = xy; + xy = yx; + yx = tmp; + + tmp = yz; + yz = zy; + zy = tmp; + + tmp = zx; + zx = xz; + xz = tmp; + return *this; +} + + +Mat3d& Mat3d::symmetrize(const Mat3d& M) +{ + xx = 2 * M.xx; + yy = 2 * M.yy; + zz = 2 * M.zz; + xy = yx = M.xy + M.yx; + yz = zy = M.yz + M.zy; + zx = xz = M.zx + M.xz; + return *this; +} + + +Mat3d& Mat3d::symmetrize() +{ + xx = 2 * xx; + yy = 2 * yy; + zz = 2 * zz; + xy = yx = xy + yx; + yz = zy = yz + zy; + zx = xz = zx + xz; + return *this; +} + +Mat3d Mat3d::operator- () const +{ + Mat3d M; + M.xx = - xx; + M.xy = - xy; + M.xz = - xz; + + M.yx = - yx; + M.yy = - yy; + M.yz = - yz; + + M.zx = - zx; + M.zy = - zy; + M.zz = - zz; + return M; +} + +Mat3d& Mat3d::negate(const Mat3d& M) +{ + xx = - M.xx; + xy = - M.xy; + xz = - M.xz; + + yx = - M.yx; + yy = - M.yy; + yz = - M.yz; + + zx = - M.zx; + zy = - M.zy; + zz = - M.zz; + + return *this; +} + + +Mat3d& Mat3d::negate() +{ + xx = - xx; + xy = - xy; + xz = - xz; + + yx = - yx; + yy = - yy; + yz = - yz; + + zx = - zx; + zy = - zy; + zz = - zz; + + return *this; +} + + +Mat3d& Mat3d::add(const Mat3d& M, const Mat3d& N) +{ + xx = M.xx + N.xx; + xy = M.xy + N.xy; + xz = M.xz + N.xz; + + yx = M.yx + N.yx; + yy = M.yy + N.yy; + yz = M.yz + N.yz; + + zx = M.zx + N.zx; + zy = M.zy + N.zy; + zz = M.zz + N.zz; + + return *this; +} + + +Mat3d& Mat3d::add(const Mat3d& M) +{ + xx += M.xx; + xy += M.xy; + xz += M.xz; + + yx += M.yx; + yy += M.yy; + yz += M.yz; + + zx += M.zx; + zy += M.zy; + zz += M.zz; + + return *this; +} + + +Mat3d& Mat3d::sub(const Mat3d& M, const Mat3d& N) +{ + xx = M.xx - N.xx; + xy = M.xy - N.xy; + xz = M.xz - N.xz; + + yx = M.yx - N.yx; + yy = M.yy - N.yy; + yz = M.yz - N.yz; + + zx = M.zx - N.zx; + zy = M.zy - N.zy; + zz = M.zz - N.zz; + + return *this; +} + + +Mat3d& Mat3d::sub(const Mat3d& M) +{ + xx -= M.xx; + xy -= M.xy; + xz -= M.xz; + + yx -= M.yx; + yy -= M.yy; + yz -= M.yz; + + zx -= M.zx; + zy -= M.zy; + zz -= M.zz; + + return *this; +} + + +Mat3d& Mat3d::scale(const Mat3d& M, double s) +{ + xx = s * M.xx; + xy = s * M.xy; + xz = s * M.xz; + yx = s * M.yx; + yy = s * M.yy; + yz = s * M.yz; + zx = s * M.zx; + zy = s * M.zy; + zz = s * M.zz; + + return *this; +} + + +Mat3d& Mat3d::scale(double s) +{ + xx *= s; + xy *= s; + xz *= s; + yx *= s; + yy *= s; + yz *= s; + zx *= s; + zy *= s; + zz *= s; + + return *this; +} + +Mat3d& Mat3d::preScale(const Mat3d& M, const Vect3d& v) +{ // Mat3d(v) * M + xx = M.xx*v.x; + xy = M.xy*v.x; + xz = M.xz*v.x; + + yx = M.yx*v.y; + yy = M.yy*v.y; + yz = M.yz*v.y; + + zx = M.zx*v.z; + zy = M.zy*v.z; + zz = M.zz*v.z; + return *this; +} + +Mat3d& Mat3d::preScale(const Vect3d& v) +{ // Mat3d(s) * this + xx *= v.x; + xy *= v.x; + xz *= v.x; + + yx *= v.y; + yy *= v.y; + yz *= v.y; + + zx *= v.z; + zy *= v.z; + zz *= v.z; + return *this; +} + +Mat3d& Mat3d::postScale(const Mat3d& M, const Vect3d& v) +{ // M * Mat3d(v) + xx = M.xx*v.x; + xy = M.xy*v.y; + xz = M.xz*v.z; + + yx = M.yx*v.x; + yy = M.yy*v.y; + yz = M.yz*v.z; + + zx = M.zx*v.x; + zy = M.zy*v.y; + zz = M.zz*v.z; + return *this; +} + +Mat3d& Mat3d::postScale(const Vect3d& v) +{ // this * Mat3d(v) + xx *= v.x; + xy *= v.y; + xz *= v.z; + + yx *= v.x; + yy *= v.y; + yz *= v.z; + + zx *= v.x; + zy *= v.y; + zz *= v.z; + return *this; +} + + + +// Vect3d transforming ///////////////////// +Vect3d& Mat3d::xform(const Vect3d& v, Vect3d& xv) const +{ + xv.x = xx * v.x + xy * v.y + xz * v.z; + xv.y = yx * v.x + yy * v.y + yz * v.z; + xv.z = zx * v.x + zy * v.y + zz * v.z; + return xv; +} + + +Vect3d& Mat3d::xform(Vect3d& v) const +{ + double ox, oy; + + ox = v.x; oy= v.y; + v.x = xx * ox + xy * oy + xz * v.z; + v.y = yx * ox + yy * oy + yz * v.z; + v.z = zx * ox + zy * oy + zz * v.z; + return v; +} + + +Vect3d& Mat3d::invXform(const Vect3d& v, Vect3d& xv) const +{ + xv.x = xx * v.x + yx * v.y + zx * v.z; + xv.y = xy * v.x + yy * v.y + zy * v.z; + xv.z = xz * v.x + yz * v.y + zz * v.z; + return xv; +} + + +Vect3d& Mat3d::invXform(Vect3d& v) const +{ + double ox, oy; + + ox = v.x; oy= v.y; + v.x = xx * ox + yx * oy + zx * v.z; + v.y = xy * ox + yy * oy + zy * v.z; + v.z = xz * ox + yz * oy + zz * v.z; + return v; +} + + +// Vect3f transforming ///////////////////// +Vect3f& Mat3d::xform(const Vect3f& v, Vect3f& xv) const +{ + xv.x = (float)(xx * v.x + xy * v.y + xz * v.z); + xv.y = (float)(yx * v.x + yy * v.y + yz * v.z); + xv.z = (float)(zx * v.x + zy * v.y + zz * v.z); + return xv; +} + + +Vect3f& Mat3d::xform(Vect3f& v) const +{ + float ox, oy; + + ox = v.x; oy= v.y; + v.x = (float)(xx * ox + xy * oy + xz * v.z); + v.y = (float)(yx * ox + yy * oy + yz * v.z); + v.z = (float)(zx * ox + zy * oy + zz * v.z); + return v; +} + + +Vect3f& Mat3d::invXform(const Vect3f& v, Vect3f& xv) const +{ + xv.x = (float)(xx * v.x + yx * v.y + zx * v.z); + xv.y = (float)(xy * v.x + yy * v.y + zy * v.z); + xv.z = (float)(xz * v.x + yz * v.y + zz * v.z); + return xv; +} + + +Vect3f& Mat3d::invXform(Vect3f& v) const +{ + float ox, oy; + + ox = v.x; oy= v.y; + v.x = (float)(xx * ox + yx * oy + zx * v.z); + v.y = (float)(xy * ox + yy * oy + zy * v.z); + v.z = (float)(xz * ox + yz * oy + zz * v.z); + return v; +} + + + + + +/////////////////////////////////////////////////////////////////////////////// +// +// MatXf xm_inline definitions +// +/////////////////////////////////////////////////////////////////////////////// +MatXf::MatXf(const float16& T) +{ + R[0][0] = T[0]; R[1][0] = T[1]; R[2][0] = T[2]; + R[0][1] = T[4]; R[1][1] = T[5]; R[2][1] = T[6]; + R[0][2] = T[8]; R[1][2] = T[9]; R[2][2] = T[10]; + d[0] = T[12]; d[1] = T[13]; d[2] = T[14]; +} + +MatXf::operator MatXd () const +{ + return MatXd(R, d); +} + +MatXf& MatXf::set(const Se3f& T) +{ + R.set(T.rot()); + d = T.trans(); + return *this; +} + +// Vect3d transforming ///////////////////// +Vect3d& MatXf::xformVect(const Vect3d& v, Vect3d& xv) const +{ + return R.xform(v, xv); +} + + +Vect3d& MatXf::xformVect(Vect3d& v) const +{ + return R.xform(v); +} + + +Vect3d& MatXf::xformPoint(const Vect3d& p, Vect3d& xp) const +{ + R.xform(p, xp); + xp.add(d); + return xp; +} + + +Vect3d& MatXf::xformPoint(Vect3d& p) const +{ + R.xform(p); + p.add(d); + return p; +} + + +Vect3d& MatXf::invXformVect(const Vect3d& v, Vect3d& xv) const +{ + return R.invXform(v, xv); +} + + +Vect3d& MatXf::invXformVect(Vect3d& v) const +{ + return R.invXform(v); +} + + +Vect3d& MatXf::invXformPoint(const Vect3d& p, Vect3d& xp) const +{ + xp.sub(p, d); + R.invXform(xp); + return xp; +} + + +Vect3d& MatXf::invXformPoint(Vect3d& p) const +{ + p.sub(d); + R.invXform(p); + return p; +} + + +// Vect3f transforming ///////////////////// +Vect3f& MatXf::xformVect(const Vect3f& v, Vect3f& xv) const +{ + return R.xform(v, xv); +} + + +Vect3f& MatXf::xformVect(Vect3f& v) const +{ + return R.xform(v); +} + + +Vect3f& MatXf::xformPoint(const Vect3f& p, Vect3f& xp) const +{ + R.xform(p, xp); + xp.add(d); + return xp; +} + + +Vect3f& MatXf::xformPoint(Vect3f& p) const +{ + R.xform(p); + p.add(d); + return p; +} + + +Vect3f& MatXf::invXformVect(const Vect3f& v, Vect3f& xv) const +{ + return R.invXform(v, xv); +} + + +Vect3f& MatXf::invXformVect(Vect3f& v) const +{ + return R.invXform(v); +} + + +Vect3f& MatXf::invXformPoint(const Vect3f& p, Vect3f& xp) const +{ + xp.sub(p, d); + R.invXform(xp); + return xp; +} + + +Vect3f& MatXf::invXformPoint(Vect3f& p) const +{ + p.sub(d); + R.invXform(p); + return p; +} + + + + +/////////////////////////////////////////////////////////////////////////////// +// +// MatXd xm_inline definitions +// +/////////////////////////////////////////////////////////////////////////////// +MatXd::MatXd(const double16& T) +{ + R[0][0] = T[0]; R[1][0] = T[1]; R[2][0] = T[2]; + R[0][1] = T[4]; R[1][1] = T[5]; R[2][1] = T[6]; + R[0][2] = T[8]; R[1][2] = T[9]; R[2][2] = T[10]; + d[0] = T[12]; d[1] = T[13]; d[2] = T[14]; +} + +MatXd::operator MatXf () const +{ + return MatXf(R, d); +} + +MatXd& MatXd::set(const Se3d& T) +{ + R.set(T.rot()); + d = T.trans(); + return *this; +} + + +// Vect3d transforming ///////////////////// +Vect3d& MatXd::xformVect(const Vect3d& v, Vect3d& xv) const +{ + return R.xform(v, xv); +} + + +Vect3d& MatXd::xformVect(Vect3d& v) const +{ + return R.xform(v); +} + + +Vect3d& MatXd::xformPoint(const Vect3d& p, Vect3d& xp) const +{ + R.xform(p, xp); + xp.add(d); + return xp; +} + + +Vect3d& MatXd::xformPoint(Vect3d& p) const +{ + R.xform(p); + p.add(d); + return p; +} + + +Vect3d& MatXd::invXformVect(const Vect3d& v, Vect3d& xv) const +{ + return R.invXform(v, xv); +} + + +Vect3d& MatXd::invXformVect(Vect3d& v) const +{ + return R.invXform(v); +} + + +Vect3d& MatXd::invXformPoint(const Vect3d& p, Vect3d& xp) const +{ + xp.sub(p, d); + R.invXform(xp); + return xp; +} + + +Vect3d& MatXd::invXformPoint(Vect3d& p) const +{ + p.sub(d); + R.invXform(p); + return p; +} + + + + +// Vect3f transforming ///////////////////// +Vect3f& MatXd::xformVect(const Vect3f& v, Vect3f& xv) const +{ + return R.xform(v, xv); +} + + +Vect3f& MatXd::xformVect(Vect3f& v) const +{ + return R.xform(v); +} + + +Vect3f& MatXd::xformPoint(const Vect3f& p, Vect3f& xp) const +{ + R.xform(p, xp); + xp.add(d); + return xp; +} + + +Vect3f& MatXd::xformPoint(Vect3f& p) const +{ + R.xform(p); + p.add(d); + return p; +} + + +Vect3f& MatXd::invXformVect(const Vect3f& v, Vect3f& xv) const +{ + return R.invXform(v, xv); +} + + +Vect3f& MatXd::invXformVect(Vect3f& v) const +{ + return R.invXform(v); +} + + +Vect3f& MatXd::invXformPoint(const Vect3f& p, Vect3f& xp) const +{ + xp.sub(p, d); + R.invXform(xp); + return xp; +} + + +Vect3f& MatXd::invXformPoint(Vect3f& p) const +{ + p.sub(d); + R.invXform(p); + return p; +} + + + + +/////////////////////////////////////////////////////////////////////////////// +// QuatF xm_inline definitions +/////////////////////////////////////////////////////////////////////////////// +QuatF::operator QuatD () const +{ + return QuatD((float)s_,(float)x_,(float)y_,(float)z_); +} + +int QuatF::operator == (const QuatF& other) const +{ + return fabs(s_ - other.s_) < FLT_COMPARE_TOLERANCE && + fabs(x_ - other.x_) < FLT_COMPARE_TOLERANCE && + fabs(y_ - other.y_) < FLT_COMPARE_TOLERANCE && + fabs(z_ - other.z_) < FLT_COMPARE_TOLERANCE; +} + +int QuatF::operator!= (const QuatF& other) const +{ + return fabs(s_ - other.s_) > FLT_COMPARE_TOLERANCE || + fabs(x_ - other.x_) > FLT_COMPARE_TOLERANCE || + fabs(y_ - other.y_) > FLT_COMPARE_TOLERANCE || + fabs(z_ - other.z_) > FLT_COMPARE_TOLERANCE; +} + +Vect3f QuatF::axis() const +{ + Vect3f v(x_, y_, z_); + if (v.norm() == 0.0) v = Vect3f::I; // axis is arbitrary here + else v.normalize(); + return v; +} + + +float QuatF::angle() const +{ + return 2 * acosf(s_); +} + + +QuatF& QuatF::normalize(const QuatF& q) +{ + float scale; + + scale = 1.f / sqrtf(q.s_*q.s_ + q.x_*q.x_ + q.y_*q.y_ + q.z_*q.z_); + s_ = scale * q.s_; + x_ = scale * q.x_; + y_ = scale * q.y_; + z_ = scale * q.z_; + return *this; +} + +QuatF normalize(const QuatF& q) +{ + float scale; + scale = 1.f / sqrtf(q.s_*q.s_ + q.x_*q.x_ + q.y_*q.y_ + q.z_*q.z_); + return QuatF(scale * q.s_, scale * q.x_, scale * q.y_, scale * q.z_); +} + + +QuatF& QuatF::normalize() +{ + float scale; + + scale = 1.f / sqrtf(s_*s_ + x_*x_ + y_*y_ + z_*z_); + s_ *= scale; + x_ *= scale; + y_ *= scale; + z_ *= scale; + return *this; +} + + +QuatF& QuatF::invert(const QuatF& q) +{ + s_ = -q.s_; + x_ = q.x_; + y_ = q.y_; + z_ = q.z_; + return *this; +} + + +QuatF& QuatF::invert() +{ + s_ = -s_; + return *this; +} + +QuatF& QuatF::operator+= (const QuatF& q) +{ + s_ += q.s_; + x_ += q.x_; + y_ += q.y_; + z_ += q.z_; + return *this; +} +QuatF& QuatF::operator-= (const QuatF& q) +{ + s_ -= q.s_; + x_ -= q.x_; + y_ -= q.y_; + z_ -= q.z_; + return *this; +} +QuatF QuatF::operator+ (const QuatF& q) const +{ + return QuatF(s_ + q.s_,x_ + q.x_,y_ + q.y_,z_ + q.z_); +} +QuatF QuatF::operator- (const QuatF& q) const +{ + return QuatF(s_ - q.s_,x_ - q.x_,y_ - q.y_,z_ - q.z_); +} + +float QuatF::dot (const QuatF& q) const +{ + return s_*q.s_ + x_*q.x_ + y_*q.y_ + z_*q.z_; +} + + +// Scalar operations ///////////////// +QuatF& QuatF::operator*= (float w) +{ + s_ *= w; + x_ *= w; + y_ *= w; + z_ *= w; + return *this; +} +QuatF& QuatF::operator/= (float w) +{ + w = 1/w; + s_ *= w; + x_ *= w; + y_ *= w; + z_ *= w; + return *this; +} +QuatF QuatF::operator* (float w) const +{ + return QuatF(s_*w,x_*w,y_*w,z_*w); +} +QuatF QuatF::operator/ (float w) const +{ + w = 1/w; + return QuatF(s_*w,x_*w,y_*w,z_*w); +} +QuatF operator* (float w,const QuatF& q) +{ + return QuatF(q.s_*w,q.x_*w,q.y_*w,q.z_*w); +} + +xm_inline void QuatF::slerp(const QuatF& a,const QuatF& b,float t) +{ + // Slerp(q1,q2,t) = (sin((1-t)*A)/sin(A))*q1+(sin(t*A)/sin(A))*q2 + float scale0, scale1; + + // calc cosine + float cosom = a.dot(b); + + // adjust signs (if necessary) + if(cosom < 0.0){ + cosom = -cosom; + negate(b); + } + else + *this = b; + + // calculate coefficients + if ((1.0 - cosom) > 1e-5f ) { + // standard case (slerp) + float omega = acosf(cosom); + float sinom = sinf(omega); + scale0 = sinf((1.0f - t) * omega) / sinom; + scale1 = sinf(t * omega) / sinom; + } + else { // "from" and "to" quaternions are very close, so we can do a linear interpolation + scale0 = 1.0f - t; + scale1 = t; + } + + // calculate final values + *this *= scale1; + *this += a*scale0; +} + + +/////////////////////////////////////////////////////////////////////////////// +// QuatD xm_inline definitions +/////////////////////////////////////////////////////////////////////////////// +QuatD::operator QuatF () const +{ + return QuatF((float)s_,(float)x_,(float)y_,(float)z_); +} + +int QuatD::operator == (const QuatD& other) const +{ + return fabs(s_ - other.s_) < DBL_COMPARE_TOLERANCE && + fabs(x_ - other.x_) < DBL_COMPARE_TOLERANCE && + fabs(y_ - other.y_) < DBL_COMPARE_TOLERANCE && + fabs(z_ - other.z_) < DBL_COMPARE_TOLERANCE; +} + +int QuatD::operator!= (const QuatD& other) const +{ + return fabs(s_ - other.s_) > DBL_COMPARE_TOLERANCE || + fabs(x_ - other.x_) > DBL_COMPARE_TOLERANCE || + fabs(y_ - other.y_) > DBL_COMPARE_TOLERANCE || + fabs(z_ - other.z_) > DBL_COMPARE_TOLERANCE; +} + +Vect3d QuatD::axis() const +{ + Vect3d v(x_, y_, z_); + if (v.norm() == 0.0) v = Vect3d::I; // axis is arbitrary here + else v.normalize(); + return v; +} + + +double QuatD::angle() const +{ + return 2 * acos(s_); +} + + +QuatD& QuatD::normalize(const QuatD& q) +{ + double scale; + + scale = 1.0 / sqrt(q.s_*q.s_ + q.x_*q.x_ + q.y_*q.y_ + q.z_*q.z_); + s_ = scale * q.s_; + x_ = scale * q.x_; + y_ = scale * q.y_; + z_ = scale * q.z_; + return *this; +} + +QuatD normalize(const QuatD& q) +{ + double scale; + scale = 1.0 / sqrt(q.s_*q.s_ + q.x_*q.x_ + q.y_*q.y_ + q.z_*q.z_); + return QuatD(scale * q.s_, scale * q.x_, scale * q.y_, scale * q.z_); +} + + +QuatD& QuatD::normalize() +{ + double scale; + + scale = 1.0 / sqrt(s_*s_ + x_*x_ + y_*y_ + z_*z_); + s_ *= scale; + x_ *= scale; + y_ *= scale; + z_ *= scale; + return *this; +} + + +QuatD& QuatD::invert(const QuatD& q) +{ + s_ = -q.s_; + x_ = q.x_; + y_ = q.y_; + z_ = q.z_; + return *this; +} + + +QuatD& QuatD::invert() +{ + s_ = -s_; + return *this; +} + +QuatD& QuatD::operator+= (const QuatD& q) +{ + s_ += q.s_; + x_ += q.x_; + y_ += q.y_; + z_ += q.z_; + return *this; +} +QuatD& QuatD::operator-= (const QuatD& q) +{ + s_ -= q.s_; + x_ -= q.x_; + y_ -= q.y_; + z_ -= q.z_; + return *this; +} +QuatD QuatD::operator+ (const QuatD& q) const +{ + return QuatD(s_ + q.s_,x_ + q.x_,y_ + q.y_,z_ + q.z_); +} +QuatD QuatD::operator- (const QuatD& q) const +{ + return QuatD(s_ - q.s_,x_ - q.x_,y_ - q.y_,z_ - q.z_); +} + +double QuatD::dot (const QuatD& q) const +{ + return s_*q.s_ + x_*q.x_ + y_*q.y_ + z_*q.z_; +} + + +// Scalar operations ///////////////// +QuatD& QuatD::operator*= (double w) +{ + s_ *= w; + x_ *= w; + y_ *= w; + z_ *= w; + return *this; +} +QuatD& QuatD::operator/= (double w) +{ + w = 1/w; + s_ *= w; + x_ *= w; + y_ *= w; + z_ *= w; + return *this; +} +QuatD QuatD::operator* (double w) const +{ + return QuatD(s_*w,x_*w,y_*w,z_*w); +} +QuatD QuatD::operator/ (double w) const +{ + w = 1/w; + return QuatD(s_*w,x_*w,y_*w,z_*w); +} +QuatD operator* (double w,const QuatD& q) +{ + return QuatD(q.s_*w,q.x_*w,q.y_*w,q.z_*w); +} + +xm_inline void QuatD::slerp(const QuatD& a,const QuatD& b, double t) +{ + // Slerp(q1,q2,t) = (sin((1-t)*A)/sin(A))*q1+(sin(t*A)/sin(A))*q2 + double scale0, scale1; + + // calc cosine + double cosom = a.dot(b); + + // adjust signs (if necessary) + if(cosom < 0.0){ + cosom = -cosom; + negate(b); + } + else + *this = b; + + // calculate coefficients + if ((1.0 - cosom) > 1e-5f ) { + // standard case (slerp) + double omega = acos(cosom); + double sinom = sin(omega); + scale0 = sin((1.0 - t) * omega) / sinom; + scale1 = sin(t * omega) / sinom; + } + else { // "from" and "to" quaternions are very close, so we can do a linear interpolation + scale0 = 1.0 - t; + scale1 = t; + } + + // calculate final values + *this *= scale1; + *this += a*scale0; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// Se3f xm_inline definitions +/////////////////////////////////////////////////////////////////////////////// +Se3f::operator Se3d () const +{ + return Se3d(q, d); +} + +Se3f& Se3f::mult(const Se3f& T, const Se3f& U) +{ + q.mult(T.q, U.q); + T.q.xform(U.d, d); + d.add(d, T.d); + return *this; +} + + +Se3f& Se3f::premult(const Se3f& T) +{ + q.premult(T.q); + T.q.xform(d); + d.add(T.d); + return *this; +} + + +Se3f& Se3f::postmult(const Se3f& T) +{ + Vect3f v; + + q.xform(T.d, v); + d.add(v); + q.postmult(T.q); + return *this; +} + + +Se3f& Se3f::invert(const Se3f& T) +{ + q.s_ = -T.q.s_; + q.x_ = T.q.x_; + q.y_ = T.q.y_; + q.z_ = T.q.z_; + q.xform(T.d, d); + d.negate(d); + return *this; +} + + +Se3f& Se3f::invert() +{ + q.s_ = -q.s_; + q.xform(d); + d.negate(); + return *this; +} + + +Vect3f& Se3f::xformVect(const Vect3f& v, Vect3f& xv) const +{ + q.xform(v, xv); + return xv; +} + + +Vect3f& Se3f::xformVect(Vect3f& v) const +{ + q.xform(v); + return v; +} + + +Vect3f& Se3f::xformPoint(const Vect3f& p, Vect3f& xp) const +{ + q.xform(p, xp); + xp.add(d); + return xp; +} + + +Vect3f& Se3f::xformPoint(Vect3f& p) const +{ + q.xform(p); + p.add(d); + return p; +} + + +Vect3f& Se3f::invXformVect(const Vect3f& v, Vect3f& xv) const +{ + q.invXform(v, xv); + return xv; +} + + +Vect3f& Se3f::invXformVect(Vect3f& v) const +{ + q.invXform(v); + return v; +} + + +Vect3f& Se3f::invXformPoint(const Vect3f& p, Vect3f& xp) const +{ + xp.sub(p, d); + q.invXform(xp); + return xp; +} + + +Vect3f& Se3f::invXformPoint(Vect3f& p) const +{ + p.sub(d); + q.invXform(p); + return p; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// Se3d xm_inline definitions +/////////////////////////////////////////////////////////////////////////////// +Se3d::operator Se3f () const +{ + return Se3f(q, d); +} + +Se3d& Se3d::mult(const Se3d& T, const Se3d& U) +{ + q.mult(T.q, U.q); + T.q.xform(U.d, d); + d.add(d, T.d); + return *this; +} + + +Se3d& Se3d::premult(const Se3d& T) +{ + q.premult(T.q); + T.q.xform(d); + d.add(T.d); + return *this; +} + + +Se3d& Se3d::postmult(const Se3d& T) +{ + Vect3d v; + + q.xform(T.d, v); + d.add(v); + q.postmult(T.q); + return *this; +} + + +Se3d& Se3d::invert(const Se3d& T) +{ + q.s_ = -T.q.s_; + q.x_ = T.q.x_; + q.y_ = T.q.y_; + q.z_ = T.q.z_; + q.xform(T.d, d); + d.negate(d); + return *this; +} + + +Se3d& Se3d::invert() +{ + q.s_ = -q.s_; + q.xform(d); + d.negate(); + return *this; +} + + +Vect3d& Se3d::xformVect(const Vect3d& v, Vect3d& xv) const +{ + q.xform(v, xv); + return xv; +} + + +Vect3d& Se3d::xformVect(Vect3d& v) const +{ + q.xform(v); + return v; +} + + +Vect3d& Se3d::xformPoint(const Vect3d& p, Vect3d& xp) const +{ + q.xform(p, xp); + xp.add(d); + return xp; +} + + +Vect3d& Se3d::xformPoint(Vect3d& p) const +{ + q.xform(p); + p.add(d); + return p; +} + + +Vect3d& Se3d::invXformVect(const Vect3d& v, Vect3d& xv) const +{ + q.invXform(v, xv); + return xv; +} + + +Vect3d& Se3d::invXformVect(Vect3d& v) const +{ + q.invXform(v); + return v; +} + + +Vect3d& Se3d::invXformPoint(const Vect3d& p, Vect3d& xp) const +{ + xp.sub(p, d); + q.invXform(xp); + return xp; +} + + +Vect3d& Se3d::invXformPoint(Vect3d& p) const +{ + p.sub(d); + q.invXform(p); + return p; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// Vect4f xm_inline definitions +// +/////////////////////////////////////////////////////////////////////////////// + +int Vect4f::operator== (const Vect4f& other) const +{ + return fabs(x - other.x) < FLT_COMPARE_TOLERANCE && + fabs(y - other.y) < FLT_COMPARE_TOLERANCE && + fabs(z - other.z) < FLT_COMPARE_TOLERANCE && + fabs(w - other.w) < FLT_COMPARE_TOLERANCE; +} + +int Vect4f::operator!= (const Vect4f& v) const +{ + return fabs(x - v.x) > FLT_COMPARE_TOLERANCE || + fabs(y - v.y) > FLT_COMPARE_TOLERANCE || + fabs(z - v.z) > FLT_COMPARE_TOLERANCE || + fabs(w - v.w) > FLT_COMPARE_TOLERANCE; +} + +void Vect4f::swap(Vect4f& other) +{ + Vect4f tmp; + + tmp = *this; + *this = other; + other = tmp; +} + +Vect4f& Vect4f::project() +{ + w = 1/w; + x *= w; + y *= w; + z *= w; + return *this; +} + +Vect4f& Vect4f::project(const Vect4f& v) +{ + w = 1/v.w; + x = x*w; + y = y*w; + z = z*w; + return *this; +} + + +Vect4f& Vect4f::add(const Vect4f& u, const Vect4f& v) +{ + x = u.x + v.x; + y = u.y + v.y; + z = u.z + v.z; + w = u.w + v.w; + return *this; +} + + +Vect4f& Vect4f::add(const Vect4f& v) +{ + x += v.x; + y += v.y; + z += v.z; + w += v.w; + return *this; +} + + +Vect4f& Vect4f::sub(const Vect4f& u, const Vect4f& v) +{ + x = u.x - v.x; + y = u.y - v.y; + z = u.z - v.z; + w = u.w - v.w; + return *this; +} + + +Vect4f& Vect4f::sub(const Vect4f& v) +{ + x -= v.x; + y -= v.y; + z -= v.z; + w -= v.w; + return *this; +} + + +Vect4f& Vect4f::mult(const Vect4f& u, const Vect4f& v) +{ + x = u.x * v.x; + y = u.y * v.y; + z = u.z * v.z; + w = u.w * v.w; + return *this; +} + + +Vect4f& Vect4f::mult(const Vect4f& v) +{ + x *= v.x; + y *= v.y; + z *= v.z; + w *= v.w; + return *this; +} + +Vect4f& Vect4f::div(const Vect4f& u, const Vect4f& v) +{ + x = u.x / v.x; + y = u.y / v.y; + z = u.z / v.z; + w = u.w / v.w; + return *this; +} + + +Vect4f& Vect4f::div(const Vect4f& v) +{ + x /= v.x; + y /= v.y; + z /= v.z; + w /= v.w; + return *this; +} + + + +Vect4f& Vect4f::scale(const Vect4f& v, float s) +{ + x = s * v.x; + y = s * v.y; + z = s * v.z; + w = s * v.w; + return *this; +} + + +Vect4f& Vect4f::scale(float s) +{ + x *= s; + y *= s; + z *= s; + w *= s; + return *this; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// Mat4f xm_inline definitions +// +/////////////////////////////////////////////////////////////////////////////// + +Mat4f::Mat4f(float xx_,float xy_,float xz_,float xw_, + float yx_,float yy_,float yz_,float yw_, + float zx_,float zy_,float zz_,float zw_, + float wx_,float wy_,float wz_,float ww_) +{ + xx = xx_; xy = xy_; xz = xz_; xw = xw_; + yx = yx_; yy = yy_; yz = yz_; yw = yw_; + zx = zx_; zy = zy_; zz = zz_; zw = zw_; + wx = wx_; wy = wy_; wz = wz_; ww = ww_; +} + +Mat4f& Mat4f::set(const Mat3f& rot) +{ + xx = rot.xx; xy = rot.xy; xz = rot.xz; xw = 0; + yx = rot.yx; yy = rot.yy; yz = rot.yz; yw = 0; + zx = rot.zx; zy = rot.zy; zz = rot.zz; zw = 0; + wx = 0; wy = 0; wz = 0; ww = 1.0f; + return *this; +} + +Mat4f& Mat4f::set(const Mat3f& rot, const Vect3f& trans) +{ + xx = rot.xx; xy = rot.xy; xz = rot.xz; xw = trans.x; + yx = rot.yx; yy = rot.yy; yz = rot.yz; yw = trans.y; + zx = rot.zx; zy = rot.zy; zz = rot.zz; zw = trans.z; + wx = 0; wy = 0; wz = 0; ww = 1.0f; + return *this; +} + +Mat4f& Mat4f::set(const MatXf& X) +{ + const Mat3f& rot = X.rot(); + const Vect3f& trans = X.trans(); + xx = rot.xx; xy = rot.xy; xz = rot.xz; xw = trans.x; + yx = rot.yx; yy = rot.yy; yz = rot.yz; yw = trans.y; + zx = rot.zx; zy = rot.zy; zz = rot.zz; zw = trans.z; + wx = 0; wy = 0; wz = 0; ww = 1.0f; + return *this; +} + +Mat4f& Mat4f::setXcol(const Vect4f& v) +{ + xx = v.x; + yx = v.y; + zx = v.z; + wx = v.w; + return *this; +} + + +Mat4f& Mat4f::setYcol(const Vect4f& v) +{ + xy = v.x; + yy = v.y; + zy = v.z; + wy = v.w; + return *this; +} + + +Mat4f& Mat4f::setZcol(const Vect4f& v) +{ + xz = v.x; + yz = v.y; + zz = v.z; + wz = v.w; + return *this; +} + +Mat4f& Mat4f::setWcol(const Vect4f& v) +{ + xw = v.x; + yw = v.y; + zw = v.z; + ww = v.w; + return *this; +} + + +// Vect4f transforming ///////////////////// +Vect4f& Mat4f::xform(const Vect4f& v, Vect4f& xv) const +{ + xv.x = xx * v.x + xy * v.y + xz * v.z + xw * v.w; + xv.y = yx * v.x + yy * v.y + yz * v.z + yw * v.w; + xv.z = zx * v.x + zy * v.y + zz * v.z + zw * v.w; + xv.w = wx * v.x + wy * v.y + wz * v.z + ww * v.w; + return xv; +} + + +Vect4f& Mat4f::xform(Vect4f& v) const +{ + Vect4f v0 = v; + return xform(v0, v); +} + +Vect4f& Mat4f::xform(const Vect3f& v, Vect4f& xv) const +{ + xv.x = xx * v.x + xy * v.y + xz * v.z + xw; + xv.y = yx * v.x + yy * v.y + yz * v.z + yw; + xv.z = zx * v.x + zy * v.y + zz * v.z + zw; + xv.w = wx * v.x + wy * v.y + wz * v.z + ww; + return xv; +} + +Mat4f& Mat4f::xpose(const Mat4f& M) +{ + xx = M.xx; + xy = M.yx; + xz = M.zx; + xw = M.wx; + + yx = M.xy; + yy = M.yy; + yz = M.zy; + yw = M.wy; + + zx = M.xz; + zy = M.yz; + zz = M.zz; + zw = M.wz; + + wx = M.xw; + wy = M.yw; + wz = M.zw; + ww = M.ww; + + return *this; +} + + +Mat4f& Mat4f::xpose() +{ + #define __swap__(x,y) { float t = y; y = x; x = t; } + __swap__(xy, yx); + __swap__(yz, zy); + __swap__(zx, xz); + __swap__(xw, wx); + __swap__(yw, wy); + __swap__(zw, wz); + #undef __swap__ + return *this; +} + + +////////////////////////////////////////////////////////////////////////////////// +// +// Stream's I/O operations +// +////////////////////////////////////////////////////////////////////////////////// +#ifndef _XMATH_NO_IOSTREAM + +// Vect2s I/O ////////////////////////// +inline ostream& operator<<(ostream &os, const Vect2i& v) +{ + os << v.x << " " << v.y; + return os; +} + +inline istream& operator>>(istream &is, Vect2i& v) +{ + is >> v.x >> v.y; + return is; +} + +// Vect2s I/O ////////////////////////// +inline ostream& operator<<(ostream &os, const Vect2f& v) +{ + os << v.x << " " << v.y; + return os; +} + +inline istream& operator>>(istream &is, Vect2f& v) +{ + is >> v.x >> v.y; + return is; +} + + +// Vect2s I/O ////////////////////////// +inline ostream& operator<<(ostream &os, const Vect2s& v) +{ + os << v.x << " " << v.y; + return os; +} + +inline istream& operator>>(istream &is, Vect2s& v) +{ + is >> v.x >> v.y; + return is; +} + + +// Vect3d I/O ////////////////////////// +inline ostream& operator<<(ostream &os, const Vect3d& v) +{ + os << v.x << " " << v.y << " " << v.z; + return os; +} + +inline istream& operator>>(istream &is, Vect3d& v) +{ + is >> v.x >> v.y >> v.z; + return is; +} + + +// Vect3f I/O ////////////////////////// +inline ostream& operator<<(ostream &os, Vect3f& v) +{ + os << v.x << " " << v.y << " " << v.z; + return os; +} + +inline istream& operator>>(istream &is, Vect3f& v) +{ + is >> v.x >> v.y >> v.z; + return is; +} + +// Vect4f I/O ////////////////////////// +inline ostream& operator<<(ostream &os, const Vect4f& v) +{ + os << v.x << " " << v.y << " " << v.z << " " << v.w; + return os; +} + +inline istream& operator>>(istream &is, Vect4f& v) +{ + is >> v.x >> v.y >> v.z >> v.w; + return is; +} + + +// Mat3d I/O //////////////////////// +inline ostream& operator<<(ostream& os, const Mat3d& m) +{ + os << m.xx << " \t" << m.xy << " \t" << m.xz << endl; + os << m.yx << " \t" << m.yy << " \t" << m.yz << endl; + os << m.zx << " \t" << m.zy << " \t" << m.zz; + return os; +} + +inline istream& operator>>(istream &is, Mat3d& m) +{ + is >> m.xx >> m.xy >> m.xz; + is >> m.yx >> m.yy >> m.yz; + is >> m.zx >> m.zy >> m.zz; + return is; +} + +// Mat3f I/O //////////////////////// +inline ostream& operator<<(ostream& os, const Mat3f& m) +{ + os << m.xx << " \t" << m.xy << " \t" << m.xz << endl; + os << m.yx << " \t" << m.yy << " \t" << m.yz << endl; + os << m.zx << " \t" << m.zy << " \t" << m.zz; + return os; +} + +inline istream& operator>>(istream &is, Mat3f& m) +{ + is >> m.xx >> m.xy >> m.xz; + is >> m.yx >> m.yy >> m.yz; + is >> m.zx >> m.zy >> m.zz; + return is; +} + + +// MatXd I/O /////////////////// +inline ostream& operator<<(ostream& os, const MatXd& m) +{ + return os << m.R << " " << m.d; +} + +inline istream& operator>>(istream& is, MatXd& m) +{ + Se3d T; + is >> T; + m.set(T); + return is; +} + + +// MatXf I/O /////////////////// +inline ostream& operator<<(ostream& os, const MatXf& m) +{ + return os << m.R << " " << m.d; +} + +inline istream& operator>>(istream& is, MatXf& m) +{ + Se3d T; + is >> T; + m.set(T); + return is; +} + + +// QuatD I/O /////////////////// +inline istream& operator>>(istream& is, QuatD& q) +{ + is >> q.s_ >> q.x_ >> q.y_ >> q.z_; + return is; +} + +inline ostream& operator<<(ostream& os, const QuatD& q) +{ + os << q.s_ << " " << q.x_ << " " << q.y_ << " " << q.z_; + return os; +} + +// QuatF I/O /////////////////// +inline istream& operator>>(istream& is, QuatF& q) +{ + is >> q.s_ >> q.x_ >> q.y_ >> q.z_; + return is; +} + +inline ostream& operator<<(ostream& os, const QuatF& q) +{ + os << q.s_ << " " << q.x_ << " " << q.y_ << " " << q.z_; + return os; +} + + +// Se3d I/O /////////////////// +inline ostream& operator<<(ostream& os, const Se3d& se3) +{ + return os << se3.q << " " << se3.d; +} + +inline istream& operator>>(istream& is, Se3d& se3) +{ + return is >> se3.q >> se3.d; +} + +// Se3f I/O /////////////////// +inline ostream& operator<<(ostream& os, const Se3f& se3) +{ + return os << se3.q << " " << se3.d; +} + +inline istream& operator>>(istream& is, Se3f& se3) +{ + return is >> se3.q >> se3.d; +} + + +#endif // _XMATH_NO_IOSTREAM + +#endif // __XMATH_H__ diff --git a/MechoSoma/XTool/xrecorder.cpp b/MechoSoma/XTool/xrecorder.cpp new file mode 100644 index 00000000..f22fcc43 --- /dev/null +++ b/MechoSoma/XTool/xrecorder.cpp @@ -0,0 +1,27 @@ +#include "xtool.h" + +XRecorder XRec; + +XRecorder::XRecorder(void) +{ +} + +void XRecorder::Quant(void) +{ +} + +void XRecorder::Open(char* fname,int mode) +{ +} + +void XRecorder::Close(void) +{ +} + +void XRecorder::PutMessage(int msg,int sz,void* p) +{ +} + +void XRecorder::GetMessage(void) +{ +} diff --git a/MechoSoma/XTool/xsound.cpp b/MechoSoma/XTool/xsound.cpp new file mode 100644 index 00000000..ff74bb09 --- /dev/null +++ b/MechoSoma/XTool/xsound.cpp @@ -0,0 +1,100 @@ +#include "xsound.h" + +int SoundInit(int maxHZ, int digMode, int channels) +{ + return 0; +} + +void SoundPlay(void *lpDSB, int channel, int priority, int cropos, int flags) +{ +} + +void SoundRelease(void *lpDSB) +{ +} + +void SoundStop(int channel) +{ +} + +void* GetSound(int channel) +{ +} + +void SoundLoad(char *filename, void **lpDSB) +{ +} + +void SoundFinit(void) +{ +} + +void SoundVolume(int channel, int volume) +{ +} + +void SetVolume(void *lpDSB, int volume) +{ +} + +int GetVolume(void *lpDSB) +{ + return 0; +} + +int GetSoundVolume(int channel) +{ + return 0; +} + +void GlobalVolume(int volume) +{ +} + +void SoundPan(int channel, int panning) +{ +} + +int SoundStatus(int channel) +{ + return 0; +} + +int SoundStatus(void* lpDSB) +{ + return 0; +} + +int ChannelStatus(int channel) +{ + return 0; +} + +int GetSoundFrequency(void *lpDSB) +{ + return 0; +} + +void SetSoundFrequency(void *lpDSB,int frq) +{ +} + +void SoundStreamOpen(char *filename, void **strptr) +{ +} + +void SoundStreamClose(void *stream) +{ +} + +void SoundStreamRelease(void *stream) +{ +} + +void xsInitCD(void) +{ +} + +void xsMixerOpen(void) +{ +} diff --git a/MechoSoma/XTool/xsound.h b/MechoSoma/XTool/xsound.h new file mode 100644 index 00000000..c4ceb60a --- /dev/null +++ b/MechoSoma/XTool/xsound.h @@ -0,0 +1,95 @@ +#ifndef __X_SOUND_H +#define __X_SOUND_H + +#define DS_LOOPING 0x00000001 +#define DS_QUEUE 0x00000100 +#define DS_STREAM 0x00000200 + +#define AVI_LOOPING DS_LOOPING +#define AVI_DRAW 0x00100000 +#define AVI_END 0x00200000 +#define AVI_NOTIMER 0x00400000 +#define AVI_NODRAW 0x00800000 +#define AVI_INTERPOLATE 0x01000000 +#define AVI_NOPALETTE 0x02000000 + +#define DIG_F_MONO_8 0 +#define DIG_F_MONO_16 1 +#define DIG_F_STEREO_8 2 +#define DIG_F_STEREO_16 3 + +#define PLAYBACK_TIMER_PERIOD 200 +#define PLAYBACK_OVERSAMPLE 4 +#define PLAYBACK_TIMER_ACCURACY 10 +#define NUM_BUFFER_SEGMENTS 4 + +void* GetDS_Ptr(void); + +int SoundInit(int maxHZ, int digMode, int channels); +void SoundPlay(void *lpDSB, int channel, int priority, int cropos, int flags); +void SoundRelease(void *lpDSB); +void SoundStop(int channel); +void* GetSound(int channel); +void SoundLoad(char *filename, void **lpDSB); +void SoundFinit(void); +void SoundVolume(int channel, int volume); +void SetVolume(void *lpDSB, int volume); +int GetVolume(void *lpDSB); +int GetSoundVolume(int channel); +void GlobalVolume(int volume); +void SoundPan(int channel, int panning); + +int SoundStatus(int channel); +int SoundStatus(void* lpDSB); +int ChannelStatus(int channel); + +int GetSoundFrequency(void *lpDSB); +void SetSoundFrequency(void *lpDSB,int frq); + +void SoundStreamOpen(char *filename, void **strptr); +void SoundStreamClose(void *stream); +void SoundStreamRelease(void *stream); + +#define SoundStreamPlay(lpDSB, channel, priority, cropos, flags) SoundPlay(lpDSB, channel, priority, cropos, flags | DS_STREAM) + +int AVIopen(char *filename, int flags, int channel, void **avi); +void AVIplay(void *avi,int x, int y); +void AVIstop(void *avi); +void AVIclose(void *avi); +int AVIwidth(void *avi); +int AVIheight(void *avi); +int AVIredraw(void *avi); +void AVIredraw(void *avi, int state); +void AVIdraw(void *avi); +void AVIGetData(void *avi, void *data); +void *AVIGetPalette(void *avi); + +/* --------------------- CD Management --------------------- */ + +// xsGetStatusCD() return values... +#define XCD_NOT_READY 0x00 +#define XCD_PAUSED 0x01 +#define XCD_PLAYING 0x02 +#define XCD_STOPPED 0x03 +#define XCD_OTHER 0x04 + +void xsInitCD(void); +void xsPlayCD(int track,int min = 0,int sec = 0); +void xsPlayOneTrackCD(int track,int min = 0,int sec = 0); +void xsStopCD(void); +void xsPauseCD(void); +void xsResumeCD(void); +int xsGetStatusCD(void); +int xsGetCurTrackCD(void); +int xsGetNumTracksCD(void); +int xsGetTrackLenCD(int track); + +/* ------------------- Volume Management ------------------- */ + +void xsMixerOpen(void); +int xsGetVolumeCD(void); +void xsSetVolumeCD(int val); +int xsGetVolumeWAVE(void); +void xsSetVolumeWAVE(int val); + +#endif diff --git a/MechoSoma/XTool/xstream.cpp b/MechoSoma/XTool/xstream.cpp new file mode 100644 index 00000000..a4ef7d33 --- /dev/null +++ b/MechoSoma/XTool/xstream.cpp @@ -0,0 +1,720 @@ +#include "xtool.h" + +#include +#include +#include + +#include +#include + +#include "filesystem.h" +#include "port.h" + +static const char *openMSG = "CREATE/OPEN FAILURE"; +static const char *sizeMSG = "FILE SIZE CALCULATION ERROR"; + +unsigned xsReadBytes = 0; +unsigned xsReadBytesDelta = 0; +unsigned xsWriteBytes = 0; +unsigned xsWriteBytesDelta = 0; + +unsigned xsRdWrResolution = 500000U; + +void (*xsReadHandler)(unsigned) = NULL; +void (*xsWriteHandler)(unsigned) = NULL; + +void xsSetReadHandler(void (*fp)(unsigned),unsigned res) +{ + xsReadHandler = fp; + xsRdWrResolution = res; + xsReadBytes = 0; +} + +void xsSetWriteHandler(void (*fp)(unsigned),unsigned res) +{ + xsWriteHandler = fp; + xsRdWrResolution = res; + xsWriteBytes = 0; +} + +std::fstream *open_file(const char* name, unsigned f) +{ + std::ios::openmode mode; + mode = std::ios::binary; + if (f & XS_IN) + mode |= std::ios::in; + if (f & XS_OUT) + mode |= std::ios::out; + if (f & XS_APPEND) + mode |= std::ios::app; + + return new std::fstream(name, mode); +} + +XStream::XStream(int err) +{ + ErrHUsed = err; + handler = NULL; + eofFlag = 1; + radix = XS_DEFRADIX; + digits = XS_DEFDIGITS; + extSize = -1; + extPos = 0; +} + +XStream::XStream(const char* name, unsigned flags,int err) +{ + ErrHUsed = err; + handler = NULL; // (XSHANDLE)-1; + eofFlag = 1; + radix = XS_DEFRADIX; + digits = XS_DEFDIGITS; + extSize = -1; + extPos = 0; + open(name,flags); +} + +XStream::~XStream() +{ + close(); +} + +int XStream::open(const char* name, unsigned f) +{ +#ifdef XSTREAM_DEBUG + std::cerr << "DBG: XStream::open(\"" << name << "\", 0x" << std::hex << f << ")" << std::endl; +#endif + + const auto file_path = file::normalize_path(name); + + std::fstream *file = open_file(file_path.c_str(), f); + handler = file; + if (file->is_open()) { + fname = name; + pos = file->tellg(); + eofFlag = 0; + } else { + #ifdef XSTREAM_DEBUG + std::cerr << "ERR: XStream::open(\"" << name << "\", 0x" << std::hex << f << ")" << std::endl; + #endif + if(ErrHUsed) + ErrH.Abort(openMSG,XERR_USER,0,""); + else + return 0; + } + return 1; +} + +int XStream::open(XStream* owner,long s,long ext_sz) +{ + /* Full stream debug + std::fstream debug("openfile.txt", std::ios::out|std::ios::app); + if (debug.is_open()) + debug<<"OPEN_XSTREAM "< fname< fname; + handler = owner -> handler; + pos = 0; + owner -> seek(s,XS_BEG); + eofFlag = owner -> eof(); + extSize = ext_sz; + extPos = s; + return 1; +} + +void XStream::close(void) +{ + + if(handler == NULL) + return; + //std::cout<<"XStream::close: "<(handler); + + if (internal_handler->is_open()) + internal_handler->close(); + delete internal_handler; + } + + handler = NULL; + //fname = ""; + pos = 0L; + eofFlag = 1; + extSize = -1; + extPos = 0; +} + +unsigned long XStream::read(void* buf, unsigned long len) +{ + unsigned long ret; + auto internal_handler = reinterpret_cast(handler); + /*if(!ReadFile(handler,buf,len,&ret,0)) + if(ErrHUsed) ErrH.Abort(readMSG,XERR_USER,GetLastError(),fname); + else return 0U; + if(ret < len) eofFlag = 1;*/ + internal_handler->read((char *)buf, len); + len = internal_handler->gcount(); + ret = len; + pos += ret; + if(extSize != -1 && pos >= extSize) eofFlag = 1; + + if(xsReadHandler){ + xsReadBytesDelta += ret; + if(xsReadBytesDelta >= xsRdWrResolution){ + xsReadBytes += xsReadBytesDelta; + xsReadBytesDelta = 0; + (*xsReadHandler)(xsReadBytes); + } + } + + // Full stream debug + /*std::fstream debug("openfile.txt", std::ios::out|std::ios::app); + if (debug.is_open()) + debug<<"READ "<(handler); + /*std::cout<<"Start write to:"<fail() + <<" "<<((std::fstream *)handler)->good() + <<" "<<((std::fstream *)handler)->eof() + <<" "<<((std::fstream *)handler)->bad() + <<" open:"<<((std::fstream *)handler)->is_open() + <<" tellp:"<<((std::fstream *)handler)->tellp()<write((char *)buf, len); + /* + std::cout<<"END write to:"<fail() + <<" "<<((std::fstream *)handler)->good() + <<" "<<((std::fstream *)handler)->eof() + <<" "<<((std::fstream *)handler)->bad() + <<" tellp:"<<((std::fstream *)handler)->tellp()<= xsRdWrResolution){ + xsWriteBytes += xsWriteBytesDelta; + xsWriteBytesDelta = 0; + (*xsWriteHandler)(xsWriteBytes); + } + } + return ret; +} + +long XStream::seek(long offset, int dir) +{ + /* Full stream debug*/ + /*std::fstream debug("openfile.txt", std::ios::out|std::ios::app); + if (debug.is_open()) + debug<<"SEEK START "<tellg() + <<" addr:"<(handler); + long ret=0; + if(extSize != -1){ + switch(dir){ + case XS_BEG: + //ret = SetFilePointer(handler,extPos + offset,0,dir) - extPos; + if (internal_handler->flags() & std::ios::out) { + internal_handler->seekp(extPos + offset, std::ios_base::beg); + } + else { + internal_handler->seekg(extPos + offset, std::ios_base::beg); + } + break; + case XS_END: + //ret = SetFilePointer(handler,extPos + extSize - offset - 1,0,XS_BEG) - extPos; + if (internal_handler->flags() & std::ios::out) { + internal_handler->seekp(extPos + extSize - offset - 1, std::ios_base::beg); + } else { + internal_handler->seekg(extPos + extSize - offset - 1, std::ios_base::beg); + } + break; + case XS_CUR: + //ret = SetFilePointer(handler,extPos + pos + offset,0,XS_BEG) - extPos; + //((std::fstream *)handler)->clear(); + if (internal_handler->flags() & std::ios::out) { + internal_handler->seekp(extPos + pos + offset, std::ios_base::beg); + } else { + internal_handler->seekg(extPos + pos + offset, std::ios_base::beg); + } + break; + } + + if (internal_handler->flags() & std::ios::out) + ret = internal_handler->tellp() - (std::streamoff)extPos; + else + ret = internal_handler->tellg() - (std::streamoff)extPos; + } + else + { + //ret = SetFilePointer(handler,offset,0,dir); + //std::cout<<"SEEK:"<flags() & std::ios::out) + internal_handler->seekp(offset, std::ios_base::beg); + else + internal_handler->seekg(offset, std::ios_base::beg); + break; + case XS_END: + if (internal_handler->flags() & std::ios::out) + internal_handler->seekp(offset, std::ios_base::end); + else + internal_handler->seekg(offset, std::ios_base::end); + break; + case XS_CUR: + if (internal_handler->flags() & std::ios::out) + internal_handler->seekp(offset, std::ios_base::cur); + else + internal_handler->seekg(offset, std::ios_base::cur); + break; + } + if (internal_handler->flags() & std::ios::out) + ret = internal_handler->tellp(); + else + ret = internal_handler->tellg(); + + } + /* Full stream debug*/ + /*debug.open("openfile.txt", std::ios::out|std::ios::app); + if (debug.is_open()) + debug<<"SEEK "<fail()) { + std::cout<<"Warning: Bad seek in file."<= size() - 1) eofFlag = 1; else eofFlag = 0; + + return pos = ret; +} + +long XStream::size() +{ +//std::cout<<"XStream::size()"<(handler); + long tmp = extSize; + long int tmp2; + if(tmp == -1){ + //tmp=GetFileSize(handler,0); + if (internal_handler->flags() & std::ios::in) { + tmp2 = internal_handler->tellg(); + internal_handler->seekp(0, std::ios_base::end); + tmp = internal_handler->tellg(); + internal_handler->seekp(tmp2); + } else { + tmp2 = internal_handler->tellp(); + internal_handler->seekg(0, std::ios_base::end); + tmp = internal_handler->tellp(); + internal_handler->seekg(tmp2); + } + if (tmp == -1L) { + if (ErrHUsed) + ErrH.Abort(sizeMSG,XERR_USER,0,""); + else + return -1; + } + } + /* Full stream debug + std::fstream debug("openfile.txt", std::ios::out|std::ios::app); + if (debug.is_open()) + debug<<"SIZE "< (char* v) +{ + read(v,(unsigned)strlen(v)); + return *this; +} + +XStream& XStream::operator> (char& v) +{ + read(&v,(unsigned)sizeof(char)); + return *this; +} + +XStream& XStream::operator> (unsigned char& v) +{ + read(&v,(unsigned)sizeof(char)); + return *this; +} + +XStream& XStream::operator> (short& v) +{ + read(&v,(unsigned)sizeof(int16_t)); + return *this; +} + +XStream& XStream::operator> (unsigned short& v) +{ + read(&v,(unsigned)sizeof(uint16_t)); + return *this; +} + +XStream& XStream::operator> (int& v) +{ + read(&v,(unsigned)sizeof(int)); + return *this; +} + +XStream& XStream::operator> (unsigned& v) +{ + read(&v,(unsigned)sizeof(unsigned)); + return *this; +} + +XStream& XStream::operator> (long& v) +{ + read(&v,(unsigned)sizeof(int32_t)); + return *this; +} + +XStream& XStream::operator> (unsigned long& v) +{ + read(&v,(unsigned)sizeof(uint32_t)); + return *this; +} + +XStream& XStream::operator> (double& v) +{ + read(&v,(unsigned)sizeof(double)); + return *this; +} + +XStream& XStream::operator> (float& v) +{ + read(&v,(unsigned)sizeof(float)); + return *this; +} + +XStream& XStream::operator> (long double& v) +{ + read(&v,(unsigned)sizeof(long double)); + return *this; +} + +XStream& XStream::operator<= (char var) +{ + char* s = port_itoa(var,_ConvertBuffer,radix); + write(s,strlen(s)); + return *this; +} + +XStream& XStream::operator<= (unsigned char var) +{ + char* s = port_itoa(var,_ConvertBuffer,radix); + write(s,strlen(s)); + return *this; +} + +XStream& XStream::operator<= (short var) +{ + char* s = port_itoa(var,_ConvertBuffer,radix); + write(s,strlen(s)); + return *this; +} + +XStream& XStream::operator<= (unsigned short var) +{ + char* s = port_ltoa(var,_ConvertBuffer,radix); + write(s,strlen(s)); + return *this; +} + +XStream& XStream::operator<= (int var) +{ + char* s = port_itoa(var,_ConvertBuffer,radix); + write(s,strlen(s)); + return *this; +} + +XStream& XStream::operator<= (unsigned var) +{ + char* s = port_ultoa(var,_ConvertBuffer,radix); + write(s,strlen(s)); + return *this; +} + +XStream& XStream::operator<= (long var) +{ + char* s = port_ltoa(var,_ConvertBuffer,radix); + write(s,strlen(s)); + return *this; +} + +XStream& XStream::operator<= (unsigned long var) +{ + char* s = port_ultoa(var,_ConvertBuffer,radix); + write(s,strlen(s)); + return *this; +} + +XStream& XStream::operator<= (float var) +{ + int len = snprintf(_ConvertBuffer, _CONV_BUFFER_LEN, "%.*g", digits, var); + write(_ConvertBuffer,len); + return *this; +} + +XStream& XStream::operator<= (double var) +{ + int len = snprintf(_ConvertBuffer, _CONV_BUFFER_LEN, "%.*g", digits, var); + write(_ConvertBuffer,len); + return *this; +} + +XStream& XStream::operator<= (long double var) +{ + int len = snprintf(_ConvertBuffer, _CONV_BUFFER_LEN, "%.*Lg", digits, var); + write(_ConvertBuffer,len); + return *this; +} + +XStream& XStream::operator>= (char& var) +{ + int ret = read(_ConvertBuffer,4); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = (char)strtol(p,&p,0); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (unsigned char& var) +{ + int ret = read(_ConvertBuffer,4); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = (unsigned char)strtoul(p,&p,0); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (short& var) +{ + int ret = read(_ConvertBuffer,6); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = (short)strtol(p,&p,0); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (unsigned short& var) +{ + int ret = read(_ConvertBuffer,6); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = (unsigned short)strtoul(p,&p,0); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (int& var) +{ + int ret = read(_ConvertBuffer,16); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = strtol(p,&p,0); + //std::cout<<"seek - p:"<<(long long)p<<" _ConvertBuffer:"<<(long)_ConvertBuffer<<" ret:"<= (unsigned& var) +{ + int ret = read(_ConvertBuffer,16); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = strtoul(p,&p,0); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (long& var) +{ + int ret = read(_ConvertBuffer,16); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = strtol(p,&p,0); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (unsigned long& var) +{ + int ret = read(_ConvertBuffer,16); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = strtoul(p,&p,0); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (double& var) +{ + int ret = read(_ConvertBuffer,_CONV_BUFFER_LEN); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = strtod(p,&p); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (float& var) +{ + int ret = read(_ConvertBuffer,_CONV_BUFFER_LEN); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = (float)strtod(p,&p); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +XStream& XStream::operator>= (long double& var) +{ + int ret = read(_ConvertBuffer,_CONV_BUFFER_LEN); + if(!ret) return *this; + char* p = _ConvertBuffer; + p[ret] = ' '; + var = strtod(p,&p); + seek(p - _ConvertBuffer + 1 - ret,XS_CUR); + return *this; +} + +char* XStream::getline(char* buf, unsigned len) +{ + int i = -1; + do { + i++; + read(&buf[i],1); + } while(buf[i] != '\n' && i < (int)len && !eof()); + if(eof()) + buf[i] = '\0'; + else + buf[i - 1] = '\0'; + return buf; +} diff --git a/MechoSoma/XTool/xtool.h b/MechoSoma/XTool/xtool.h new file mode 100644 index 00000000..c318feb8 --- /dev/null +++ b/MechoSoma/XTool/xtool.h @@ -0,0 +1,1218 @@ +/* +****************************************************************************** +** ** +** XTOOL Windows 32 API version 3.0nt ** +** for Windows-NT, Windows 95 ** +** ** +** (C)1993-97 by K-D Lab::KranK, K-D Lab::Steeler, Dr.Tronick ** +** ** +****************************************************************************** +*/ + + +#ifndef __XTCORE_H +#define __XTCORE_H + +#ifndef FORCEINLINE +#ifdef _MSC_VER + #if _MSC_VER == 1100 //MSVisual C++ 5.0 + #define FORCEINLINE inline + #else + #define FORCEINLINE __forceinline + #endif +#else +#define FORCEINLINE inline //__attribute__((always_inline)) +#endif //_MSC_VER +#endif //FORCEINLINE + +#ifndef NULL +#define NULL 0L +#endif + +// XSysObject IDs... +#define XGRAPH_SYSOBJ_ID 0x01 +#define XSOUND_SYSOBJ_ID 0x02 +#define XAVI_SYSOBJ_ID 0x03 +#define XD3D_SYSOBJ_ID 0x04 + +struct XListElement +{ + XListElement* next; + XListElement* prev; + + XListElement(void){ next = prev = NULL; } +}; + +// fPtr -> prev == lPtr +// lPtr -> next == NULL +struct XList +{ + int ListSize; + XListElement* fPtr; + XListElement* lPtr; + + void ClearList(void){ ListSize = 0; fPtr = lPtr = NULL; } + + void AddElement(XListElement* p); + void RemoveElement(XListElement* p); + + XList(void); + ~XList(void); +}; + +#define XT_TERMINATE_ID 0xFFFFFFFF + +struct XRuntimeObject +{ + int ID; + int Timer; + + XRuntimeObject* next; + + virtual void Init(int pID){ } + virtual void Finit(void){ } + virtual int Quant(void){ if(next) return next -> ID; return XT_TERMINATE_ID; } + + void SetTimer(int t){ Timer = t; } + + XRuntimeObject(void){ ID = 1; next = NULL; Timer = 0; } + XRuntimeObject(int id){ ID = id; next = NULL; Timer = 0; } + XRuntimeObject(int id,int tm){ ID = id; next = NULL; Timer = tm; } + ~XRuntimeObject(void){ } +}; + +// XSysObject::flags... +#define XSYS_OBJ_INACTIVE 0x01 + +struct XSysObject : XListElement +{ + int ID; + int flags; + + void* QuantPtr; + + XSysObject(void){ ID = 0; flags = 0; QuantPtr = NULL; } +}; + +/* + "Critical Section" sinchronisation method + for "protected" data in multi-processing application + +struct XCriticalSection +{ + KDWIN::LPCRITICAL_SECTION csection; + XCriticalSection(void *section) { csection = (KDWIN::LPCRITICAL_SECTION )section; KDWIN::EnterCriticalSection(csection); } + ~XCriticalSection(void) { KDWIN::LeaveCriticalSection(csection); } +}; + +*/ + +void xtCreateRuntimeObjectTable(int len = 0); +void xtRegisterRuntimeObject(XRuntimeObject* p); +XRuntimeObject* xtGetRuntimeObject(int id); + +void xtRegisterSysQuant(void (*qPtr)(void),int id); +void xtUnRegisterSysQuant(int id); + +int xtIsActive(void); +int xtNeedExit(void); + +void xtClearMessageQueue(void); + +int xtInitApplication(void); +void xtDoneApplication(void); + +void* xtGet_hInstance(void); +void* xtGet_hWnd(void); +void xtSet_hWnd(void* hWnd); +extern void* XGR_hWnd; + +void xtSysQuantDisable(int v = 1); +void xtSysQuant(void); + +void xtCreateDummyWindow(int x = 0,int y = 0,int sx = 100,int sy = 100); +void xtCloseDummyWindow(void); + +#endif /* __XTCORE_H */ + + +/* + XConsole (Windows 32 API version) + By K-D Lab::KranK, Dr.Tronick, K-D Lab::Steeler (C) 1993-97 V3.0nt +*/ + +#ifndef __XCONSOLE_H +#define __XCONSOLE_H + +#undef NULL +#ifndef NULL +#define NULL 0L +#endif + +struct XConsole +{ + int radix; + int digits; + + int tab; + + void UpdateBuffer(const char *); + + XConsole(void); + ~XConsole(void); + + XConsole& operator< (const char*); + XConsole& operator< (char); + XConsole& operator< (unsigned char); + + XConsole& operator<= (short); + XConsole& operator<= (unsigned short); + XConsole& operator<= (int); + XConsole& operator<= (unsigned int); + XConsole& operator<= (long); + XConsole& operator<= (unsigned long); + XConsole& operator<= (float); + XConsole& operator<= (double); + XConsole& operator<= (long double); + + void SetRadix(int _radix){ radix = _radix; } + void SetDigits(int _digits){ digits = _digits; } + void SetTab(int size){ tab = size; } + void clear(); + + void setpos(int _x,int _y); + void getpos(int &x,int &y); + void initialize(int mode); +}; + +#define _CONV_BUFFER_LEN 63 +extern char _ConvertBuffer[_CONV_BUFFER_LEN + 1]; +extern XConsole XCon; + +#endif /* __XCONSOLE_H */ + +#ifndef __XBUFFER_H +#define __XBUFFER_H + +#ifndef NULL +#define NULL 0L +#endif + +#define XB_DEFSIZE 256 + +#define XB_BEG 0 +#define XB_CUR 1 +#define XB_END 2 + +#define XB_FORWARD 0 +#define XB_BACKWARD 1 +#define XB_GLOBAL 2 + +#define XB_CASEON 0 +#define XB_CASEOFF 1 + +#define XB_DEFRADIX 10 +#define XB_DEFDIGITS 8 + +struct XBuffer +{ + char* buf; + unsigned int size; + unsigned int offset; + int radix; + int digits; + int MakeFree; + int automatic_realloc; + + XBuffer(unsigned int sz = XB_DEFSIZE, int automatic_realloc_ = 0); + XBuffer(void* p,int sz); + ~XBuffer(){ free(); } + + void SetRadix(int r) { radix = r; } + void SetDigits(int d) { digits = d; } + + void alloc(unsigned int sz); + void free(void); + void fill(char fc = '\0'); + void set(int off,int mode = XB_BEG); + void init(void){ offset = 0; *buf = 0; } + int search(char* what,int mode = XB_FORWARD,int cs = XB_CASEON); + int end() const { return (offset > size); } + + unsigned int tell(void) const { return offset; } + unsigned int length(void) const { return size; } + char* address(){ return buf; } + + unsigned int read(void* s, unsigned int len); + unsigned int write(const void* s, unsigned int len, int bin_flag = 1); + void handleOutOfSize(); + + XBuffer& operator< (const char* v); + XBuffer& operator< (char* v) { return this->operator<((const char*) v); }; + XBuffer& operator< (char v) { return write(v); } + XBuffer& operator< (unsigned char v) { return write(v); } + XBuffer& operator< (short v) { return write(v); } + XBuffer& operator< (unsigned short v) { return write(v); } + XBuffer& operator< (int v ) { return write(v); } + XBuffer& operator< (unsigned int v) { return write(v); } + XBuffer& operator< (long v) { return write(v); } + XBuffer& operator< (unsigned long v) { return write(v); } + XBuffer& operator< (float v) { return write(v); } + XBuffer& operator< (double v) { return write(v); } + XBuffer& operator< (long double v) { return write(v); } + + XBuffer& operator> (char* v); + XBuffer& operator> (char& v) { return read(v); } + XBuffer& operator> (unsigned char& v) { return read(v); } + XBuffer& operator> (short& v) { return read(v); } + XBuffer& operator> (unsigned short& v) { return read(v); } + XBuffer& operator> (int& v) { return read(v); } + XBuffer& operator> (unsigned int& v) { return read(v); } + XBuffer& operator> (long& v) { return read(v); } + XBuffer& operator> (unsigned long& v) { return read(v); } + XBuffer& operator> (float& v) { return read(v); } + XBuffer& operator> (double& v) { return read(v); } + XBuffer& operator> (long double& v) { return read(v); } + + XBuffer& operator<= (char); + XBuffer& operator<= (unsigned char); + XBuffer& operator<= (short); + XBuffer& operator<= (unsigned short); + XBuffer& operator<= (int); + XBuffer& operator<= (unsigned int); + XBuffer& operator<= (long); + XBuffer& operator<= (unsigned long); + XBuffer& operator<= (float); + XBuffer& operator<= (double); + XBuffer& operator<= (long double); + + XBuffer& operator>= (char&); + XBuffer& operator>= (unsigned char&); + XBuffer& operator>= (short&); + XBuffer& operator>= (unsigned short&); + XBuffer& operator>= (int&); + XBuffer& operator>= (unsigned int&); + XBuffer& operator>= (long&); + XBuffer& operator>= (unsigned long&); + XBuffer& operator>= (float&); + XBuffer& operator>= (double&); + XBuffer& operator>= (long double&); + + operator char* (){ return buf; } + char* operator ()(int offs){ return buf + offs; } + XBuffer& operator++(){ offset++; return *this; } + XBuffer& operator--(){ offset--; return *this; } + XBuffer& operator+= (int v){ offset+=v; return *this; } + XBuffer& operator-= (int v){ offset-=v; return *this; } + + char operator[](int ind) const { return buf[ind]; } + char operator()() const { return buf[offset]; } + + char& operator[](int ind){ return buf[ind]; } + char& operator()(){ return buf[offset]; } + + template XBuffer& write(const T& v){ while(offset + sizeof(T) >= size) handleOutOfSize(); (T&)buf[offset] = v; offset += sizeof(T); return *this; } + template XBuffer& read(T& v){ v = (T&)buf[offset]; offset += sizeof(T); return *this; } +}; + +#endif /* __XBUFFER_H */ + +#ifndef __XSTREAM_H +#define __XSTREAM_H + + +#define XS_IN 0x0001 +#define XS_OUT 0x0002 +#define XS_NOREPLACE 0x0004 +#define XS_APPEND 0x0008 +#define XS_NOBUFFERING 0x0010 +#define XS_NOSHARING 0x0020 + +#define XS_SHAREREAD 0x0040 +#define XS_SHAREWRITE 0x0080 + +#define XS_BEG 0 +#define XS_CUR 1 +#define XS_END 2 + +#define XS_DEFRADIX 10 +#define XS_DEFDIGITS 8 + +struct XStream +{ + typedef void* XSHANDLE; + + XSHANDLE handler; + long pos; + int eofFlag; + int ErrHUsed; + bool ioError_; + const char* fname; + int radix, digits; + long extSize; + long extPos; + + XStream(int err = 1); + XStream(const char* name, unsigned flags,int err = 1); + ~XStream(); + + int open(const char* name, unsigned f = XS_IN); + int open(XStream* owner,long start,long ext_sz = -1); + void close(); + unsigned long read(void* buf, unsigned long len); + unsigned long write(const void* buf, unsigned long len); + long seek(long offset, int dir); + long tell() const { return pos; } + char* getline(char* buf, unsigned len); + int eof(){ return eofFlag || pos >= size(); } + long size() const; + long size(); + // int gethandler(){ return (int)handler; } + void gettime(unsigned& date,unsigned& time); + void flush(); + const char* GetFileName() const { return fname; } + void SetRadix(int r){ radix=r; } + void SetDigits(int d){ digits=d; } + + XStream& operator< (const char*); + XStream& operator< (char); + XStream& operator< (unsigned char); + XStream& operator< (short); + XStream& operator< (unsigned short); + XStream& operator< (int); + XStream& operator< (unsigned int); + XStream& operator< (long); + XStream& operator< (unsigned long); + XStream& operator< (float); + XStream& operator< (double); + XStream& operator< (long double); + + XStream& operator> (char*); + XStream& operator> (char&); + XStream& operator> (unsigned char&); + XStream& operator> (short&); + XStream& operator> (unsigned short&); + XStream& operator> (int&); + XStream& operator> (unsigned int&); + XStream& operator> (long&); + XStream& operator> (unsigned long&); + XStream& operator> (float&); + XStream& operator> (double&); + XStream& operator> (long double&); + + XStream& operator<= (char); + XStream& operator<= (unsigned char); + XStream& operator<= (short); + XStream& operator<= (unsigned short); + XStream& operator<= (int); + XStream& operator<= (unsigned int); + XStream& operator<= (long); + XStream& operator<= (unsigned long); + XStream& operator<= (float); + XStream& operator<= (double); + XStream& operator<= (long double); + + XStream& operator>= (char&); + XStream& operator>= (unsigned char&); + XStream& operator>= (short&); + XStream& operator>= (unsigned short&); + XStream& operator>= (int&); + XStream& operator>= (unsigned int&); + XStream& operator>= (long&); + XStream& operator>= (unsigned long&); + XStream& operator>= (float&); + XStream& operator>= (double&); + XStream& operator>= (long double&); + + int operator! (){ if(handler != XSHANDLE(-1)) return 1; else return 0; } + operator void* (){ if(handler != XSHANDLE(-1)) return 0; else return this; } + + bool ioError() const { return ioError_; } + + template XStream& write(const T& v){ write(&v, sizeof(T)); return *this; } + template XStream& read(T& v){ read(&v, sizeof(T)); return *this; } +}; + +#endif /* __XSTREAM_H */ + + +#ifndef _ERRH_H +#define _ERRH_H + +#ifndef NULL +#define NULL 0L +#endif + +#define X_WINNT 0x0001 +#define X_WIN32S 0x0002 +#define X_WIN95 0x0003 + +#define XERR_ALL 0xFFFF +#define XERR_NONE 0x0000 + +#define XERR_USER 0x0001 +#define XERR_CTRLBRK 0x0004 +#define XERR_MATH 0x0008 +#define XERR_FLOAT 0x0010 +#define XERR_CRITICAL 0x0020 +#define XERR_SIGNAL 0x0040 + +#define XERR_ACCESSVIOLATION 0x0080 +#define XERR_DEBUG 0x0100 +#define XERR_UNKNOWN 0x0200 + +struct XErrorHandler +{ + unsigned flags; + unsigned state; + + const char* prefix; + const char* postfix; + + void (*restore_func)(void); + + XErrorHandler(void); + ~XErrorHandler(void); + + void SetFlags(unsigned f); + void ClearFlags(unsigned f); + unsigned InfoFlags(unsigned f); + + void SetPrefix(const char* s); + void SetPostfix(const char* s); + void SetRestore(void (*rf)(void)); + void SetState(int s){state=s;} + void Abort(const char* message, int code = XERR_USER, int addval = -1, const char* subj = NULL); + void Exit(void); + void RTC(const char *file,unsigned int line, const char *expr); + void WriteLog(char* error, char* msg); +}; + +extern XErrorHandler ErrH; + +// Use this macro for after any operation for errors diagnostic +#define XAssert(expr) ErrH.RTC(__FILE__,__LINE__,expr) + + +#if (!defined(_FINAL_VERSION_) || defined(_DEBUG)) && !defined(NASSERT) + +// Use d3dFlipToGdiSurface() for D3D Fullscreen modes +void SetAssertRestoreGraphicsFunction(void(*func)()); + +int DiagAssert(unsigned long dwOverrideOpts, const char* szMsg, const char* szFile, unsigned long dwLine ) ; + +#undef NDEBUG +#define xxassert(exp, msg) \ + do \ + { static int ignore = 0; \ + if ( !(exp) && !ignore) \ + switch(DiagAssert ( 0 , msg, __FILE__ , __LINE__)){ \ + case 1: ignore = 1; break; \ + case 2: __asm { int 3 }; break; \ + }\ + } while (0) + +#define xassert(exp) xxassert(exp, #exp) + +#else // ... + +#define SetAssertRestoreGraphicsFunction(func) +#define xxassert(exp, msg) +#define xassert(exp) + +#endif // ... + +#ifdef _WIN32 +#undef assert +#define assert(x) xassert(x) +#endif + +#endif /* _ERRH_H */ + +#ifndef __XRECORDER_H +#define __XRECORDER_H + +// XRecorderMessage types... +enum XRecorderMessages +{ + XRC_SYSTEM_MESSAGE = 1, // Keyoard events... + XRC_XMOUSE_MESSAGE, // Mouse events... + XRC_USER_MESSAGE, // Custom events... + + XRC_MAX_MESSAGE_ID +}; + +struct XRecorderMessage +{ + int Type; + int Frame; + int DataSize; + + int* data; + + XRecorderMessage(void){ Type = 0; DataSize = 0; Frame = 0; data = NULL; } +}; + +// XRecorder flags... +#define XRC_RECORD_MODE 0x01 +#define XRC_PLAY_MODE 0x02 +#define XRC_MESSAGE_READ 0x04 +#define XRC_EXTERNAL_QUANT 0x08 + +#define XRC_CONTROL_COUNT 1024 +#define XRC_BUFFER_SIZE 5 + +struct XRecorder +{ + int flags; + + int frameCount; + int controlCount; + + void* hWnd; + + XStream* hFile; + + int nextMsgDataSize; + XRecorderMessage* nextMsg; + + void Quant(void); + + void Open(char* fname,int mode); + void Close(void); + void Flush(void); + + void PutMessage(int msg,int sz = 0,void* p = NULL); + void PutSysMessage(int id,int msg,int wp,int lp); + void GetMessage(void); + void DispatchMessage(void); + int CheckMessage(int code); + + XRecorder(void); +}; + +extern XRecorder XRec; + +#endif /* __XRECORDER_H */ + +#ifndef __XKEY_H +#define __XKEY_H + +// Flags for XKey::keyStates... +#define XKEY_REPEAT 0x0002 +#define XKEY_PRESSED 0x0004 +#define XKEY_WASPRESSED 0x0008 + +#define XKEY_MAXCODE 256 + +/* + * Virtual Keys, Standard Set + */ + +#define VK_UNKNOWN 0x00 +#define VK_LBUTTON 0x01 +#define VK_RBUTTON 0x02 +#define VK_CANCEL 0x03 +#define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */ + +#define VK_BACK 0x08 +#define VK_TAB 0x09 + +#define VK_CLEAR 0x0C +#define VK_RETURN 0x0D + +#define VK_SHIFT 0x10 +#define VK_CONTROL 0x11 +#define VK_MENU 0x12 +#define VK_PAUSE 0x13 +#define VK_CAPITAL 0x14 + + +#define VK_ESCAPE 0x1B + +#define VK_SPACE 0x20 +#define VK_PRIOR 0x21 +#define VK_NEXT 0x22 +#define VK_END 0x23 +#define VK_HOME 0x24 +#define VK_LEFT 0x25 +#define VK_UP 0x26 +#define VK_RIGHT 0x27 +#define VK_DOWN 0x28 +#define VK_SELECT 0x29 +#define VK_PRINT 0x2A +#define VK_EXECUTE 0x2B +#define VK_SNAPSHOT 0x2C +#define VK_INSERT 0x2D +#define VK_DELETE 0x2E +#define VK_HELP 0x2F + +/* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ +#define VK_0 0x30 +#define VK_1 0x31 +#define VK_2 0x32 +#define VK_3 0x33 +#define VK_4 0x34 +#define VK_5 0x35 +#define VK_6 0x36 +#define VK_7 0x37 +#define VK_8 0x38 +#define VK_9 0x39 + +/* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ +#define VK_A 0x41 +#define VK_B 0x42 +#define VK_C 0x43 +#define VK_D 0x44 +#define VK_E 0x45 +#define VK_F 0x46 +#define VK_G 0x47 +#define VK_H 0x48 +#define VK_I 0x49 +#define VK_J 0x4A +#define VK_K 0x4B +#define VK_L 0x4C +#define VK_M 0x4D +#define VK_N 0x4E +#define VK_O 0x4F +#define VK_P 0x50 +#define VK_Q 0x51 +#define VK_R 0x52 +#define VK_S 0x53 +#define VK_T 0x54 +#define VK_U 0x55 +#define VK_V 0x56 +#define VK_W 0x57 +#define VK_X 0x58 +#define VK_Y 0x59 +#define VK_Z 0x5A + +#define VK_LWIN 0x5B +#define VK_RWIN 0x5C +#define VK_APPS 0x5D + +#define VK_NUMPAD0 0x60 +#define VK_NUMPAD1 0x61 +#define VK_NUMPAD2 0x62 +#define VK_NUMPAD3 0x63 +#define VK_NUMPAD4 0x64 +#define VK_NUMPAD5 0x65 +#define VK_NUMPAD6 0x66 +#define VK_NUMPAD7 0x67 +#define VK_NUMPAD8 0x68 +#define VK_NUMPAD9 0x69 +#define VK_MULTIPLY 0x6A +#define VK_ADD 0x6B +#define VK_SEPARATOR 0x6C +#define VK_SUBTRACT 0x6D +#define VK_DECIMAL 0x6E +#define VK_DIVIDE 0x6F +#define VK_F1 0x70 +#define VK_F2 0x71 +#define VK_F3 0x72 +#define VK_F4 0x73 +#define VK_F5 0x74 +#define VK_F6 0x75 +#define VK_F7 0x76 +#define VK_F8 0x77 +#define VK_F9 0x78 +#define VK_F10 0x79 +#define VK_F11 0x7A +#define VK_F12 0x7B +#define VK_F13 0x7C +#define VK_F14 0x7D +#define VK_F15 0x7E +#define VK_F16 0x7F +#define VK_F17 0x80 +#define VK_F18 0x81 +#define VK_F19 0x82 +#define VK_F20 0x83 +#define VK_F21 0x84 +#define VK_F22 0x85 +#define VK_F23 0x86 +#define VK_F24 0x87 + +#define VK_NUMLOCK 0x90 +#define VK_SCROLL 0x91 + +/* + * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. + * Used only as parameters to GetAsyncKeyState() and GetKeyState(). + * No other API or message will distinguish left and right keys in this way. + */ +#define VK_LSHIFT 0xA0 +#define VK_RSHIFT 0xA1 +#define VK_LCONTROL 0xA2 +#define VK_RCONTROL 0xA3 +#define VK_LMENU 0xA4 +#define VK_RMENU 0xA5 + +#define VK_VOLUME_MUTE 0xAD +#define VK_VOLUME_DOWN 0xAE +#define VK_VOLUME_UP 0xAF + +#define VK_ATTN 0xF6 +#define VK_CRSEL 0xF7 +#define VK_EXSEL 0xF8 +#define VK_EREOF 0xF9 +#define VK_PLAY 0xFA +#define VK_ZOOM 0xFB +#define VK_NONAME 0xFC +#define VK_PA1 0xFD +#define VK_OEM_CLEAR 0xFE + + +// Some additional virtual keycodes... +#define VK_OEM_1 0xBA +#define VK_OEM_PLUS 0xBB +#define VK_OEM_COMMA 0xBC +#define VK_OEM_MINUS 0xBD +#define VK_OEM_PERIOD 0xBE +#define VK_OEM_2 0xBF +#define VK_OEM_3 0xC0 +#define VK_OEM_4 0xDB +#define VK_OEM_5 0xDC +#define VK_OEM_6 0xDD +#define VK_OEM_7 0xDE + +#define VK_OEM_SCROLL 0x91 + +#define VK_OEM_ALT 0x12 + +#define VK_SLASH 0xBF +#define VK_BKSLASH 0x5C +#define VK_TILDE 0xC0 +#define VK_LBR 0x5B +#define VK_RBR 0x5D + + +struct XKeyStruct +{ + typedef void (*PFN)(int); + typedef void (*PFK)(); + + PFK keyPressFnc[XKEY_MAXCODE]; + PFK keyUnpressFnc[XKEY_MAXCODE]; + + void* pressHandler; + void* unpressHandler; + + int LastChar; + int LastScanCode; + char keyStates[XKEY_MAXCODE]; + + XKeyStruct(); + ~XKeyStruct(); + + void init(void* pH, void* upH); + void finit(void); + void setPress(int key,void (*keyFunction)(void),int repeat); + void setUnpress(int key,void (*keyFunction)(void)); + + void PressFnc(int vkey, int key); + void UnPressFnc(int vkey, int key); + + void clear(void); + + int Pressed(int key); + int wasPressed(int key); +}; + +extern XKeyStruct XKey; + +int xtGetKeyName(int vkey,int shift,int russian = 0); +char* xtGetKeyNameText(int key); + +int xtGetKeyState(int vk); + +#endif /* __XKEY_H */ + + +#ifndef __XUTIL_H +#define __XUTIL_H + +void* xalloc(unsigned sz); +void* xrealloc(void* p,unsigned sz); +void xfree(void* p); + +#define XALLOC(a) xalloc(a) +#define XREALLOC(a,b) xrealloc(a,b) +#define XFREE(a) xfree(a) + +unsigned int XRnd(unsigned int m); +void XRndSet(unsigned int m); +unsigned int XRndGet(); + +char* XFindNext(void); +char* XFindFirst(char* mask); + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +// #ifndef __ROUND__ +// #define __ROUND__ + +// __forceinline int round(double x) +// { +// int a; +// _asm { +// fld x +// fistp dword ptr a +// } +// return a; +// } + +// __forceinline int round(float x) +// { +// int a; +// _asm { +// fld x +// fistp dword ptr a +// } +// return a; +// } + +// template +// __forceinline T sqr(const T& x){ return x*x; } + +// template +// __forceinline int SIGN(const T& x) { return x ? (x > 0 ? 1 : -1 ) : 0; } + +// #endif __ROUND__ + +// __forceinline int BitSR(int x) +// { +// int return_var; +// _asm { +// mov eax, x +// cdq +// xor eax,edx +// sub eax,edx +// bsr eax,eax +// mov [return_var],eax +// } +// return return_var; +// } + +void initclock(void); +int clocki(void); +double clockf(void); + +void xtDeleteFile(char* fname); + +#endif +#ifndef __XCPUID_H +#define __XCPUID_H + +#define CPU_INTEL 0x00000001 + +// Intel features IDs + +#define INTEL_MMX 0x00800000 + +// Intel Family IDs +#define CPU_INTEL_386 3 +#define CPU_INTEL_486 4 +#define CPU_INTEL_PENTIUM 5 +#define CPU_INTEL_PENTIUM_PRO 6 + +//Intel Pentium model's +#define PENTIUM_P5A 0 +#define PENTIUM_P5 1 +#define PENTIUM_P54C 2 +#define PENTIUM_P54T 3 +#define PENTIUM_MMX 4 +#define PENTIUM_DX4 5 +#define PENTIUM_P5OVER 6 +#define PENTIUM_P54CA 7 + +// Intel Pentium Pro model's +#define PENTIUM_PROA 0 +#define PENTIUM_PRO 1 +#define PENTIUM_PRO2 3 +#define PENTIUM_PRO55CT 4 +#define PENTIUM_PROF 5 + +extern unsigned int xt_processor_id; +extern unsigned int xt_processor_type; +extern unsigned int xt_processor_family; +extern unsigned int xt_processor_model; +extern unsigned int xt_processor_revision; +extern unsigned int xt_processor_features; + +unsigned int xt_get_cpuid(void); +char* xt_getMMXstatus(void); + +extern int xt_mmxUse; + +#endif // __XCPUID_H + +#ifndef __XZIP_H__ +#define __XZIP_H__ + +typedef unsigned long ulong; + +ulong ZIP_compress(char* trg,ulong trgsize,char* src,ulong srcsize); +ulong ZIP_GetExpandedSize(char* p); +void ZIP_expand(char* trg,ulong trgsize,char* src,ulong srcsize); + + +#endif //__XZIP_H__ + +#ifndef __XT_LIST_H__ +#define __XT_LIST_H__ + + +template class xtList +{ + int numElements; + Type* firstElement; + void test(int code); + +public: + + xtList(); + ~xtList(); + + int size(); + Type* first(); + Type* last(); + + void clear(); + void delete_all(); + + void insert(Type* p); + void append(Type* p); + void insert(Type* pointer,Type* p); + void append(Type* pointer,Type* p); + void remove(Type* p); + Type* search(int ID); +}; + +template +inline void xtList::test(int code) +{ +#ifdef _XT_TEST_LIST_ + Type* p = first(); + int cnt = 0; + while(p){ + cnt++; + p = p -> next; + } + if(cnt != numElements) + ErrH.Abort("List",XERR_USER,code); +#endif +} + +template +inline xtList::xtList() +{ + numElements = 0; firstElement = 0; +} + +template +inline xtList::~xtList() +{ + clear(); +} + +template +inline void xtList::clear() +{ + while(first()) + remove(first()); +} + +template +inline void xtList::delete_all() +{ + Type* p; + while((p = first()) != 0){ + remove(p); + delete p; + } +} + +template +inline int xtList::size() +{ + return numElements; +} + +template +inline Type* xtList::first() +{ + return firstElement; +} + +template +inline Type* xtList::last() +{ + return firstElement ? firstElement -> prev : 0; +} + +template +inline void xtList::insert(Type* p) +{ + if(p -> list) + ErrH.Abort("Element is already in list"); + numElements++; + if(firstElement){ + p -> next = firstElement; + p -> prev = firstElement -> prev; + firstElement -> prev = p; + } + else{ + p -> prev = p; + p -> next = 0; + } + firstElement = p; + p -> list = this; + test(0); +} + +template +inline void xtList::insert(Type* pointer,Type* p) +{ + if(!firstElement || firstElement == pointer){ + insert(p); + return; + } + if(!pointer){ + append(p); + return; + } + + if(p -> list) + ErrH.Abort("Element is already in list"); + numElements++; + p -> next = pointer; + p -> prev = pointer -> prev; + pointer -> prev -> next = p; + pointer -> prev = p; + p -> list = this; + test(5); +} + + +template +inline void xtList::append(Type* p) +{ + if(p -> list) + ErrH.Abort("Element is already in list"); + numElements++; + if(firstElement){ + p -> next = 0; + p -> prev = firstElement -> prev; + firstElement -> prev -> next = p; + firstElement -> prev = p; + } + else{ + p -> next = 0; + p -> prev = firstElement = p; + } + p -> list = this; + test(1); +} + +template +inline void xtList::remove(Type* p) +{ + if(p -> list != this) + ErrH.Abort("Removed element isn't in list"); + numElements--; + if(p -> next) + p -> next -> prev = p -> prev; + else + firstElement -> prev = p -> prev; + + if(p != firstElement) + p -> prev -> next = p -> next; + else{ + firstElement = p -> next; + if(firstElement) + firstElement -> prev = p -> prev; + } + + p -> next = p -> prev = 0; + p -> list = 0; + test(2); +} + +template +inline Type* xtList::search(int ID) +{ + Type* p = first(); + while(p){ + if(p -> ID == ID) + return p; + p = p -> next; + } + return 0; +} + +#endif // __XT_LIST_H__ + + +#ifndef __ZIP_RESOURCE_H__ +#define __ZIP_RESOURCE_H__ + +class XZIP_FileHeader +{ + char* fileName; + unsigned dataOffset; + unsigned dataSize; + + int extDataSize; + char* extData; + +public: + void* list; + XZIP_FileHeader* prev; + XZIP_FileHeader* next; + + void SetName(char* p); + + unsigned size(void) const { return dataSize; } + unsigned offset(void) const { return dataOffset; } + char* data(void) const { return extData; } + char* name(void) const { return fileName; } + + void save(XStream& fh); + + XZIP_FileHeader(void); + XZIP_FileHeader(char* fname,unsigned offs,unsigned size,void* ext_ptr,int ext_sz); + XZIP_FileHeader(XStream& fh); + ~XZIP_FileHeader(void); +}; + +// XZIP_Resource flags +const int XZIP_ENABLE_EXTERNAL_FILES = 0x01; +const int XZIP_ENABLE_ZIP_HEADERS = 0x02; + +class XZIP_Resource +{ + int flags; + + char* fileName; + char* idxName; + + xtList fileList; + XStream file; + + XZIP_FileHeader* find(const char* fname); +public: + int open(char* fname,XStream& fh,int mode = 0); + + void LoadHeaders(void); + void LoadIndex(void); + void SaveIndex(void); + + void dump(char* fname); + + XZIP_Resource(char* fname,int fl); + ~XZIP_Resource(void); +}; + +#endif \ No newline at end of file diff --git a/MechoSoma/XTool/xutil.cpp b/MechoSoma/XTool/xutil.cpp new file mode 100644 index 00000000..ae34d8c5 --- /dev/null +++ b/MechoSoma/XTool/xutil.cpp @@ -0,0 +1,211 @@ +#include "xtool.h" + +#include +#include + +void* XGR_hWnd; + +#define XT_DEFAULT_TABLE_SIZE 32 + +XRuntimeObject** XRObjTable = NULL; +unsigned int XRObjTableSize = 0; + +XRuntimeObject* XRObjFirst = NULL; +XRuntimeObject* XRObjLast = NULL; + +XList::XList(void) +{ + ClearList(); +} + +XList::~XList(void) +{ +} + +void XList::AddElement(XListElement* p) +{ + if (!fPtr) + { + fPtr = lPtr = p; + p->prev = p; + p->next = NULL; + } + else + { + lPtr->next = p; + p->prev = lPtr; + p->next = NULL; + lPtr = p; + fPtr -> prev = p; + } + ListSize ++; +} + +void XList::RemoveElement(XListElement* p) +{ + XListElement* pPtr; + XListElement* nPtr; + + ListSize--; + if (ListSize) + { + pPtr = p->prev; + nPtr = p->next; + + pPtr->next = nPtr; + if (nPtr) + { + nPtr->prev = pPtr; + } + + if (p == fPtr) + { + fPtr = nPtr; + } + + if (p == lPtr) + { + lPtr = pPtr; + } + + lPtr->next = NULL; + fPtr->prev = lPtr; + } + else + { + ClearList(); + } +} + +char* XFindFirst(char* mask) +{ + return nullptr; +} + +char* XFindNext(void) +{ + return nullptr; +} + +void xtDeleteFile(char* fname) +{ +} + +void xtCreateRuntimeObjectTable(int len) +{ + int i; + if(!len) len = XT_DEFAULT_TABLE_SIZE; + XRObjTableSize = len; + XRObjTable = new XRuntimeObject*[len]; + + for(i = 0; i < len; i ++){ + XRObjTable[i] = NULL; + } +} + +void xtRegisterRuntimeObject(XRuntimeObject* p) +{ + if(!XRObjFirst){ + XRObjFirst = XRObjLast = p; + } + else { + XRObjLast -> next = p; + XRObjLast = p; + } + XRObjTable[p -> ID - 1] = p; +} + +XRuntimeObject* xtGetRuntimeObject(int id) +{ + if(id == XT_TERMINATE_ID) + return NULL; + if(!XRObjTable || !XRObjTableSize || id < 1 || id > XRObjTableSize) + ErrH.Abort("XTool system error..."); + return XRObjTable[id - 1]; +} + +int xtIsActive(void) +{ + return 0; +} + +void xtClearMessageQueue(void) +{ +} + +void xtSysQuantDisable(int v) +{ +} + +static unsigned int XRndValue = 83838383; + +unsigned int XRnd(unsigned int m) +{ + XRndValue = XRndValue * 214013L + 2531011L; + if(!m){ + return 0; + } + return ((XRndValue>> 16) & 0x7fff) % m; +} + +using ClockType = std::chrono::high_resolution_clock; +using TimePoint = std::chrono::time_point; +TimePoint start_time; + +void initclock(void) +{ + start_time = std::chrono::high_resolution_clock::now(); +} + +int clocki(void) +{ + const auto d = std::chrono::high_resolution_clock::now() - start_time; + const auto ms = std::chrono::duration_cast(d); + return static_cast(ms.count()); +} + +double clockf(void) +{ + const auto d = std::chrono::high_resolution_clock::now() - start_time; + return std::chrono::duration(d).count(); +} + +void* xtGet_hInstance(void) +{ + return nullptr; +} + +void xtRegisterSysFinitFnc(void (*fPtr)(void),int id) +{ +} + +void xtDeactivateSysFinitFnc(int id) +{ +} + +void mchGraphicsSetup(void) +{ +} + +std::string win32_get_path_from_regkey(int key_id,char* subkey_name,char* value_name) +{ + return ""; +} + +int win32_GetKeybLayoutID(void) +{ +} + +void win32_InitLocale(void) +{ +} + +void* win32_load_icon(void) +{ + return nullptr; +} + +void* GetDS_Ptr(void) +{ + return nullptr; +} diff --git a/MechoSoma/XTool/zip_headers.h b/MechoSoma/XTool/zip_headers.h new file mode 100644 index 00000000..c22d097d --- /dev/null +++ b/MechoSoma/XTool/zip_headers.h @@ -0,0 +1,61 @@ + +#ifndef __ZIP_HEADERS_H__ +#define __ZIP_HEADERS_H__ + +typedef unsigned char byte; +typedef long longint; +typedef unsigned short word; + +typedef longint signature_type; + +#define local_file_header_signature 0x04034b50L + +struct local_file_header { + word version_needed_to_extract; + word general_purpose_bit_flag; + word compression_method; + word last_mod_file_time; + word last_mod_file_date; + longint crc32; + longint compressed_size; + longint uncompressed_size; + word filename_length; + word extra_field_length; +}; + +#define central_file_header_signature 0x02014b50L + +struct central_directory_file_header { + word version_made_by; + word version_needed_to_extract; + word general_purpose_bit_flag; + word compression_method; + word last_mod_file_time; + word last_mod_file_date; + longint crc32; + longint compressed_size; + longint uncompressed_size; + word filename_length; + word extra_field_length; + word file_comment_length; + word disk_number_start; + word internal_file_attributes; + longint external_file_attributes; + longint relative_offset_local_header; +}; + +#define end_central_dir_signature 0x06054b50L + +struct end_central_dir_record { + word number_this_disk; + word number_disk_with_start_central_directory; + word total_entries_central_dir_on_this_disk; + word total_entries_central_dir; + longint size_central_directory; + longint offset_start_central_directory; + word zipfile_comment_length; +}; + +#endif // __ZIP_HEADERS_H__ + + diff --git a/MechoSoma/XTool/zip_resource.cpp b/MechoSoma/XTool/zip_resource.cpp new file mode 100644 index 00000000..66e293af --- /dev/null +++ b/MechoSoma/XTool/zip_resource.cpp @@ -0,0 +1,280 @@ + +/* ---------------------------- INCLUDE SECTION ----------------------------- */ + +#include +#include + +#ifndef _WIN32 +#include +#endif + +#include "xtool.h" +#include "zip_headers.h" + + +/* ----------------------------- STRUCT SECTION ----------------------------- */ +/* ----------------------------- EXTERN SECTION ----------------------------- */ +/* --------------------------- PROTOTYPE SECTION ---------------------------- */ +/* --------------------------- DEFINITION SECTION --------------------------- */ + +XZIP_FileHeader::XZIP_FileHeader(void) +{ + fileName = NULL; + dataOffset = 0; + dataSize = 0; + + extDataSize = 0; + extData = NULL; + + list = NULL; +} + +XZIP_FileHeader::XZIP_FileHeader(char* fname,unsigned offs,unsigned size,void* ext_ptr,int ext_sz) +{ + SetName(fname); + dataOffset = offs; + dataSize = size; + + list = NULL; + + if(ext_sz){ + extData = new char[extDataSize = ext_sz]; + memcpy(extData,(char*)ext_ptr,extDataSize); + } +} + +XZIP_FileHeader::XZIP_FileHeader(XStream& fh) +{ + int sz; + char fname[256]; + fh > sz; + + fh.read(fname,sz); + fname[sz] = 0; + + SetName(fname); + + fh > dataOffset > dataSize > extDataSize; + + if(extDataSize){ + extData = new char[extDataSize]; + fh.read(extData,extDataSize); + } +} + +XZIP_FileHeader::~XZIP_FileHeader(void) +{ + if(fileName) free(fileName); + + if(extData) + delete extData; +} + +void XZIP_FileHeader::SetName(char* p) +{ + int i,sz = strlen(p); + fileName = strdup(p); + for(i = 0; i < sz; i ++) + if(fileName[i] == '/') fileName[i] = '\\'; +} + +void XZIP_FileHeader::save(XStream& fh) +{ + int sz = strlen(fileName); + fh < sz; + fh.write(fileName,sz); + fh < dataOffset < dataSize < extDataSize; + + if(extDataSize) + fh.write(extData,extDataSize); +} + +XZIP_Resource::XZIP_Resource(char* fname,int fl) +{ + int sz; + flags = fl; + + fileName = strdup(fname); + idxName = strdup(fname); + sz = strlen(fname); + idxName[sz - 1] = 'x'; + idxName[sz - 2] = 'd'; + idxName[sz - 3] = 'i'; + + file.open(fname,XS_IN); + if(flags & XZIP_ENABLE_ZIP_HEADERS) + LoadHeaders(); + else + LoadIndex(); +} + +XZIP_Resource::~XZIP_Resource(void) +{ + XZIP_FileHeader* p; + + free(fileName); + free(idxName); + + p = fileList.first(); + while(p){ + fileList.remove(p); + delete p; + p = fileList.first(); + } +} + +void XZIP_Resource::LoadIndex(void) +{ + int i,sz; + XZIP_FileHeader* p; + + XStream fh(idxName,XS_IN); + fh > sz; + for(i = 0; i < sz; i ++){ + p = new XZIP_FileHeader(fh); + fileList.append(p); + } + fh.close(); +} + +void XZIP_Resource::LoadHeaders(void) +{ + int fl = 0; + longint sig; + + char fname[512]; + + XZIP_FileHeader* p; + + local_file_header lhdr; + central_directory_file_header chdr; + end_central_dir_record ecr; + + while(!fl){ + file > sig; + + switch(sig){ + case local_file_header_signature: + file > lhdr.version_needed_to_extract; + file > lhdr.general_purpose_bit_flag; + file > lhdr.compression_method; + file > lhdr.last_mod_file_time; + file > lhdr.last_mod_file_date; + file > lhdr.crc32; + file > lhdr.compressed_size; + file > lhdr.uncompressed_size; + file > lhdr.filename_length; + file > lhdr.extra_field_length; + + file.read(fname,lhdr.filename_length); + fname[lhdr.filename_length] = 0; + + file.seek(lhdr.extra_field_length,XS_CUR); + p = new XZIP_FileHeader(fname,file.tell(),lhdr.uncompressed_size,&lhdr,sizeof(local_file_header)); + fileList.append(p); + + file.seek(lhdr.compressed_size,XS_CUR); + break; + case central_file_header_signature: + file > chdr.version_made_by; + file > chdr.version_needed_to_extract; + file > chdr.general_purpose_bit_flag; + file > chdr.compression_method; + file > chdr.last_mod_file_time; + file > chdr.last_mod_file_date; + file > chdr.crc32; + file > chdr.compressed_size; + file > chdr.uncompressed_size; + file > chdr.filename_length; + file > chdr.extra_field_length; + file > chdr.file_comment_length; + file > chdr.disk_number_start; + file > chdr.internal_file_attributes; + file > chdr.external_file_attributes; + file > chdr.relative_offset_local_header; + + file.seek(chdr.filename_length,XS_CUR); + file.seek(chdr.extra_field_length,XS_CUR); + file.seek(chdr.file_comment_length,XS_CUR); + break; + case end_central_dir_signature: + file > ecr.number_this_disk; + file > ecr.number_disk_with_start_central_directory; + file > ecr.total_entries_central_dir_on_this_disk; + file > ecr.total_entries_central_dir; + file > ecr.size_central_directory; + file > ecr.offset_start_central_directory; + file > ecr.zipfile_comment_length; + + file.seek(ecr.zipfile_comment_length,XS_CUR); + fl = 1; + break; + } + } + file.seek(0,XS_BEG); +} + +void XZIP_Resource::SaveIndex(void) +{ + XZIP_FileHeader* p; + + XStream fh(idxName,XS_OUT); + fh < fileList.size(); + + p = fileList.first(); + while(p){ + p -> save(fh); + p = p -> next; + } + + fh.close(); +} + +XZIP_FileHeader* XZIP_Resource::find(const char* fname) +{ + XZIP_FileHeader* p = fileList.first(); + + while(p){ +#ifdef _WIN32 + if(!_stricmp(p -> name(),fname)) +#else + if(!strcasecmp(p -> name(),fname)) +#endif + return p; + p = p -> next; + } + return NULL; +} + +int XZIP_Resource::open(char* fname,XStream& fh,int mode) +{ +#ifndef _WIN32 + std::string t(fname); + for(auto &c : t){ + if(c == '/'){ + c = '\\'; + } + } + XZIP_FileHeader* p = find(t.c_str()); +#else + XZIP_FileHeader* p = find(fname); +#endif + if(p){ + fh.open(&file,p -> offset(),p -> size()); +// fh.open(new XStream(fileName,XS_IN),p -> offset(),p -> size()); + return 1; + } + return 0; +} + +void XZIP_Resource::dump(char* fname) +{ + XZIP_FileHeader* p = fileList.first(); + + XStream fh(fname,XS_OUT); + while(p){ + fh < p -> name() < " " <= p -> size() < "/" <= p -> offset() < "\r\n"; + p = p -> next; + } + fh.close(); +} diff --git a/MechoSoma/Xreal/ArcansOfMechos.cpp b/MechoSoma/Xreal/ArcansOfMechos.cpp index e8f547a7..ef200a80 100644 --- a/MechoSoma/Xreal/ArcansOfMechos.cpp +++ b/MechoSoma/Xreal/ArcansOfMechos.cpp @@ -3,12 +3,12 @@ #include "Mechos.h" #include "FieldSource.h" #include "Params.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "IVisGeneric.h" #include "sound.h" #include "MechosPrm.h" #include "ArcansPrm.h" -#include "terra.h" +#include "TERRA.H" const int morph_time = 500; @@ -21,12 +21,12 @@ Mechos::WheelMode Mechos::forward_wheels_mode() WHEEL, // WHEEL, // 1 WHEEL, // 2 - FOOT, // 3 - ìîòûëåê + FOOT, // 3 - ������� WHEEL, // 4 WHEEL, // 5 - FOOT, // 6 - æàáàñîìà - WHEEL, // 7 - âåðòîëåò - FOOT, // 8 - ñèëà äðàêîíà + FOOT, // 6 - �������� + WHEEL, // 7 - �������� + FOOT, // 8 - ���� ������� WHEEL // 9 }; return forward_wheels_modes[forward_wheels_kind()]; @@ -40,9 +40,9 @@ Mechos::WheelMode Mechos::backward_wheels_mode() WHEEL, // 3 WHEEL, // 4 WHEEL, // 5 - FOOT, // 6 - ÿðîñòü ñëèçè + FOOT, // 6 - ������ ����� WHEEL, // 7 - WHEEL, // 8 - áåøåíàÿ ïëåñåíü + WHEEL, // 8 - ������� ������� WHEEL, // 9 WHEEL, // 10 WHEEL, // 11 @@ -264,7 +264,7 @@ int Mechos::jump_pad_quant() Vect3f n = getDist(jump_pad_target, R()); n.z = 0; float dist = n.norm(); - features_ &= ~FLYING_BY_JUMP_PAD; // òû ñàì àðêàí + features_ &= ~FLYING_BY_JUMP_PAD; // �� ��� ����� if(dist < jump_pad_finish_radius || (isFlyingByArcane() && !(features() & JABASOMA)) || features() & STATIC_NULIFICATOR){ setGlobalVelocity(0, X_AXIS); setGlobalVelocity(0, Y_AXIS); @@ -298,13 +298,13 @@ void Mechos::jump() if(jump_timer()) return; jump_timer.start(400); - setLocalVelocity(jump_velocity_y, Y_AXIS); // ñêîðîñòü âïåðåä, èãíîðèðóåì ïðåäûäóùóþ ñêîðîñòü - setGlobalVelocity(jump_velocity_z, Z_AXIS); // ñêîðîñòü ââåðõ + setLocalVelocity(jump_velocity_y, Y_AXIS); // �������� ������, ���������� ���������� �������� + setGlobalVelocity(jump_velocity_z, Z_AXIS); // �������� ����� forces.push_back((QuantFunction)&Mechos::jump_quant); } int Mechos::jump_quant() { - setLocalVelocity(jump_velocity_y, Y_AXIS); // ñêîðîñòü âïåðåä, èãíîðèðóåì ïðåäûäóùóþ ñêîðîñòü + setLocalVelocity(jump_velocity_y, Y_AXIS); // �������� ������, ���������� ���������� �������� applyLocalTurnTorque(Zlocal(), Vect3f::K); dragW += Vect3f(3, 3, 3); return jump_timer(); diff --git a/MechoSoma/Xreal/Archimed.cpp b/MechoSoma/Xreal/Archimed.cpp index 52e19f17..795c5787 100644 --- a/MechoSoma/Xreal/Archimed.cpp +++ b/MechoSoma/Xreal/Archimed.cpp @@ -1,7 +1,7 @@ #include "StdAfx.h" #include "Body.h" #include "SimpleClip.h" -#include "terra.h" +#include "TERRA.H" #include "Params.h" void Body::calc_archimedean_force() diff --git a/MechoSoma/Xreal/Ball.cpp b/MechoSoma/Xreal/Ball.cpp index c666b1fb..53da1cdb 100644 --- a/MechoSoma/Xreal/Ball.cpp +++ b/MechoSoma/Xreal/Ball.cpp @@ -2,12 +2,12 @@ #include "BodyDispatcher.h" #include "Mechos.h" #include "Ball.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "sound.h" #include "AnimalArcansPrm.h" -#include "params.h" +#include "Params.h" #include "controls.h" -#include "MechoSoma.h" +#include "mechoSoma.h" void fxlabClownProcess(Vect3f& v); void fxlabBubbleSource(Vect3f& pos,DurationTimer& timer); @@ -43,7 +43,8 @@ void Ball::kill() { if(!alive()) return; - fxlabClownProcess(Vect3f(R())); + Vect3f v1(R()); + fxlabClownProcess(v1); startSound(EFF_CLOWN_BALL); // Ball -> Mechos mechos -> setTrans(R()); mechos -> make_non_colliding(); @@ -55,8 +56,10 @@ void Ball::kill() void Ball::quant() { - if(!wave_timer && submersion()) - fxlabBubbleSource(Vect3f(R()),wave_timer); + if(!wave_timer && submersion()) { + Vect3f v1(R()); + fxlabBubbleSource(v1,wave_timer); + } if(!time_to_live) kill(); if(mechos && kill_mechos){ diff --git a/MechoSoma/Xreal/Body.cpp b/MechoSoma/Xreal/Body.cpp index f8e5e645..50cc9bc7 100644 --- a/MechoSoma/Xreal/Body.cpp +++ b/MechoSoma/Xreal/Body.cpp @@ -8,12 +8,12 @@ #include "Params.h" #include "Mesh3ds.h" #include "sound.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "PolyhedronLibrary.h" -#include "terra.h" +#include "TERRA.H" #include "DebugPrm.h" -#include "Mechosoma.h" -#include "statistics.h" +#include "mechosoma.h" +#include "Statistics.h" #include "CollisionHandler.hpp" const int MIN_BODY_RADIUS = 10; @@ -479,15 +479,22 @@ void Body::setChannelRandom(char* channel) void Body::setAlpha(float alpha) { - xrealIVG -> SetObjectColor(geometry, &sColor4f(geometry -> GetDiffuse().r, geometry -> GetDiffuse().g, geometry -> GetDiffuse().b, alpha)); + sColor4f c1(geometry -> GetDiffuse().r, geometry -> GetDiffuse().g, geometry -> GetDiffuse().b, alpha); + xrealIVG -> SetObjectColor(geometry, &c1); } void Body::setColor(float r, float g, float b) { if(geometry -> GetAttribute(MESH_REFLECTION)) - xrealIVG -> SetObjectColor(geometry, &sColor4f(r, g, b, geometry -> GetDiffuse().a)); + { + sColor4f c1(r, g, b, geometry -> GetDiffuse().a); + xrealIVG -> SetObjectColor(geometry, &c1); + } else - xrealIVG -> SetObjectColor(geometry, 0, &sColor4f(r, g, b, 1)); + { + sColor4f c1(r, g, b, 1); + xrealIVG -> SetObjectColor(geometry, 0, &c1); + } } float Body::H() const diff --git a/MechoSoma/Xreal/Body.h b/MechoSoma/Xreal/Body.h index d532115b..176f3269 100644 --- a/MechoSoma/Xreal/Body.h +++ b/MechoSoma/Xreal/Body.h @@ -6,7 +6,7 @@ #define __BODY_H__ #include "BaseObject.h" -#include "Grid2d.h" +#include "Grid2D.h" #include "SimpleClip.h" extern class cInterfaceVisGeneric* xrealIVG; @@ -157,6 +157,8 @@ class DynamicBody unsigned int in_contact : 1; }; +class FieldSource; + class Body : public DynamicBody, public BaseObject, public Grid2DElement { // Friends diff --git a/MechoSoma/Xreal/BodyDispatcher.cpp b/MechoSoma/Xreal/BodyDispatcher.cpp index 30b995d1..84605b8b 100644 --- a/MechoSoma/Xreal/BodyDispatcher.cpp +++ b/MechoSoma/Xreal/BodyDispatcher.cpp @@ -2,20 +2,20 @@ #include "BodyDispatcher.h" #include "Mechos.h" #include "SimpleClip.h" -#include "params.h" -#include "mesh3ds.h" -#include "Mechosoma.h" +#include "Params.h" +#include "Mesh3ds.h" +#include "mechosoma.h" #include "FieldGrid.h" #include "MultibodyContact.h" #include "BodyFeatureHT.h" #include "PolyhedronLibrary.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "CameraDispatcher.h" #include "IGraph3d.h" #include "Statistics.h" #include "DebugPrm.h" #include "CollisionHandler.hpp" -#include "keys.h" +#include "KEYS.H" #include BodyFactory BodyDispatcher::body_factory; diff --git a/MechoSoma/Xreal/BodyFactory.h b/MechoSoma/Xreal/BodyFactory.h index 2bbb8f26..e1b995d8 100644 --- a/MechoSoma/Xreal/BodyFactory.h +++ b/MechoSoma/Xreal/BodyFactory.h @@ -15,14 +15,10 @@ class GeneralBodyCreator }; -struct eqstr -{ - bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; } -}; -class BodyFactory : hash_map, hash, eqstr> +class BodyFactory : std::unordered_map> { - typedef hash_map, hash, eqstr> HashMap; + typedef std::unordered_map> HashMap; public: BodyFactory(); void add(const char* type_name, GeneralBodyCreator* creator); diff --git a/MechoSoma/Xreal/BodyFeatureHT.h b/MechoSoma/Xreal/BodyFeatureHT.h index 097c1afd..33b395ff 100644 --- a/MechoSoma/Xreal/BodyFeatureHT.h +++ b/MechoSoma/Xreal/BodyFeatureHT.h @@ -5,6 +5,8 @@ #ifndef __BodyFeatureHT_H__ #define __BodyFeatureHT_H__ +#include + struct BodyPair { int first; @@ -23,10 +25,10 @@ struct BodyPairHasher : unary_function } }; -class BodyFeatureHT : public hash_map +class BodyFeatureHT : public std::unordered_map { public: - BodyFeatureHT(int size) : hash_map(size) {} + BodyFeatureHT(int size) : std::unordered_map(size) {} FeaturesList& operator()(const Body& b1, const Body& b2); void check_to_clear(); }; diff --git a/MechoSoma/Xreal/BonusMan.cpp b/MechoSoma/Xreal/BonusMan.cpp index 41d02aaf..eb7739aa 100644 --- a/MechoSoma/Xreal/BonusMan.cpp +++ b/MechoSoma/Xreal/BonusMan.cpp @@ -6,7 +6,7 @@ #include "Mechos.h" #include "BonusMan.h" #include "SimpleClip.h" -#include "params.h" +#include "Params.h" #include "IVisGeneric.h" #include "AnimalArcansPrm.h" @@ -152,7 +152,7 @@ void BonusMan::body_overlap_reaction(Body& body) if(((state == Running || state == Swimming) && body.averageSpeed() > bonus_man_mechos_hit_velocity || state == Paratrooper) && dynamic_cast(body).CheckBonusSlot(bonusID)){ dynamic_cast(body).AddBonus(bonusID); fxlabTakeBonus(bonusID, R()); - // Âûêèäûâàåì ñíîâà + // ���������� ����� setPosition(Vect3f(random(2048), random(2048), frnd(M_PI))); return; } diff --git a/MechoSoma/Xreal/Bubble.cpp b/MechoSoma/Xreal/Bubble.cpp index 5b4b5706..a670ad3d 100644 --- a/MechoSoma/Xreal/Bubble.cpp +++ b/MechoSoma/Xreal/Bubble.cpp @@ -5,10 +5,10 @@ #include "CustomFieldSources.h" #include "Mesh3ds.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "sound.h" #include "AnimalArcansPrm.h" -#include "params.h" +#include "Params.h" void fxlabBubbleBurst(Vect3f& v); @@ -79,6 +79,7 @@ void Bubble::quant() void Bubble::kill() { - fxlabBubbleBurst(Vect3f(R())); + Vect3f v1(R()); + fxlabBubbleBurst(v1); Body::kill(); } diff --git a/MechoSoma/Xreal/CameraClipping.cpp b/MechoSoma/Xreal/CameraClipping.cpp index 3be340e5..675fd257 100644 --- a/MechoSoma/Xreal/CameraClipping.cpp +++ b/MechoSoma/Xreal/CameraClipping.cpp @@ -3,11 +3,11 @@ #include "CameraDispatcher.h" #include "CameraPrm.h" #include "DebugPrm.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "Body.h" -#include "Mechosoma.h" +#include "mechosoma.h" #include "Statistics.h" -#include "xJoystick.h" +#include "XJoystick.h" /////////////////////////////////////////////////////////////////////////////////////////////// // ZBuffer's declarations @@ -47,7 +47,7 @@ class ZBuffer void reset(float z_max); void draw_triangle(Vect3f vv[3]); int find_nearest_point(Vect3f& v, int enable_slope); - int ZBuffer::test_point(int x, int y, int& dist); + int test_point(int x, int y, int& dist); void draw(); }; @@ -64,7 +64,7 @@ void Triangle::draw_to_z_buffer(ZBuffer& z_buffer, const MatXf& sXg, cCamera* ca Vect3f vv[3]; for(int i = 0; i < 3; i++){ vv[i] = getDist(verts[i], sXg.trans()); - vv[i].z -= SHARE_FLOAT(round(sqr(vv[i].x) + sqr(vv[i].y))); + vv[i].z -= SHARE_FLOAT(int(round(sqr(vv[i].x) + sqr(vv[i].y)))); sXg.rot().xform(vv[i]); } z_buffer.draw_triangle(vv); @@ -168,7 +168,7 @@ int CameraDispatcher::new_clip(CameraCoords& coords) sAg.xform(offset); if(z_buffer.find_nearest_point(offset, flags_ & EnableSlope )){ sAg.invXform(offset); - coords.angles.x = fabs(getDist(psi_prev, offset.psi(), 2*M_PI)) < M_PI/2 ? R2G(offset.theta() + atan(coords.CenteringDelta)) : R2G(-offset.theta() + atan(coords.CenteringDelta)); + coords.angles.x = fabs(getDist_f(psi_prev, offset.psi(), 2*M_PI)) < M_PI/2 ? R2G(offset.theta() + atan(coords.CenteringDelta)) : R2G(-offset.theta() + atan(coords.CenteringDelta)); if(flags_ & EnableSlope && R2G(offset.theta()) > camera_min_slope_angle_to_change_psi) coords.angles.z = R2G(M_PI/2 - offset.psi()); coords.rot().xform(offset); @@ -232,7 +232,10 @@ void CameraDispatcher::show() for(int i = 0; i < 4; i++) show_map_line(Vect3f(pX[i], pY[i], 0), Vect3f(pX[(i + 1)%4], pY[(i + 1)%4], 0), RED); - tri_map -> scan_poly(pX, pY, 4, TestOp()); + { + TestOp op; + tri_map -> scan_poly(pX, pY, 4, op); + } if(observer){ show_vector(observer -> R(), XCOL(GREEN)); @@ -328,6 +331,7 @@ void ZBuffer::reset(float z_max) void ZBuffer::draw() { +#ifdef _WIN32 HDC hdc; GetBackBufferDC(&hdc); int y; @@ -358,6 +362,7 @@ void ZBuffer::draw() SetPixel(hdc, x1 + 402 + x_size, y1 + 299, GREEN); ReleaseBackBufferDC(hdc); +#endif } inline int ZBuffer::test_point(int x, int y, int& dist) @@ -439,16 +444,16 @@ void ZBuffer::clip_triangle(Vect3f vv[3], int side) int out_cnt = 0; float dd[3]; for(int i = 0; i < 3; i++) - if((dd[i] = p.dist(vv[i])) < eps){ // ñíàðóæè + if((dd[i] = p.dist(vv[i])) < eps){ // ������� out_cnt++; out = i; } else in = i; switch(out_cnt){ - case 0: // âåñü âíóòðè + case 0: // ���� ������ break; - case 1: { // 1 òî÷êà ñíàðóæè (out) + case 1: { // 1 ����� ������� (out) int i1 = (out + 1) % 3; int i2 = (out + 2) % 3; float d0 = -dd[out]; @@ -458,14 +463,14 @@ void ZBuffer::clip_triangle(Vect3f vv[3], int side) Vect3f v1 = v0 + (vv[i1] - v0)*(d0 + dd[i1] > FLT_EPS ? d0/(d0 + dd[i1]) : 0); Vect3f v2 = v0 + (vv[i2] - v0)*(d0 + dd[i2] > FLT_EPS ? d0/(d0 + dd[i2]) : 0); Vect3f vv2[3]; - if(v1.distance2(vv[i2]) < v2.distance2(vv[i1])){ // ðàçðåçàåì âäîëü v1 - vv[i2] + if(v1.distance2(vv[i2]) < v2.distance2(vv[i1])){ // ��������� ����� v1 - vv[i2] vv2[0] = v1; vv2[1] = vv[i2]; vv2[2] = v2; clip_triangle(vv2, j + 1); vv[out] = v1; } - else{ // ðàçðåçàåì âäîëü v2 - vv[i1] + else{ // ��������� ����� v2 - vv[i1] vv2[0] = v1; vv2[1] = vv[i1]; vv2[2] = v2; @@ -474,7 +479,7 @@ void ZBuffer::clip_triangle(Vect3f vv[3], int side) } } break; - case 2: { // 1 òî÷êà âíóòðè (in) + case 2: { // 1 ����� ������ (in) int i1 = (in + 1) % 3; int i2 = (in + 2) % 3; float d0 = dd[in]; @@ -485,7 +490,7 @@ void ZBuffer::clip_triangle(Vect3f vv[3], int side) vv[i2] = v0 + (vv[i2] - v0)*(d0 - dd[i2] > FLT_EPS ? d0/(d0 - dd[i2]) : 0); } break; - case 3: // âåñü ñíàðóæè + case 3: // ���� ������� return; } } @@ -503,7 +508,7 @@ void ZBuffer::clip_triangle(Vect3f vv[3], int side) assert(vv[i].xi() >= x_min && vv[i].xi() <= x_max && vv[i].yi() >= y_min && vv[i].yi() <= y_max); } - // Ïîèñê âåðõíåé âåðøèíû + // ����� ������� ������� if(vv[0].y > vv[1].y){ Vect3f v = vv[0]; vv[0] = vv[1]; vv[1] = vv[2]; vv[2] = v; if(vv[0].y > vv[1].y){ @@ -515,7 +520,7 @@ void ZBuffer::clip_triangle(Vect3f vv[3], int side) Vect3f v = vv[0]; vv[0] = vv[2]; vv[2] = vv[1]; vv[1] = v; } - // Äâóñòîðîííèé òðåóãîëüíèê + // ������������ ����������� int cross_z = (vv[1].x - vv[0].x)*(vv[2].y - vv[0].y) - (vv[1].y - vv[0].y)*(vv[2].x - vv[0].x); if(fabs((float)cross_z) < 1e-5f) return; diff --git a/MechoSoma/Xreal/CameraDispatcher.cpp b/MechoSoma/Xreal/CameraDispatcher.cpp index 0de14bdd..403f4422 100644 --- a/MechoSoma/Xreal/CameraDispatcher.cpp +++ b/MechoSoma/Xreal/CameraDispatcher.cpp @@ -8,8 +8,8 @@ #include "RenderDevice.h" #include "CameraDispatcher.h" -#include "mesh3ds.h" -#include "params.h" +#include "Mesh3ds.h" +#include "Params.h" #include "SimpleClip.h" #include "CameraPrm.h" #include "Statistics.h" @@ -32,7 +32,7 @@ class FreeFlyBody : public Body /* --------------------------- DEFINITION SECTION --------------------------- */ -char* mch_cameraINI = "RESOURCE\\ISCREEN\\camera.ini"; +char* mch_cameraINI = "RESOURCE/ISCREEN/camera.ini"; char* mch_cameraModeID[CAM_MODE_MAX] = { @@ -135,15 +135,26 @@ CameraDispatcher::CameraDispatcher(cUnknownClass* ivsRenderDevice_) { ivsRenderDevice = ivsRenderDevice_; ivsCamera = (cCamera*)gb_IVisGeneric->CreateCamera(); - gb_IVisGeneric->AttachCamera(ivsCamera); // ïðèñîåäèíåíèå êàìåðû ê àêòèâíîé ñöåíå - gb_IVisGeneric->SetCameraAttribute(ivsCamera,ATTRIBUTE_CAMERA_PERSPECTIVE_WORLD_SHARE_CUTTING); // ñôåðè÷íîñòü âûâîäà è ïåðñïåêòèâà - gb_IVisGeneric->SetCameraPosition(ivsCamera,&Vect3f(0,0,512),&Vect3f(0,0,0)); - gb_IVisGeneric->SetCameraFrustum(ivsCamera, // óñòàíàâëèâàåòñÿ ïèðàìèäà âèäèìîñòè - &Vect2f(0.5f,0.5f), // öåíòð êàìåðû - &sRectangle4f(-0.499f,-0.499f,0.499f,0.499f), // âèäèìàÿ îáëàñòü êàìåðû - &Vect2f(1.0f,1.0f), // ôîêóñ êàìåðû - &Vect2f(10.0f,3000.0f), // áëèæàéøèé è äàëüíèé z-ïëîñêîñòè îòñå÷åíèÿ - &Vect2f(0.2f,0.90f)); // zNear è zFar äëÿ ìàïèðîâàíèÿ â zBuffer + gb_IVisGeneric->AttachCamera(ivsCamera); // ������������� ������ � �������� ����� + gb_IVisGeneric->SetCameraAttribute(ivsCamera,ATTRIBUTE_CAMERA_PERSPECTIVE_WORLD_SHARE_CUTTING); // ����������� ������ � ����������� + { + Vect3f v1(0,0,512); + Vect3f v2(0,0,0); + gb_IVisGeneric->SetCameraPosition(ivsCamera,&v1,&v2); + } + { + Vect2f v1(0.5f,0.5f); + sRectangle4f r1(-0.499f,-0.499f,0.499f,0.499f); + Vect2f v2(1.0f,1.0f); + Vect2f v3(10.0f,3000.0f); + Vect2f v4(0.2f,0.90f); + gb_IVisGeneric->SetCameraFrustum(ivsCamera, // ��������������� �������� ��������� + &v1, // ����� ������ + &r1, // ������� ������� ������ + &v2, // ����� ������ + &v3, // ��������� � ������� z-��������� ��������� + &v4); // zNear � zFar ��� ����������� � zBuffer + } gb_IVisGeneric->AttachCameraViewPort(ivsCamera, ivsRenderDevice); centeringDeltaFactor = 1; @@ -169,7 +180,8 @@ void CameraDispatcher::setWindow(const mchGameWindow* gWnd) { Vect2f Center(((float)gWnd -> CenterX)/XGR_MAXX,((float)gWnd->CenterY)/XGR_MAXY); Vect2f Size((float)gWnd->SizeX2/XGR_MAXX,(float)gWnd->SizeY2/XGR_MAXX); - gb_IVisGeneric->SetCameraFrustum(ivsCamera, &Center, &sRectangle4f(-Size.x,-Size.y,+Size.x,+Size.y), 0, 0, 0); + sRectangle4f r1(-Size.x,-Size.y,+Size.x,+Size.y); + gb_IVisGeneric->SetCameraFrustum(ivsCamera, &Center, &r1, 0, 0, 0); centeringDeltaFactor = (float)gWnd->SizeY/XGR_MAXY; } @@ -177,7 +189,7 @@ CameraDispatcher::~CameraDispatcher() { if(free_fly_body) delete free_fly_body; - gb_IVisGeneric->ReleaseCamera(ivsCamera); // óäàëåíèå íåíóæíîé êàìåðû + gb_IVisGeneric->ReleaseCamera(ivsCamera); // �������� �������� ������ } void CameraDispatcher::clear(void) @@ -314,7 +326,7 @@ class RayCaster float metric(float ps, float th, float rad) { // return (fabs(getDist(ps, psi, 2*M_PI)) + fabs(th - theta))*z_distance + fabs(rad - z_distance); - return (camera_theta_dominance*sqr(getDist(ps, psi, 2*M_PI)) + sqr(th - theta))*sqr(z_distance) + sqr(rad - z_distance); + return (camera_theta_dominance*sqr(getDist_f(ps, psi, 2*M_PI)) + sqr(th - theta))*sqr(z_distance) + sqr(rad - z_distance); } int cast(float ps, float th) @@ -477,7 +489,7 @@ CameraCoords CameraCoords::operator * (float t) const float CameraCoords::distance(const CameraCoords& c) const { - return ::sqrt(getDist(position, c.position).norm2() + (sqr(G2R(angles.x - c.angles.x)) + sqr(G2R(angles.y - c.angles.y)) + sqr(G2R(getDist(angles.z, c.angles.z, 360))))*cameraDistance*c.cameraDistance + sqr(cameraDistance - c.cameraDistance)); + return ::sqrt(getDist(position, c.position).norm2() + (sqr(G2R(angles.x - c.angles.x)) + sqr(G2R(angles.y - c.angles.y)) + sqr(G2R(getDist_f(angles.z, c.angles.z, 360))))*cameraDistance*c.cameraDistance + sqr(cameraDistance - c.cameraDistance)); } CameraCoords& CameraCoords::cycle() @@ -523,7 +535,7 @@ CameraCoords getDist(const CameraCoords& c1, const CameraCoords& c0) coords.position = getDist(c1.position, c0.position); coords.angles.x = c1.angles.x - c0.angles.x; coords.angles.y = c1.angles.y - c0.angles.y; - coords.angles.z = getDist(c1.angles.z, c0.angles.z, 360.f); + coords.angles.z = getDist_f(c1.angles.z, c0.angles.z, 360.f); coords.cameraDistance = c1.cameraDistance - c0.cameraDistance; coords.CenteringDelta = c1.CenteringDelta - c0.CenteringDelta; coords.time = c1.time - c0.time; @@ -622,7 +634,7 @@ CameraCoords CameraDispatcher::bodyInput() if(!is_interpolating_timer){ targetCoords().position = position; if(input_mode == BodyInput){ - if(interpolate_position_timer() && !fly_around_angle_incr){ // îòñòàâàíèå íà ñïîòå + if(interpolate_position_timer() && !fly_around_angle_incr){ // ���������� �� ����� float t = spot_acc_time - interpolate_position_timer(); // 0 - spot_acc_time t = t < spot_acc_front ? t/spot_acc_front : 1.f - (t - spot_acc_front)/(spot_acc_time - spot_acc_front); // 0 - 1 - 0 targetCoords().position += getDist(currentCoords.position, targetCoords().position)*t; @@ -656,7 +668,7 @@ CameraCoords CameraDispatcher::bodyInput() coords.angles.x = fly_slope; } - // Ïðîçðà÷íîñòü ïðè ïðèáëèæåíèè + // ������������ ��� ����������� if(currentCoords.cameraDistance < camera_transparensy_distance){ const_cast(advanced_observer) -> setPermanentAlpha(pow(currentCoords.cameraDistance/camera_transparensy_distance, camera_transparensy_power)); observer_transparent = 1; @@ -974,7 +986,7 @@ void CameraDispatcher::integration(CameraCoords& current, const CameraCoords& in else{ if(fabs(cliped_input.angles.x - current.angles.x) + 0.01f < fabs(cliped_input.angles.x - input.angles.x) + fabs(current.angles.x - input.angles.x)) mass_inv.angles.x = cliped_input.angles.x > input.angles.x ? camera_slope_mass_inv_cliped_up : camera_slope_mass_inv_cliped_down; - if(fabs(getDist(cliped_input.angles.z, current.angles.z, 360)) + 0.01f < fabs(getDist(cliped_input.angles.z, input.angles.z, 360)) + fabs(getDist(current.angles.z, input.angles.z, 360))) + if(fabs(getDist_f(cliped_input.angles.z, current.angles.z, 360)) + 0.01f < fabs(getDist_f(cliped_input.angles.z, input.angles.z, 360)) + fabs(getDist_f(current.angles.z, input.angles.z, 360))) mass_inv.angles.z = camera_turn_mass_inv_cliped; } @@ -1083,7 +1095,7 @@ void CameraDispatcher::setCoords(const Vect3f& vCamera_, const Vect3f& vTarget_) currentCoords.position = vTarget; currentCoords.CenteringDelta = 0; - Vect3f z_axis = vCamera - vTarget; // Ñìîòðèì íàîáîðîò, ò.ê. Mat3f::ID ñìîòðèò âíèç + Vect3f z_axis = vCamera - vTarget; // ������� ��������, �.�. Mat3f::ID ������� ���� currentCoords.cameraDistance = z_axis.norm(); z_axis /= currentCoords.cameraDistance; Vect3f x_axis = z_axis % Vect3f::K; @@ -1107,7 +1119,7 @@ void CameraDispatcher::setCoords(const Vect3f& vCamera_, const Vect3f& vTarget_) void CameraDispatcher::setIvsCamera(const CameraCoords& coords) { - Vect3f vg = coords.position; // Òî÷êà, êîòîðàÿ áóäåò íàõîäèòüñÿ íà ýêðàíå [0, CenteringDelta*SizeY/2, H] + Vect3f vg = coords.position; // �����, ������� ����� ���������� �� ������ [0, CenteringDelta*SizeY/2, H] Mat3f R = coords.rot(); @@ -1128,7 +1140,7 @@ void CameraDispatcher::setIvsCamera(const CameraCoords& coords) gb_IVisGeneric->ClearCameraAttribute(ivsCamera, ATTRIBUTE_CAMERA_WORLD_SHARE); #endif - // Òîëüêî äëÿ ÷òåíèÿ + // ������ ��� ������ mchCameraAX = coords.angles.x; mchCameraAY = coords.angles.y; mchCameraAZ = coords.angles.z; @@ -1389,8 +1401,10 @@ CameraCoords CameraDispatcher::stopTimeInput() } else{ Vect3f pv, pe, pe0(XGR_MouseObj.PosX, XGR_MouseObj.PosY, 0); - + +#ifdef _WIN32 _controlfp(_PC_53, _MCW_PC); +#endif if(hCamera > stop_time_hCamera){ Vect2f ScrSize = ((cRenderDevice*)ivsRenderDevice) -> GetSize(); Vect2f Center = ivsCamera -> GetCenter()*ScrSize; diff --git a/MechoSoma/Xreal/Cannon.cpp b/MechoSoma/Xreal/Cannon.cpp index 1b9fb59c..c0f0de44 100644 --- a/MechoSoma/Xreal/Cannon.cpp +++ b/MechoSoma/Xreal/Cannon.cpp @@ -2,9 +2,9 @@ #include "Body.h" #include "Meteorite.h" #include "Cannon.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "Mesh3ds.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include #pragma hdrstop @@ -28,7 +28,9 @@ Cannon::Cannon(cMesh* model_) model->SetFrame(); } -void fxCannonFire(Vect3f pos,Vect3f vel,float pow); +void fxCannonFire(Vect3f pos,Vect3f vel,float pow) +{ +} void Cannon::fire() { diff --git a/MechoSoma/Xreal/Clown.cpp b/MechoSoma/Xreal/Clown.cpp index 06437ea8..dc460f6d 100644 --- a/MechoSoma/Xreal/Clown.cpp +++ b/MechoSoma/Xreal/Clown.cpp @@ -47,12 +47,16 @@ void Clown::body_overlap_reaction(Body& body) if(body.type() == MECHOS && body.completed() && owner() != body.ID && !job_latency && body.life_time() > 6000){ Mdisp -> attachBody(new Ball(&body)); job_latency.start(300); - fxlabClownProcess(Vect3f(R())); + Vect3f v1(R()); + fxlabClownProcess(v1); } } void Clown::quant() { if(!wave_timer && submersion()) - fxlabBubbleSource(Vect3f(R()),wave_timer); + { + Vect3f v1(R()); + fxlabBubbleSource(v1,wave_timer); + } } diff --git a/MechoSoma/Xreal/Contact.cpp b/MechoSoma/Xreal/Contact.cpp index e4d66e54..6a6026e6 100644 --- a/MechoSoma/Xreal/Contact.cpp +++ b/MechoSoma/Xreal/Contact.cpp @@ -1,7 +1,7 @@ #include "StdAfx.h" #include "Body.h" #include "SimpleClip.h" -#include "params.h" +#include "Params.h" #include "CollisionHandler.hpp" const int contacts_vector_size_max = 300; diff --git a/MechoSoma/Xreal/Contact.h b/MechoSoma/Xreal/Contact.h index 1011fcff..d45ddd17 100644 --- a/MechoSoma/Xreal/Contact.h +++ b/MechoSoma/Xreal/Contact.h @@ -75,7 +75,7 @@ class ContactRef int index; public: ContactRef(int index_, ContactList& contacts_) : index(index_), contacts(&contacts_) {} - Contact* operator->() { return contacts -> begin() + index; } + Contact* operator->() { return contacts -> data() + index; } }; typedef vector ContactList2; diff --git a/MechoSoma/Xreal/ControlledObject.cpp b/MechoSoma/Xreal/ControlledObject.cpp index 111ac21e..c75ffdf8 100644 --- a/MechoSoma/Xreal/ControlledObject.cpp +++ b/MechoSoma/Xreal/ControlledObject.cpp @@ -2,7 +2,7 @@ #include "BodyDispatcher.h" #include "Body.h" #include "ControlledObject.h" -#include "params.h" +#include "Params.h" #include "DebugPrm.h" ControlledObject::ControlledObject() diff --git a/MechoSoma/Xreal/ControlledObject.h b/MechoSoma/Xreal/ControlledObject.h index 6f624a23..1b4b2b1b 100644 --- a/MechoSoma/Xreal/ControlledObject.h +++ b/MechoSoma/Xreal/ControlledObject.h @@ -61,4 +61,4 @@ class AttackAndHomeObject : virtual public ControlledObject DurationTimer turn_latency; }; -#endif __CONTROLLED_OBJECT_H__ +#endif // __CONTROLLED_OBJECT_H__ diff --git a/MechoSoma/Xreal/Crystal.cpp b/MechoSoma/Xreal/Crystal.cpp index 15e4bcbe..980b5add 100644 --- a/MechoSoma/Xreal/Crystal.cpp +++ b/MechoSoma/Xreal/Crystal.cpp @@ -1,14 +1,14 @@ //////////////////////////////////////////////////////////////////// -// Êðèñòàëë +// �������� //////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "Body.h" #include "Crystal.h" #include "Contact.h" -#include "params.h" +#include "Params.h" -#include "mesh3ds.h" -#include "m3d_effects.h" +#include "Mesh3ds.h" +#include "M3d_effects.h" #include "sound.h" #include "AnimalArcansPrm.h" diff --git a/MechoSoma/Xreal/CycledMath.h b/MechoSoma/Xreal/CycledMath.h index b1ce5c63..cdc6131b 100644 --- a/MechoSoma/Xreal/CycledMath.h +++ b/MechoSoma/Xreal/CycledMath.h @@ -9,7 +9,7 @@ const float V_SIZE_FLT = 2048.f; const double H_SIZE_DBL = 2048.; const double V_SIZE_DBL = 2048.; -inline double getDistX(double v0,double v1) +inline double getDistX_d(double v0,double v1) { double d = v0 - v1; double ad = fabs(d); @@ -18,7 +18,7 @@ inline double getDistX(double v0,double v1) return d < 0 ? d + H_SIZE_DBL : d - H_SIZE_DBL; } -inline double getDistY(double v0,double v1) +inline double getDistY_d(double v0,double v1) { double d = v0 - v1; double ad = fabs(d); @@ -27,7 +27,7 @@ inline double getDistY(double v0,double v1) return d < 0 ? d + V_SIZE_DBL : d - V_SIZE_DBL; } -inline float getDistX(float v0,float v1) +inline float getDistX_f(float v0,float v1) { float d = v0 - v1; float ad = (float)fabs(d); @@ -36,7 +36,7 @@ inline float getDistX(float v0,float v1) return d < 0 ? d + H_SIZE_FLT : d - H_SIZE_FLT; } -inline float getDistY(float v0,float v1) +inline float getDistY_f(float v0,float v1) { float d = v0 - v1; float ad = (float)fabs(d); @@ -51,7 +51,7 @@ inline float& cycle(float& f, float size) return f; } -inline float getDist(float v0, float v1, float size) +inline float getDist_f(float v0, float v1, float size) { float d = fmod(v0 - v1, size); float ad = (float)fabs(d); @@ -62,7 +62,7 @@ inline float getDist(float v0, float v1, float size) inline float& uncycle(float& f1, float f0, float size) { - f1 = f0 + getDist(f1, f0, size); + f1 = f0 + getDist_f(f1, f0, size); return f1; } @@ -78,7 +78,7 @@ inline Vect3d& CYCLE(Vect3d &R) } inline Vect3d getDist(const Vect3d &P1,const Vect3d &P0) { - return Vect3d( getDistX(P1.x,P0.x), getDistY(P1.y,P0.y), P1.z - P0.z ); + return Vect3d( getDistX_d(P1.x,P0.x), getDistY_d(P1.y,P0.y), P1.z - P0.z ); } inline Vect3d getDelta(const Vect3d &P1,const Vect3d &P0) { @@ -86,14 +86,14 @@ inline Vect3d getDelta(const Vect3d &P1,const Vect3d &P0) } inline Vect3d& UNCYCLE(Vect3d &P1,const Vect3d &P0) { - P1.x = P0.x + getDistX(P1.x, P0.x); - P1.y = P0.y + getDistY(P1.y, P0.y); + P1.x = P0.x + getDistX_d(P1.x, P0.x); + P1.y = P0.y + getDistY_d(P1.y, P0.y); return P1; } inline Vect3d getUNCYCLED(const Vect3d &P1,const Vect3d &P0) { - return Vect3d (P0.x + getDistX(P1.x, P0.x), - P0.y + getDistY(P1.y, P0.y), + return Vect3d (P0.x + getDistX_d(P1.x, P0.x), + P0.y + getDistY_d(P1.y, P0.y), P1.z); } @@ -108,7 +108,7 @@ inline Vect3f& CYCLE(Vect3f &R) } inline Vect3f getDist(const Vect3f &P1,const Vect3f &P0) { - return Vect3f( getDistX(P1.x,P0.x), getDistY(P1.y,P0.y), P1.z - P0.z ); + return Vect3f( getDistX_f(P1.x,P0.x), getDistY_f(P1.y,P0.y), P1.z - P0.z ); } inline Vect3f getDelta(const Vect3f &P1,const Vect3f &P0) { @@ -116,14 +116,14 @@ inline Vect3f getDelta(const Vect3f &P1,const Vect3f &P0) } inline Vect3f& UNCYCLE(Vect3f &P1,const Vect3f &P0) { - P1.x = P0.x + getDistX(P1.x, P0.x); - P1.y = P0.y + getDistY(P1.y, P0.y); + P1.x = P0.x + getDistX_f(P1.x, P0.x); + P1.y = P0.y + getDistY_f(P1.y, P0.y); return P1; } inline Vect3f getUNCYCLED(const Vect3f &P1,const Vect3f &P0) { - return Vect3f (P0.x + getDistX(P1.x, P0.x), - P0.y + getDistY(P1.y, P0.y), + return Vect3f (P0.x + getDistX_f(P1.x, P0.x), + P0.y + getDistY_f(P1.y, P0.y), P1.z); } diff --git a/MechoSoma/Xreal/Debris.cpp b/MechoSoma/Xreal/Debris.cpp index 9689fe56..09fcd692 100644 --- a/MechoSoma/Xreal/Debris.cpp +++ b/MechoSoma/Xreal/Debris.cpp @@ -2,7 +2,7 @@ #include "BodyDispatcher.h" #include "Body.h" #include "Debris.h" -#include "params.h" +#include "Params.h" #include "AnimalsPrm.h" #include "Mesh3ds.h" diff --git a/MechoSoma/Xreal/Dragon.cpp b/MechoSoma/Xreal/Dragon.cpp index 582fcc80..6461b6dd 100644 --- a/MechoSoma/Xreal/Dragon.cpp +++ b/MechoSoma/Xreal/Dragon.cpp @@ -3,8 +3,8 @@ #include "Mechos.h" #include "Dragon.h" #include "M3d_effects.h" -#include "mesh3ds.h" -#include "params.h" +#include "Mesh3ds.h" +#include "Params.h" #include "AnimalsPrm.h" #include "M3d_effects.h" diff --git a/MechoSoma/Xreal/Dynamics.cpp b/MechoSoma/Xreal/Dynamics.cpp index 8666534e..f0a63a8a 100644 --- a/MechoSoma/Xreal/Dynamics.cpp +++ b/MechoSoma/Xreal/Dynamics.cpp @@ -3,10 +3,10 @@ #include "Body.h" #include "SimpleClip.h" #include "MultibodyContact.h" -#include "params.h" -#include "xreal_utl.h" +#include "Params.h" +#include "Xreal_utl.h" #include "LCP_ContactSolver.h" -#include "Mechosoma.h" +#include "mechosoma.h" #include "Statistics.h" #include "QuatMath.h" diff --git a/MechoSoma/Xreal/EvilEye.cpp b/MechoSoma/Xreal/EvilEye.cpp index 47207944..f66f1a2f 100644 --- a/MechoSoma/Xreal/EvilEye.cpp +++ b/MechoSoma/Xreal/EvilEye.cpp @@ -2,7 +2,7 @@ #include "BodyDispatcher.h" #include "Mechos.h" #include "EvilEye.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "sound.h" #include "AnimalArcansPrm.h" @@ -12,7 +12,7 @@ EvilEye::EvilEye() : Body(myM3DType(10), CenteredScaledBy2Bound) { type_ = EVIL_EYE; - //attack_latency.start(evil_eye_attack_latency_time); // æäåò äî ïåðâîé àòàêè + //attack_latency.start(evil_eye_attack_latency_time); // ���� �� ������ ����� setAnimation(evil_eye_period); time_to_live.start(evil_eye_time_to_live); make_non_dynamic = 0; @@ -49,39 +49,39 @@ void EvilEye::body_overlap_reaction(Body& body) if(r.norm() > d) r.normalize(d); victim = &body; - time_to_explode.start(min(time_to_live(), evil_eye_time_to_explode)); // Âðåìÿ äî âçðûâà + time_to_explode.start(min(time_to_live(), evil_eye_time_to_explode)); // ����� �� ������ startSound(EFF_EVIL_EYE_ATTACK); } } void EvilEye::non_dynamic_evolve(float dt) { - // Ïðèëèïøèé + // ��������� setPose(victim -> pose()*Xem); if(victim -> completed()){ - if(time_to_explode()){ // ïðèøëî âðåìÿ + if(time_to_explode()){ // ������ ����� victim -> damage(1000); fxlabTitaniumExplosion(this); - kill(); // âçðûâàåò ìåõîñ + kill(); // �������� ����� } else{ - if(dynamic_cast(victim()) -> isFlyingByArcane() || !victim -> visible()){ // îòëèïàåò + if(dynamic_cast(victim()) -> isFlyingByArcane() || !victim -> visible()){ // �������� is_dynamic_ = 1; make_non_colliding(); - attack_latency.start(evil_eye_attack_latency_time); // æäåò äî ñëåäóþùåé àòàêè + attack_latency.start(evil_eye_attack_latency_time); // ���� �� ��������� ����� stopSound(EFF_EVIL_EYE_ADD); } } } else - kill(); // ìåõîñ ðàçâàëèëñÿ ñàì + kill(); // ����� ���������� ��� } void EvilEye::calc_forces_and_drags() { Body::calc_forces_and_drags(); - // Æäóùèé æåðòâó + // ������ ������ if(!attack_latency && !jump_latency && (colliding() || submersion() > 0.1)){ Body* body = Mdisp -> searchBody(R(), MECHOS); if(body && (!body -> completed() || body -> ID == owner())){ @@ -91,7 +91,7 @@ void EvilEye::calc_forces_and_drags() } if(body){ Vect3f dr = getDist(body -> R(), R()); - if(dr.norm() < evil_eye_attack_distance){ // ïîïàë â çîíó àòàêè + if(dr.norm() < evil_eye_attack_distance){ // ����� � ���� ����� dr.z += evil_eye_delta_z; dr *= evil_eye_velocity_factor; setGlobalVelocity(dr); diff --git a/MechoSoma/Xreal/FieldGrid.cpp b/MechoSoma/Xreal/FieldGrid.cpp index 9644f389..20ca3068 100644 --- a/MechoSoma/Xreal/FieldGrid.cpp +++ b/MechoSoma/Xreal/FieldGrid.cpp @@ -63,7 +63,8 @@ class BodyAffectOp void FieldGrid::affect(Body& body) const { - scan(body.getBound(), BodyAffectOp(body)); + BodyAffectOp op(body); + scan(body.getBound(), op); } diff --git a/MechoSoma/Xreal/FieldGrid.h b/MechoSoma/Xreal/FieldGrid.h index bc25a513..d3e402f9 100644 --- a/MechoSoma/Xreal/FieldGrid.h +++ b/MechoSoma/Xreal/FieldGrid.h @@ -2,16 +2,18 @@ #ifndef __FIELD_GRID__ #define __FIELD_GRID__ +#include + #include "Body.h" #include "Grid2D.h" #include "FieldSource.h" class FieldGridBase : public Grid2D {}; -class FieldGrid : public slist >, public FieldGridBase +class FieldGrid : public std::list >, public FieldGridBase { public: - typedef slist > List; + typedef std::list > List; typedef FieldGridBase Grid; void add(FieldSource* source); diff --git a/MechoSoma/Xreal/FieldSource.cpp b/MechoSoma/Xreal/FieldSource.cpp index 9659d0ad..b5aec60f 100644 --- a/MechoSoma/Xreal/FieldSource.cpp +++ b/MechoSoma/Xreal/FieldSource.cpp @@ -2,13 +2,13 @@ #include "Body.h" #include "CustomFieldSources.h" #include "Params.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "ArcansPrm.h" #include "AnimalArcansPrm.h" #include "Mechos.h" ////////////////////////////////////////////////////////////////// -// Îáùèé Òî÷å÷íûé Èñòî÷íèê +// ����� �������� �������� ////////////////////////////////////////////////////////////////// GeneralFieldSource::GeneralFieldSource(const Vect3f& r_, float radius_, float attraction_force_, float lift_force_, const Vect3f& vortical_force_, const Vect3f& torque_, int owner_ID_) @@ -21,7 +21,7 @@ GeneralFieldSource::GeneralFieldSource(const Vect3f& r_, float radius_, float at } ////////////////////////////////////////////////////////////////// -// Âèõðü +// ����� ////////////////////////////////////////////////////////////////// VortexFieldSource::VortexFieldSource(const Vect3f& r_, float radius_, int owner_ID_, float factor, int clock_wise) : GeneralFieldSource(r_, radius_, k_vortex_attraction, k_vortex_lift, @@ -65,7 +65,7 @@ void VortexFieldSource::affect(Body& b) const } ////////////////////////////////////////////////////////////////// -// Ìàãíèòíîå ïîëå +// ��������� ���� ////////////////////////////////////////////////////////////////// MagneticFieldSource::MagneticFieldSource(const Vect3f& r_, float radius_, int owner_ID_) : GeneralFieldSource(r_, radius_, -magnetic_field_repulsion, 0, @@ -97,7 +97,7 @@ void MagneticFieldSource::affect(Body& b) const } ////////////////////////////////////////////////////////////////// -// Ïðèòÿæåíèå +// ���������� ////////////////////////////////////////////////////////////////// AttractionFieldSource::AttractionFieldSource(const Vect3f& r_, float radius_, int owner_ID_) : GeneralFieldSource(r_, radius_, k_attraction_arcan, 0, @@ -129,7 +129,7 @@ void AttractionFieldSource::affect(Body& b) const } ///////////////////////////////////////////////////////////////////////////////////////// -// Ïðèòÿæåíèå, ñôåðà +// ����������, ����� ///////////////////////////////////////////////////////////////////////////////////////// BubbleFieldSource::BubbleFieldSource(const Vect3f& r_, float radius_, int owner_ID_) : GeneralFieldSource(r_, radius_, 6, 0, diff --git a/MechoSoma/Xreal/FirePoint.cpp b/MechoSoma/Xreal/FirePoint.cpp index 5edd7d02..735592f9 100644 --- a/MechoSoma/Xreal/FirePoint.cpp +++ b/MechoSoma/Xreal/FirePoint.cpp @@ -1,10 +1,10 @@ #include "StdAfx.h" #include "FirePoint.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "HashStringGroup.h" ////////////////////////////////////////////////////////////////////////// -// Êîíñòðóêòîðà +// ������������ ////////////////////////////////////////////////////////////////////////// typedef FirePoint* (*FirePointConstructor)(const Vect3f& dummyA, const Vect3f& dummyB); @@ -39,7 +39,7 @@ FirePoint* FountainConstructor(const Vect3f& dummyA, const Vect3f& dummyB) } ////////////////////////////////////////////////////////////////////////// -// Hash-table òèïîâ +// Hash-table ����� ////////////////////////////////////////////////////////////////////////// struct FirePointType { diff --git a/MechoSoma/Xreal/FirePoint.h b/MechoSoma/Xreal/FirePoint.h index 47b4e7aa..8784e0ba 100644 --- a/MechoSoma/Xreal/FirePoint.h +++ b/MechoSoma/Xreal/FirePoint.h @@ -29,7 +29,7 @@ struct FirePoint : Vect3f { }; }; -void fxlabCannonFire(Vect3f& pos,Vect3f& vel,float pow); +void fxlabCannonFire(const Vect3f& pos,Vect3f& vel,float pow); struct CannonPoint : FirePoint { @@ -49,7 +49,8 @@ struct CannonPoint : FirePoint bodyPose.xformVect(direction, d); CYCLE(v); - fxlabCannonFire(v,d*(4 + fabsRnd(4)),2000); + Vect3f v1(d*(4 + fabsRnd(4))); + fxlabCannonFire(v,v1,2000); }; }; }; diff --git a/MechoSoma/Xreal/FixedPathBody.cpp b/MechoSoma/Xreal/FixedPathBody.cpp index 21afb9f4..6a42620d 100644 --- a/MechoSoma/Xreal/FixedPathBody.cpp +++ b/MechoSoma/Xreal/FixedPathBody.cpp @@ -1,15 +1,20 @@ +#include + #include "StdAfx.h" #include "BodyDispatcher.h" #include "SimpleClip.h" #include "FixedPathBody.h" #include "Mesh3ds.h" -#include "params.h" +#include "Params.h" #include "sound.h" #include "CameraPrm.h" #include "QuatMath.h" +#ifndef _WIN32 +#include "port.h" +#endif -class SoundTable : hash_map +class SoundTable : std::unordered_map { public: SoundTable() diff --git a/MechoSoma/Xreal/Forest_world.cpp b/MechoSoma/Xreal/Forest_world.cpp index 1bceb69e..97b4aa57 100644 --- a/MechoSoma/Xreal/Forest_world.cpp +++ b/MechoSoma/Xreal/Forest_world.cpp @@ -4,8 +4,9 @@ #include "Mechos.h" #include "CrawlingObject.h" #include "Worm.h" -#include "params.h" -#include "algorithm" +#include "Params.h" + +#include const int NumWorms = 12; @@ -34,8 +35,7 @@ void ForestWorld::pre_quant() BodyDispatcher::pre_quant(); if(!isSnow() && !quant_latency){ quant_latency.start(1000); - int num = 0; - count_if(total_bodies.begin(), total_bodies.end(), IsWorm(), num); + int num = std::count_if(total_bodies.begin(), total_bodies.end(), IsWorm()); if(num < NumWorms) createBody("Worm", Vect3f(random(2047), random(2047), 0)); } diff --git a/MechoSoma/Xreal/Frog.cpp b/MechoSoma/Xreal/Frog.cpp index baeb7fda..1fb7e9ce 100644 --- a/MechoSoma/Xreal/Frog.cpp +++ b/MechoSoma/Xreal/Frog.cpp @@ -4,7 +4,7 @@ #include "Mesh3ds.h" #include "PointControlledObject.h" #include "Frog.h" -#include "params.h" +#include "Params.h" #include "sound.h" #include "AnimalsPrm.h" diff --git a/MechoSoma/Xreal/Grid2D.h b/MechoSoma/Xreal/Grid2D.h index c2e313d3..85f794b1 100644 --- a/MechoSoma/Xreal/Grid2D.h +++ b/MechoSoma/Xreal/Grid2D.h @@ -1,8 +1,8 @@ #ifndef __GRID_2D__ #define __GRID_2D__ -#include -#include "xreal_utl.h" +#include +#include "Xreal_utl.h" ///////////////////////////////////////// // Integer Rectangle @@ -86,6 +86,7 @@ struct Grid2DConfig { template class Grid2D : PassDispatcher, Grid2DConfig { + using G2D = Grid2DConfig; public: class Node { @@ -99,67 +100,67 @@ class Grid2D : PassDispatcher, Grid2DConfig short dy() const { return dy_; } }; - typedef slist SList; + using SList = std::list; //////////////////////////////////////////////////////////////////////////////////// // Insertion & removing //////////////////////////////////////////////////////////////////////////////////// void insert(const T& obj, iRectangle rect) { - prep_rectangle(rect); + G2D::prep_rectangle(rect); for(int y = rect.y0;y <= rect.y1;y++) for(int x = rect.x0;x <= rect.x1;x++) - if(obj.belongSquare(x*cell_sx, y*cell_sy, cell_sx, cell_sy)) - table[mask_y(y)][mask_x(x)].push_front( Node(&obj, cycling_dx(x), cycling_dy(y)) ); + if(obj.belongSquare(x*G2D::cell_sx, y*G2D::cell_sy, G2D::cell_sx, G2D::cell_sy)) + table[G2D::mask_y(y)][G2D::mask_x(x)].push_front( Node(&obj, G2D::cycling_dx(x), G2D::cycling_dy(y)) ); } void erase(const T& obj, iRectangle rect) { - prep_rectangle(rect); + G2D::prep_rectangle(rect); for(int y = rect.y0;y <= rect.y1;y++) for(int x = rect.x0;x <= rect.x1;x++) - table[mask_y(y)][mask_x(x)].remove( Node(&obj, cycling_dx(x), cycling_dy(y)) ); + table[G2D::mask_y(y)][G2D::mask_x(x)].remove( Node(&obj, G2D::cycling_dx(x), G2D::cycling_dy(y)) ); } void move(const T& obj, iRectangle prev_rect, iRectangle rect) { - prep_rectangle(rect); - prep_rectangle(prev_rect); + G2D::prep_rectangle(rect); + G2D::prep_rectangle(prev_rect); if(rect == prev_rect) return; int y; for(y = prev_rect.y0;y <= prev_rect.y1;y++) for(int x = prev_rect.x0;x <= prev_rect.x1;x++) - table[mask_y(y)][mask_x(x)].remove( Node(&obj, cycling_dx(x), cycling_dy(y)) ); + table[G2D::mask_y(y)][G2D::mask_x(x)].remove( Node(&obj, G2D::cycling_dx(x), G2D::cycling_dy(y)) ); for(y = rect.y0;y <= rect.y1;y++) for(int x = rect.x0;x <= rect.x1;x++) - if(obj.belongSquare(x*cell_sx, y*cell_sy, cell_sx, cell_sy)) - table[mask_y(y)][mask_x(x)].push_front( Node(&obj, cycling_dx(x), cycling_dy(y)) ); + if(obj.belongSquare(x*G2D::cell_sx, y*G2D::cell_sy, G2D::cell_sx, G2D::cell_sy)) + table[G2D::mask_y(y)][G2D::mask_x(x)].push_front( Node(&obj, G2D::cycling_dx(x), G2D::cycling_dy(y)) ); } void clear() { - for(int y = 0;y < sy;y++) - for(int x = 0;x < sx;x++) + for(int y = 0;y < G2D::sy;y++) + for(int x = 0;x < G2D::sx;x++) table[y][x].clear(); } //////////////////////////////////////////////////////////////////////////////////// // Accessing //////////////////////////////////////////////////////////////////////////////////// - SList& operator() (int x, int y) { return table[masked_prep_y(y)][masked_prep_x(x)]; } + SList& operator() (int x, int y) { return table[G2D::masked_prep_y(y)][G2D::masked_prep_x(x)]; } template void scan(iRectangle rect, Op& op) const { beginPass(); - prep_rectangle(rect); + G2D::prep_rectangle(rect); for(int y = rect.y0;y <= rect.y1;y++){ - short dy = cycling_dy(y); + short dy = G2D::cycling_dy(y); for(int x = rect.x0;x <= rect.x1;x++){ - short dx = cycling_dx(x); - const SList& root = table[mask_y(y)][mask_x(x)]; - SList::const_iterator i; + short dx = G2D::cycling_dx(x); + const SList& root = table[G2D::mask_y(y)][G2D::mask_x(x)]; + typename SList::const_iterator i; FOR_EACH(root, i) if(doPass(**i)) op(**i, dx - i -> dx(), dy - i -> dy()); @@ -170,10 +171,10 @@ class Grid2D : PassDispatcher, Grid2DConfig template int process_cell(int x, int y, Op& op) const { - short dx = cycling_dx(x); - short dy = cycling_dy(y); - const SList& root = table[mask_y(y)][mask_x(x)]; - SList::const_iterator i; + short dx = G2D::cycling_dx(x); + short dy = G2D::cycling_dy(y); + const SList& root = table[G2D::mask_y(y)][G2D::mask_x(x)]; + typename SList::const_iterator i; FOR_EACH(root, i) if(doPass(**i)) if(!op(**i, dx - i -> dx(), dy - i -> dy())) @@ -188,7 +189,7 @@ class Grid2D : PassDispatcher, Grid2DConfig const int F_PREC = 16; iRectangle rect(x1_, y1_, x2_, y2_); - prep_rectangle(rect); + G2D::prep_rectangle(rect); int x1 = rect.x0; int y1 = rect.y0; int x2 = rect.x1; @@ -262,8 +263,8 @@ class Grid2D : PassDispatcher, Grid2DConfig int i; for(i = 0; i < n; i++){ - pX[i] >>= shift_x; - pY[i] >>= shift_y; + pX[i] >>= G2D::shift_x; + pY[i] >>= G2D::shift_y; } int vals_up = 0; @@ -355,16 +356,16 @@ class Grid2D : PassDispatcher, Grid2DConfig void show(int x, int y) const { beginPass(); - int x0 = masked_prep_x(x); - int y0 = masked_prep_y(y); + int x0 = G2D::masked_prep_x(x); + int y0 = G2D::masked_prep_y(y); const SList& root = table[y0][x0]; - SList::const_iterator i; + typename SList::const_iterator i; FOR_EACH(root, i) if(doPass(**i)) (*i) -> show(); - Vect3f p0(x0*cell_sx, y0*cell_sy, 0); - Vect3f dx(cell_sx, 0, 0); - Vect3f dy(0, cell_sy, 0); + Vect3f p0(x0*G2D::cell_sx, y0*G2D::cell_sy, 0); + Vect3f dx(G2D::cell_sx, 0, 0); + Vect3f dy(0, G2D::cell_sy, 0); show_vector(p0, p0 + dx, p0 + dx + dy, p0 + dy, XCOL(CYAN, 100)); } @@ -372,19 +373,19 @@ class Grid2D : PassDispatcher, Grid2DConfig { beginPass(); iRectangle rect(xc - sz, yc - sz, xc + sz, yc + sz); - prep_rectangle(rect); + G2D::prep_rectangle(rect); for(int y = rect.y0;y <= rect.y1;y++) for(int x = rect.x0;x <= rect.x1;x++){ - const SList& root = table[mask_y(y)][mask_x(x)]; - SList::const_iterator i; + const SList& root = table[G2D::mask_y(y)][G2D::mask_x(x)]; + typename SList::const_iterator i; FOR_EACH(root, i) if(doPass(**i)) (*i) -> show(); if(greed_color){ - Vect3f p0(x*cell_sx, y*cell_sy, 0); - Vect3f dx(cell_sx, 0, 0); - Vect3f dy(0, cell_sy, 0); + Vect3f p0(x*G2D::cell_sx, y*G2D::cell_sy, 0); + Vect3f dx(G2D::cell_sx, 0, 0); + Vect3f dy(0, G2D::cell_sy, 0); show_vector(p0, p0 + dx, p0 + dx + dy, p0 + dy, greed_color); } } @@ -392,15 +393,15 @@ class Grid2D : PassDispatcher, Grid2DConfig void show_area(const T& obj, int color) const { - for(int y = 0;y < sy;y++) - for(int x = 0;x < sx;x++){ + for(int y = 0;y < G2D::sy;y++) + for(int x = 0;x < G2D::sx;x++){ const SList& root = table[y][x]; - SList::const_iterator i; + typename SList::const_iterator i; FOR_EACH(root, i) if(&obj == *i){ - Vect3f p0(x*cell_sx, y*cell_sy, 0); - Vect3f dx(cell_sx, 0, 0); - Vect3f dy(0, cell_sy, 0); + Vect3f p0(x*G2D::cell_sx, y*G2D::cell_sy, 0); + Vect3f dx(G2D::cell_sx, 0, 0); + Vect3f dy(0, G2D::cell_sy, 0); show_vector(p0, p0 + dx, p0 + dx + dy, p0 + dy, color); } } @@ -409,14 +410,14 @@ class Grid2D : PassDispatcher, Grid2DConfig int size() const { int sz = 0; - for(int y = 0;y < sy;y++) - for(int x = 0;x < sx;x++) + for(int y = 0;y < G2D::sy;y++) + for(int x = 0;x < G2D::sx;x++) sz += table[y][x].size(); return sz; } protected: - SList table[sy][sx]; + SList table[G2D::sy][G2D::sx]; }; #endif // __GRID_2D__ diff --git a/MechoSoma/Xreal/Joystick/XJoystick.h b/MechoSoma/Xreal/Joystick/XJoystick.h index b0c10a52..5e8b3097 100644 --- a/MechoSoma/Xreal/Joystick/XJoystick.h +++ b/MechoSoma/Xreal/Joystick/XJoystick.h @@ -1,7 +1,10 @@ - #ifndef _XJOYSTICK_H #define _XJOYSTICK_H +#ifndef _WIN32 +#include +#endif + //--------------------------------------------------------------------------- struct XJOYSTATE @@ -21,15 +24,24 @@ struct XJOYSTATE class XJoystick : public XJOYSTATE { int next_input; +#ifdef _WIN32 struct IDirectInputDevice2* gpdiJoystick; +#endif XJOYSTATE prev_state; public: int ID; - XJoystick() { gpdiJoystick = 0; } + XJoystick() + { +#ifdef _WIN32 + gpdiJoystick = 0; +#endif + } ~XJoystick() { release(); } +#ifdef _WIN32 int prepare(IDirectInputDevice2* gpdiJoystick); +#endif int acquire(); int input(); void release(); diff --git a/MechoSoma/Xreal/Joystick/XJoystick_port.cpp b/MechoSoma/Xreal/Joystick/XJoystick_port.cpp new file mode 100644 index 00000000..2f805ef5 --- /dev/null +++ b/MechoSoma/Xreal/Joystick/XJoystick_port.cpp @@ -0,0 +1,29 @@ +#include "XJoystick.h" + +int XJoystickInit(int ErrHUsed) +{ + return 0; +} + +void XJoystickCleanup(void) +{ +} + +void XJoystickQuant() +{ +} + +int XJoystickIsButtonPressed(int button, int joystick_ID) +{ + return 0; +} + +XJoystick* XJoystickGetJoystick(int joystick_ID) +{ + return 0; +} + +XJoystickHandler XJoystickSetHandler(XJoystickHandler handler) +{ + return handler; +} diff --git a/MechoSoma/Xreal/LCP_ContactSolver.cpp b/MechoSoma/Xreal/LCP_ContactSolver.cpp index dda078df..3756b1bb 100644 --- a/MechoSoma/Xreal/LCP_ContactSolver.cpp +++ b/MechoSoma/Xreal/LCP_ContactSolver.cpp @@ -2,11 +2,11 @@ #include "Body.h" #include "Contact.h" #include "LCP_ContactSolver.h" -#include "params.h" -#include "cholesky.h" -#include "Mechosoma.h" +#include "Params.h" +#include "CHOLESKY.H" +#include "mechosoma.h" #include "Statistics.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" //#define _CHECK_RESOLVING_ @@ -80,7 +80,7 @@ Mat3f& DynamicBody::global_mass_matrix(const Vect3f& ri, const Vect3f& rj, Mat3f void Body::calc_normal_mass_matrix(Mat& M) { int normal_size = contacts.size() + contacts2.size(); - mass_matrix_array = new(tnt_mem_heap) Mass_Matrix_Array(normal_size); + mass_matrix_array = new Mass_Matrix_Array(normal_size); normal_contacts.clear(); diff --git a/MechoSoma/Xreal/LCP_Solver.cpp b/MechoSoma/Xreal/LCP_Solver.cpp index a0c6878b..8f4c6712 100644 --- a/MechoSoma/Xreal/LCP_Solver.cpp +++ b/MechoSoma/Xreal/LCP_Solver.cpp @@ -1,13 +1,13 @@ #include "StdAfx.h" #include "LCP_Solver.h" -#include "qr.h" -#include "lu.h" +#include "QR.H" +#include "LU.H" #include "svd.h" -#include "cholesky.h" -#include "trislv.h" -#include "transv.h" /* transpose views */ +#include "CHOLESKY.H" +#include "TRISLV.H" +#include "TRANSV.H" /* transpose views */ //#include "PrmEdit.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "Params.h" #include "DebugPrm.h" @@ -99,7 +99,11 @@ void LCP_Solver::save_problem(ofstream& out) out << "init_counter: " << init_counter << endl; out << "det(M): " << det(M) << endl; - out << (!Cholesky_upper_factorization(fullMatrix(), Mat(size + size_frictional, size + size_frictional)) ? "PSD" : "nonPSD!!!") << endl; + { + auto m1 = fullMatrix(); + Mat m2(size + size_frictional, size + size_frictional); + out << (!Cholesky_upper_factorization(m1, m2) ? "PSD" : "nonPSD!!!") << endl; + } out << "prp: " << prp; out << "f: " << f; out << "a: " << a; @@ -455,7 +459,10 @@ void LCP_Solver::solveCholesky(Mat& A, Vect& B) if(Cholesky_upper_factorization(A, L) !=0) abort("LCP_Solver: Cholesky_upper_factorization fails"); Vect y = Lower_triangular_solve(L, B); - B = Upper_triangular_solve(Transpose_view(L), y); + { + auto m1 = Transpose_view(L); + B = Upper_triangular_solve(m1, y); + } } void LCP_Solver::solveSVD(Mat& A, Vect& B) diff --git a/MechoSoma/Xreal/LCP_Solver.h b/MechoSoma/Xreal/LCP_Solver.h index f4ddc48f..782383bc 100644 --- a/MechoSoma/Xreal/LCP_Solver.h +++ b/MechoSoma/Xreal/LCP_Solver.h @@ -4,8 +4,10 @@ ////////////////////////////////////////////// // Control defines ////////////////////////////////////////////// +#ifdef _WIN32 #define TNT_MEM_HEAP 200000 #define TNT_NO_BOUNDS_CHECK +#endif //#define _LCPSolverListing_ //#define _LCPSolverTest_ @@ -39,9 +41,9 @@ extern MemoryHeap tnt_mem_heap; #endif #endif -#include "tnt.h" -#include "vec.h" -#include "fmat.h" +#include "TNT.H" +#include "VEC.H" +#include "FMAT.H" using namespace TNT; @@ -69,11 +71,11 @@ class LCP_Solver { protected: enum ContactProperty { - _CLEAN_ = 0, // ×èñòûé êîíòàêò - _C_ = 1, // "Clamped" - çàôèêñèðîâàííûé êîíòàêò: f > 0, (a == 0) - _NC_ = 2, // "NonClamped" - ðàçðàâàþùèéñÿ êîíòàêò: f == 0, (a > 0) + _CLEAN_ = 0, // ������ ������� + _C_ = 1, // "Clamped" - ��������������� �������: f > 0, (a == 0) + _NC_ = 2, // "NonClamped" - ������������� �������: f == 0, (a > 0) - _CLEAN_F_ = 4, // ×èñòûé êîíòàêò, òðåíèå + _CLEAN_F_ = 4, // ������ �������, ������ _CF_ = 8, // "ClampedFriction" _NCF_ = 16, // "NonClampedFriction" @@ -81,8 +83,8 @@ class LCP_Solver _M_ = 2, // "-" _NCP_ = _NCF_ | _P_, // "NonClamped +": f == k*fn, a.< 0 - _CP_ = _CF_ | _P_, // "Clamped +" - çàôèêñèðîâàííûé äëÿ òðåíèÿ: 0 < f < k*fn, (a == 0) - _CM_ = _CF_ | _M_, // "Clamped -" - çàôèêñèðîâàííûé äëÿ òðåíèÿ: -k*fn < f < 0, (a == 0) + _CP_ = _CF_ | _P_, // "Clamped +" - ��������������� ��� ������: 0 < f < k*fn, (a == 0) + _CM_ = _CF_ | _M_, // "Clamped -" - ��������������� ��� ������: -k*fn < f < 0, (a == 0) _NCM_ = _NCF_ | _M_ // "NonClamped -": f == -k*fn, a.> 0 }; diff --git a/MechoSoma/Xreal/LCP_frictional.cpp b/MechoSoma/Xreal/LCP_frictional.cpp index b6f72476..18386c3d 100644 --- a/MechoSoma/Xreal/LCP_frictional.cpp +++ b/MechoSoma/Xreal/LCP_frictional.cpp @@ -6,7 +6,7 @@ //////////////////////////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "LCP_Solver.h" -#include "cholesky.h" +#include "CHOLESKY.H" #include "Statistics.h" //#define _FrictionalListing_ @@ -22,11 +22,11 @@ void LCP_Solver::compute_force_frictional() while(1){ ///////////////////////////////////////////////////////////// - // Óñòàíîâêà êàñàòåëüíûõ óñëîâèé + // ��������� ����������� ������� int d; drive_friction = _CLEAN_F_; for(d = 1; d <= size_frictional; d++){ - if(prp_t(d) != _CLEAN_F_) // óñëîâèå óæå óñòàíîâëåíî + if(prp_t(d) != _CLEAN_F_) // ������� ��� ����������� continue; switch(prp(fn_index(d))){ @@ -34,24 +34,24 @@ void LCP_Solver::compute_force_frictional() if(fabs(a_t(d)) > a_t_zero_threshould) drive_to_zero_frictional(d); else - // íåò êàñàòåëüíîãî óñêîðåíèÿ + // ��� ������������ ��������� prp_t(d) = a_t(d) < 0 ? _NCP_ : _NCM_; break; - case _NC_: // íåò íîðìàëüíîé ñèëû íà äàííîì êîíòàêòå - if(fabs(f_t(d)) > LCP_delta_tolerance) // óáèðàåì ðàíåå óñòàíîâëåííóþ êàñàòåëüíóþ ñèëó + case _NC_: // ��� ���������� ���� �� ������ �������� + if(fabs(f_t(d)) > LCP_delta_tolerance) // ������� ����� ������������� ����������� ���� drive_to_zero_frictional(d); else prp_t(d) = a_t(d) < 0 ? _NCP_ : _NCM_; break; - case _CLEAN_: // óñòàíàâëèâàòü êàñàòåëüíîå óñëîâèå ïîñëå óñòàíîâêè íîðìàëüíîãî + case _CLEAN_: // ������������� ����������� ������� ����� ��������� ����������� break; } } ///////////////////////////////////////////////////////////// - // Óñòàíîâêà íîðìàëüíûõ óñëîâèé + // ��������� ���������� ������� drive_friction = 0; for(d = 1; d <= size; d++){ if(prp(d) != _CLEAN_) @@ -151,18 +151,18 @@ void LCP_Solver::drive_to_zero_frictional(int d) // Normal case _CLEAN_: case _NC_: { - int index_t = ft_index(index); // ïðîâåðÿåì óñëîâèå íà òðåíèå, åñëè åñòü + int index_t = ft_index(index); // ��������� ������� �� ������, ���� ���� if(index_t){ - if(prp_t(index_t) & _CF_) // áûëî clamped - óáèðàåì + if(prp_t(index_t) & _CF_) // ���� clamped - ������� C_size_frictional--; - prp_t(index_t) = _CLEAN_F_; // î÷èùàåì + prp_t(index_t) = _CLEAN_F_; // ������� } if(prev_state == _C_) C_size_frictional--; break; } case _C_: -// assert(0); // åñëè åñòü êàñàòåëüíîå óñëîâèå, òî åãî íàäî, âîçìîæíî, î÷èñòèòü +// assert(0); // ���� ���� ����������� �������, �� ��� ����, ��������, �������� C_size_frictional++; break; } @@ -184,11 +184,11 @@ void LCP_Solver::fdirection_frictional(int d) if(drive_friction) if(prp(fn_index(d)) == _C_) - df_t(d) = dir = -SIGN(a_t(d)); // íàñòðàèâàåì êàñàòåëüíóþ ñèëó, ÷òîáû ìèíèìèçèðîâàòü êàñàòåëüíîå óñêîðåíèå + df_t(d) = dir = -SIGN(a_t(d)); // ����������� ����������� ����, ����� �������������� ����������� ��������� else - df_t(d) = dir = -SIGN(f_t(d)); // óáèðàåì êàñàòåëüíóþ ñèëó, ò.ê. íåò íîðìàëüíîé + df_t(d) = dir = -SIGN(f_t(d)); // ������� ����������� ����, �.�. ��� ���������� else - df(d) = 1; // íàñòðàèâàåì íîðìàëüíóþ ñèëó + df(d) = 1; // ����������� ���������� ���� if(!C_size_frictional) return; diff --git a/MechoSoma/Xreal/Mechos.cpp b/MechoSoma/Xreal/Mechos.cpp index 714b8cd8..9713bab5 100644 --- a/MechoSoma/Xreal/Mechos.cpp +++ b/MechoSoma/Xreal/Mechos.cpp @@ -5,24 +5,24 @@ #include "SimpleClip.h" #include "Params.h" #include "sound.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "IVisGeneric.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "Line2D.h" -#include "MechoSoma.h" -#include "xreal_utl.h" +#include "mechosoma.h" +#include "Xreal_utl.h" #include "fxlabInterface.h" #include "BaseTrail.h" -#include "terra.h" +#include "TERRA.H" #include "controls.h" #include "CustomFieldSources.h" -#include "Joystick\XJoystick.h" +#include "XJoystick.h" #include "PolyhedronLibrary.h" #include "RungeKutta4.h" #include "MechosPrm.h" #include "ArcansPrm.h" #include "PersonageDifferetiationPrm.h" -#include "statistics.h" +#include "Statistics.h" #include "DebugPrm.h" #include "AnimalArcansPrm.h" @@ -165,14 +165,14 @@ void Mechos::registerGeometry() for(i = 1; i < NUM_PARTS; i++) part_offsets[i] = part_by_index(i) -> LocalMatrix; swing_phase = 0; - character_angles.set(0); - character_angles_velocity.set(0); + character_angles.set(0.0); + character_angles_velocity.set(0.0); velocity_y_prev = 0; sensor_source = 0; effects_queue.clear(); if(current_effect != StoneHitEffect) runEffect(NoEffect); - acceleration_spot_direction.set(0); + acceleration_spot_direction.set(0.0); formic_transport_finish_angle = 0; rotation_angle = 0; alpha = 1; @@ -183,7 +183,7 @@ void Mechos::registerGeometry() left_rudder_angle = right_rudder_angle = 0; forward_wheels_phase = backward_wheels_phase = 0; assembling_point_dist = 0; - dV_applied.set(0); + dV_applied.set(0.0); reset_stopping(); jabasoma_jumping_log = 0; @@ -233,15 +233,15 @@ void Mechos::createBound() float zmin = geometry -> zminTotal(); float zmax = geometry -> zmaxTotal()*mechos_zsize_scale; - // Ïîïðàâêà äëÿ ïåðñîíàæåé, àññèìåòðè÷íûõ ïî X + // �������� ��� ����������, ������������� �� X float delta_x = -(part_by_index(RBWheel) -> GlobalMatrix.trans().x + part_by_index(LBWheel) -> GlobalMatrix.trans().x)/2; - // Ñäâèãàåì âïåðåä ÖÌ + // �������� ������ �� float delta_y = -(ymax + ymin)/2; ymin += delta_y; ymax += delta_y; - // Îïóñêàåì ÖÌ + // �������� �� float z_axles = 0; for(w = RFWheel; w <= LBWheel; w++) z_axles += part_by_index(w) -> GlobalMatrix.trans().z; @@ -356,7 +356,7 @@ void Mechos::disorganize() } setTrans(R().z + mesh_offset.z, Z_AXIS); - mesh_offset.set(0); + mesh_offset.set(0.0); Body::createBound(); set_archimedean_force(personage_buoyancy); @@ -674,7 +674,7 @@ void Mechos::calc_forces_and_drags() setLocalAngularVelocity(teleportation_spin*teleportation_timer()/starting_teleportation_time + teleportation_spin_initial, Z_AXIS); setPermanentAlpha(1 - teleportation_timer()/starting_teleportation_time); geometry -> SetScale(1 + (teleportation_size - 1)*teleportation_timer()/finishing_teleportation_time); - if(!teleportation_timer && (fabs(getDist(teleportation_psi, psi(), 2*M_PI)) < teleportation_psi_error || !after_disorganize_latency)){ + if(!teleportation_timer && (fabs(getDist_f(teleportation_psi, psi(), 2*M_PI)) < teleportation_psi_error || !after_disorganize_latency)){ state_ = ASSEMBLING_MECHOS; features_ &= ~ROTATING; setRot(-teleportation_psi, Z_AXIS); @@ -745,11 +745,11 @@ void Mechos::calc_forces_and_drags_of_normal_mechos() float Vy = Vlocal().y; Vy -= dV_applied.y*mechos_collision_correction_restitution; setLocalVelocity(Vy, Y_AXIS); - dV_applied.set(0); + dV_applied.set(0.0); control(); - // Óñòàíîâêà íà êîëåñà + // ��������� �� ������ if(theta() > M_PI/3) applyLocalTurnTorque(Zlocal(), Vect3f::K); @@ -773,7 +773,7 @@ void Mechos::calc_forces_and_drags_of_normal_mechos() applyLocalForce( traction*speed_increment_factor*k_traction_water, Y_AXIS); applyLocalTorque( rudder*k_rudder_water*SIGN(Vlocal().y + traction*5), Z_AXIS); } - // Ïîêà÷èâàíèå + // ����������� if(!ground_colliding){ swing_phase += evolve_time_step*(1. + speed_avr/20); applyGlobalForce(mechos_swing_lift_force*sin(swing_phase), Z_AXIS); @@ -830,18 +830,22 @@ void Mechos::calc_forces_and_drags_of_normal_mechos() float u_n = dot(vel, normal) - horizontal_velocity_relaxation_value; if(u_n < 0){ Mat3f Ig_inv1(Ig_inv), Ig_inv2; - Ig_inv[0].set(0); - Ig_inv[1].set(0); + Ig_inv[0].set(0.0); + Ig_inv[1].set(0.0); Ig_inv[2] *= horizontal_Ig_inv_z_factor; - float Aii = dot(normal, global_mass_matrix(c.cp1g, c.cp1g, Mat3f())*normal); + Mat3f m1; + float Aii = dot(normal, global_mass_matrix(c.cp1g, c.cp1g, m1)*normal); if(body2 && body2 -> is_dynamic()){ if(body2 -> type() == MECHOS){ Ig_inv2 = body2 -> Ig_inv; - body2 -> Ig_inv[0].set(0); - body2 -> Ig_inv[1].set(0); + body2 -> Ig_inv[0].set(0.0); + body2 -> Ig_inv[1].set(0.0); body2 -> Ig_inv[2] *= horizontal_Ig_inv_z_factor; } - Aii += dot(normal, body2 -> global_mass_matrix(c.cp2g, c.cp2g, Mat3f())*normal); + { + Mat3f m1; + Aii += dot(normal, body2 -> global_mass_matrix(c.cp2g, c.cp2g, m1)*normal); + } } float j_n = -u_n*horizontal_k_restitution_plus_one/(Aii + 0.001); Vect3f J = normal*j_n; @@ -860,9 +864,13 @@ void Mechos::calc_forces_and_drags_of_normal_mechos() Vect3f z_axis = Vect3f::K; float u_z = dot(vel, z_axis) + vertical_velocity_relaxation_value; if(enable_vertical_analytics && u_z > 0){ - float Aii = dot(z_axis, global_mass_matrix(c.cp1g, c.cp1g, Mat3f())*z_axis); + Mat3f m1; + float Aii = dot(z_axis, global_mass_matrix(c.cp1g, c.cp1g, m1)*z_axis); if(body2) - Aii += dot(z_axis, body2 -> global_mass_matrix(c.cp2g, c.cp2g, Mat3f())*z_axis); + { + Mat3f m2; + Aii += dot(z_axis, body2 -> global_mass_matrix(c.cp2g, c.cp2g, m2)*z_axis); + } float j = -u_z/(Aii + 0.001); Vect3f J = z_axis*j; V.scaleAdd(J, mass_inv); @@ -894,13 +902,13 @@ void Mechos::calc_forces_and_drags_of_moving_personage() void Mechos::calc_forces_and_drags_of_assembling_personage() { - // Ðó÷íîé ïîâîðîò ñóùíîñòè + // ������ ������� �������� if(active() && (mchKeyPressed(MCH_KEY_TURN_LEFT, control_config) || mchKeyPressed(MCH_KEY_TURN_RIGHT, control_config))){ manual_essence_turn = 1; setGlobalAngularVelocity((mchKeyPressed(MCH_KEY_TURN_RIGHT, control_config) ? 1 : -1)*standing_personage_manual_rudder, Z_AXIS); } - // Ïîâîðîò íà ñåìÿ + // ������� �� ���� if(!manual_essence_turn){ Vect3f r; Alg().invXform(assembling_direction, r); @@ -1098,7 +1106,8 @@ void Mechos::damage(float dE, int damage_style) energy = 0; if(features() & NON_DESTRUCTING && energy < 1) energy = 1; - fxlabDamageWarinig(Vect3f(R()),this,damage_style); + Vect3f v1(R()); + fxlabDamageWarinig(v1,this,damage_style); } } @@ -1283,7 +1292,7 @@ void Mechos::hide() /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Ñèñòåìà îáðàòíîé ñâÿçè äëÿ PointControl +// ������� �������� ����� ��� PointControl /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Mechos::target_achieved() { @@ -1357,8 +1366,8 @@ void Mechos::control() void Mechos::keyboard_control() { - float traction_incr = 1.; // ñêîðîñòü íàáîðà ìîùíîñòè - float traction_decr = 1; // ñêîðîñòü ñáðîñà (ïðîòèâîïîëîæíàÿ ñòðåëêà - ìãíîâåííî + òîðìîç) + float traction_incr = 1.; // �������� ������ �������� + float traction_decr = 1; // �������� ������ (��������������� ������� - ��������� + ������) XJoystick* joystick = enable_joystick_control ? XJoystickGetJoystick() : 0; @@ -1435,7 +1444,7 @@ void Mechos::keyboard_control() } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Ìóðàâåéíèê +// ���������� /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Mechos::formicTransport(const Vect3f& target, const Vect3f& next_point_for_direction) { @@ -1459,7 +1468,7 @@ void Mechos::formicTransport(const Vect3f& target, const Vect3f& next_point_for_ } setTrans(R().z + mesh_offset.z, Z_AXIS); - mesh_offset.set(0); + mesh_offset.set(0.0); state_ = FORMIC_TRANSPORTED_MECHOS; completed_ = 0; visible_ = 0; @@ -1670,7 +1679,10 @@ void Mechos::setColor(int index, const sColor4f* diffuse, const sColor4f* specul { cMesh* mesh = part_by_index(index); if(mesh) - xrealIVG -> SetObjectColor(mesh, diffuse ? &sColor4f(diffuse -> r, diffuse -> g, diffuse -> b, diffuse -> a*alpha) : 0, specular, 1 << index); + { + sColor4f c1(diffuse -> r, diffuse -> g, diffuse -> b, diffuse -> a*alpha); + xrealIVG -> SetObjectColor(mesh, diffuse ? &c1 : 0, specular, 1 << index); + } } void Mechos::getColor(int index, sColor4f* diffuse, sColor4f* specular) @@ -1840,7 +1852,7 @@ int Mechos::startRotation(float angle, float speed) int Mechos::rotation_quant() { setLocalAngularVelocity(rotation_speed, Z_AXIS); - float dangle = getDist(psi(), prev_psi, 2*M_PI); + float dangle = getDist_f(psi(), prev_psi, 2*M_PI); if(fabs(dangle) > fabs(rotation_angle)){ features_ &= ~ROTATING; setLocalAngularVelocity(0, Z_AXIS); @@ -2000,14 +2012,14 @@ void Mechos::Wheel::convert(const MatXf& pose) n_contacts = 0; total_penetration = 0; - contact_point.set(0); - normal.set(0); + contact_point.set(0.0); + normal.set(0.0); property = 0; n_contacts_non_central = 0; total_penetration_non_central = 0; - contact_point_non_central.set(0); - normal_non_central.set(0); + contact_point_non_central.set(0.0); + normal_non_central.set(0.0); property_non_central = 0; f_n = j_t = 0; @@ -2015,7 +2027,7 @@ void Mechos::Wheel::convert(const MatXf& pose) angular_acceleration = 0; contacted_body = 0; - axle_cross_radius.set(0); + axle_cross_radius.set(0.0); radius_cross_tangent_dot_axle = 0; brake_delta_omega = 0; max_friction_impulse = 0; @@ -2332,12 +2344,14 @@ void Mechos::applyWheelsForce() float B[4], X[4]; for(i = 0; i < 4; i++){ Wheel& wi = wheels[i]; - A[i][i] = dot(wi.tangent, global_mass_matrix(wi.contact_point, wi.contact_point, Mat3f())*wi.tangent + Mat3f m1; + A[i][i] = dot(wi.tangent, global_mass_matrix(wi.contact_point, wi.contact_point, m1)*wi.tangent + (wi.TOI_inv*wi.radius_cross_tangent_dot_axle)*wi.axle_cross_radius )*mechos_diagonal_element_scaling_factor; for(int j = i + 1; j < 4; j++){ Wheel& wj = wheels[j]; - A[i][j] = dot(wi.tangent, global_mass_matrix(wi.contact_point, wj.contact_point, Mat3f())*wj.tangent); + Mat3f m2; + A[i][j] = dot(wi.tangent, global_mass_matrix(wi.contact_point, wj.contact_point, m2)*wj.tangent); } B[i] = -wi.v_t; } @@ -2348,7 +2362,8 @@ void Mechos::applyWheelsForce() for(i = 0; i < 4; i++){ Wheel& wi = wheels[i]; if(wi.check_if_blocked(X[i])){ - A[i][i] = dot(wi.tangent, global_mass_matrix(wi.contact_point, wi.contact_point, Mat3f())*wi.tangent)*mechos_diagonal_element_scaling_factor; + Mat3f m3; + A[i][i] = dot(wi.tangent, global_mass_matrix(wi.contact_point, wi.contact_point, m3)*wi.tangent)*mechos_diagonal_element_scaling_factor; wheels_blocked++; } } @@ -2431,7 +2446,8 @@ void Mechos::applyWheelsForce() if(i == WheelRB){ Vect3f dx = Alg().xcol()*((wheels[WheelLB].position.x - wheels[WheelRB].position.x)/2); dx.z = 0; - xrealIVG -> CreateTangentTrail(&(trail_pos0[WheelRB] + dx), + auto v1 = (trail_pos0[WheelRB] + dx); + xrealIVG -> CreateTangentTrail(&v1, &TrailColors[RedTrackTrail], &dr, &TrailColors[RedTrackTrail], mechos_red_track_time, mechos_red_track_animation_period, dx.norm() + mechos_red_track_thickness_add); } diff --git a/MechoSoma/Xreal/Mechos.h b/MechoSoma/Xreal/Mechos.h index 89eb02e7..55aa20ac 100644 --- a/MechoSoma/Xreal/Mechos.h +++ b/MechoSoma/Xreal/Mechos.h @@ -12,6 +12,8 @@ #include "PersonageDifferetiationPrm.h" +class BodyDispatcher; + class Mechos : virtual public PointControlledObject, private PersonageDifferetiationData { public: diff --git a/MechoSoma/Xreal/MechosEffects.cpp b/MechoSoma/Xreal/MechosEffects.cpp index cbd3cf92..97cf33d0 100644 --- a/MechoSoma/Xreal/MechosEffects.cpp +++ b/MechoSoma/Xreal/MechosEffects.cpp @@ -3,7 +3,7 @@ #include "Mechos.h" #include "MechosPrm.h" #include "sound.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" /////////////////////////////////////////////////////////////////////////////////////////// // Effects @@ -11,22 +11,22 @@ EffectData Mechos::effect_data[EffectsMax] = { EffectData(0, "main", EffectData::Cycled), - EffectData(1000, "no", EffectData::Forward, EFF_ANIMATION_1_BACK), // "HugeAcceleration", // Ñèëüíîå óñêîðåíèå ïîñëå íàåçäà íà ñïåöèàëüíûå ñïîòû: îäíîðàçîâàÿ àíèìàöèÿ. - EffectData(1000, "no", EffectData::Forward), // "Landing", // Ïðèçåìëåíèå ïîñëå äîëãîãî ïîëåòà: îäíîðàçîâàÿ àíèìàöèÿ. - EffectData(1000, "no", EffectData::Cycled), // "SpringBoardFly", // Ñâîáîäíûé ïðîäîëæèòåëüíûé ïîëåò ïîñëå òðàìïëèíà: çàöèêëåííàÿ àíèìàöèÿ. - EffectData(main_period, "main", EffectData::Forward), // "Resting", // Cïîêîéíîå ñîñòîÿíèè: ïåðèîäè÷åñêè âîçíèêàþùàÿ àíèìàöèÿ. - EffectData(outstrip_period, "exult", EffectData::Forward, EFF_ANIMATION_1_OUTRUN), // "OutstripTheNeighbour", // Îáãîí ñîïåðíèêà (ñóìàòîõó íà ñòàðòå íå ó÷èòûâàòü): îäíîðàçîâàÿ àíèìàöèÿ, ðàíüøå áûëà "outstrip" - EffectData(sadness_period, "sadness", EffectData::Forward, EFF_ANIMATION_1_OUTDRIVEN), // "OutstrippedByNeighbour", // Îáãîí ñîïåðíèêîì (ñóìàòîõó íà ñòàðòå íå ó÷èòûâàòü): îäíîðàçîâàÿ àíèìàöèÿ. - EffectData(1000, "no", EffectData::Forward), // "Collision", // Ñòîëêíîâåíèå ñ ñîïåðíèêîì: îäíîðàçîâàÿ àíèìàöèÿ. - EffectData(sadness_period, "sadness", EffectData::Forward, EFF_ANIMATION_1_SADNESS), // "InfluenceOfArcane", // Äåéñòâèå ÷óæîãî Àðêàíà: íåñêîëüêî âèäîâ îäíîðàçîâîé àíèìàöèè. - EffectData(exult_period, "exult", EffectData::Forward, EFF_ANIMATION_1_LUCKY), // "ExultEffect", // Ëèêîâàíèå îò ïîïàäàíèÿ â ñîïåðíèêà Àðêàíîì, óñïåøíîå ôèíèøèðîâàíèå: îäíîðàçîâàÿ àíèìàöèÿ. - EffectData(sadness_period, "sadness", EffectData::Forward), // "ObstacleAnnoying", // Ðàçäðàæåíèå îò ñòîëêíîâåíèÿ ñ ïðåïÿòñòâèåì-Àðêàíîì: îäíîðàçîâàÿ àíèìàöèÿ. - EffectData(1000, "no", EffectData::Forward, EFF_ANIMATION_1_CHECKDROP), // "CheckPointOmission", // Ïðîïóñê ÷åêïîéíòà: îäíîðàçîâàÿ àíèìàöèÿ (îáîðà÷èâàåòñÿ è êðè÷èò â êàìåðó). - EffectData(2000, "no", EffectData::Cycled), // "FlyingByArcane", // Óïðàâëÿåìûé ïîëåò ñ ïîìîùüþ Àðêàíà: çàöèêëåííàÿ àíèìàöèÿ (íàïðèìåð, ìàøåò ðó÷êàìè). - EffectData(2000, "no", EffectData::Cycled), // "Swimming", // Ïëàâàíèå ïî âîäå: çàöèêëåííàÿ àíèìàöèÿ (íàïðèìåð, ïåðåâîðà÷èâàåòñÿ êàê ïîïëàâîê). - EffectData(hit_period, "hit", EffectData::ForwardThenBackwardThenForwardThenBackward, EFF_ANIMATION_1_CRUSH, hit_delay), // "StoneHit", // Ïàäàåò êàìåíü íà ãîëîâó + EffectData(1000, "no", EffectData::Forward, EFF_ANIMATION_1_BACK), // "HugeAcceleration", // ������� ��������� ����� ������ �� ����������� �����: ����������� ��������. + EffectData(1000, "no", EffectData::Forward), // "Landing", // ����������� ����� ������� ������: ����������� ��������. + EffectData(1000, "no", EffectData::Cycled), // "SpringBoardFly", // ��������� ��������������� ����� ����� ���������: ����������� ��������. + EffectData(main_period, "main", EffectData::Forward), // "Resting", // C�������� ���������: ������������ ����������� ��������. + EffectData(outstrip_period, "exult", EffectData::Forward, EFF_ANIMATION_1_OUTRUN), // "OutstripTheNeighbour", // ����� ��������� (�������� �� ������ �� ���������): ����������� ��������, ������ ���� "outstrip" + EffectData(sadness_period, "sadness", EffectData::Forward, EFF_ANIMATION_1_OUTDRIVEN), // "OutstrippedByNeighbour", // ����� ���������� (�������� �� ������ �� ���������): ����������� ��������. + EffectData(1000, "no", EffectData::Forward), // "Collision", // ������������ � ����������: ����������� ��������. + EffectData(sadness_period, "sadness", EffectData::Forward, EFF_ANIMATION_1_SADNESS), // "InfluenceOfArcane", // �������� ������ ������: ��������� ����� ����������� ��������. + EffectData(exult_period, "exult", EffectData::Forward, EFF_ANIMATION_1_LUCKY), // "ExultEffect", // ��������� �� ��������� � ��������� �������, �������� �������������: ����������� ��������. + EffectData(sadness_period, "sadness", EffectData::Forward), // "ObstacleAnnoying", // ����������� �� ������������ � ������������-�������: ����������� ��������. + EffectData(1000, "no", EffectData::Forward, EFF_ANIMATION_1_CHECKDROP), // "CheckPointOmission", // ������� ���������: ����������� �������� (������������� � ������ � ������). + EffectData(2000, "no", EffectData::Cycled), // "FlyingByArcane", // ����������� ����� � ������� ������: ����������� �������� (��������, ����� �������). + EffectData(2000, "no", EffectData::Cycled), // "Swimming", // �������� �� ����: ����������� �������� (��������, ���������������� ��� ��������). + EffectData(hit_period, "hit", EffectData::ForwardThenBackwardThenForwardThenBackward, EFF_ANIMATION_1_CRUSH, hit_delay), // "StoneHit", // ������ ������ �� ������ EffectData(run_period, "run", EffectData::Cycled), // "RunToSeed", - EffectData(exult_period, "exult", EffectData::Forward, EFF_ANIMATION_1_BONUS) // "BonusExultEffect", // Ëèêîâàíèå îò âçÿòèÿ áîíóñà + EffectData(exult_period, "exult", EffectData::Forward, EFF_ANIMATION_1_BONUS) // "BonusExultEffect", // ��������� �� ������ ������ }; EffectData::EffectData(float period, char* channel, Mode mode_, int sound_, int delay_) diff --git a/MechoSoma/Xreal/MechosForSale.h b/MechoSoma/Xreal/MechosForSale.h index 7b3f9e75..bb8edeea 100644 --- a/MechoSoma/Xreal/MechosForSale.h +++ b/MechoSoma/Xreal/MechosForSale.h @@ -1,15 +1,19 @@ //////////////////////////////////////////////////////////////////// -// Mechos äëÿ ìàãàçèíà +// Mechos ��� �������� //////////////////////////////////////////////////////////////////// #include "Body.h" #include "Mesh3ds.h" +#ifndef _WIN32 +#include "port.h" +#endif + class MechosForSale : Body { - // Èíäåêñ äëÿ îáðàùåíèÿ ê ìàññèâó äåòàëåé (0-engine, front, back, rfw, rbw, lfw, lbw) + // ������ ��� ��������� � ������� ������� (0-engine, front, back, rfw, rbw, lfw, lbw) static int PART_INDEX(int type) { return BitSR(M3D_TYPE(type)); } - // Îáðàùåíèå ê äåòàëè ïî òèïó + // ��������� � ������ �� ���� cMesh* part_by_type(int partType) const; - // Îáðàùåíèå ê äåòàëè ïî èíäåêñó: 0-engine, 1-front, 2-back, 3-rf, 4-rb, 5-lf, 6-lb + // ��������� � ������ �� �������: 0-engine, 1-front, 2-back, 3-rf, 4-rb, 5-lf, 6-lb cMesh* part_by_index(int index) const; public: diff --git a/MechoSoma/Xreal/Meteorite.cpp b/MechoSoma/Xreal/Meteorite.cpp index a8fe66d1..f4059641 100644 --- a/MechoSoma/Xreal/Meteorite.cpp +++ b/MechoSoma/Xreal/Meteorite.cpp @@ -1,12 +1,12 @@ //////////////////////////////////////////////////////////////////// -// Ìåòåîðèò +// �������� //////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "Mechos.h" #include "Meteorite.h" #include "Params.h" #include "SimpleClip.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "sound.h" #include "AnimalArcansPrm.h" @@ -36,7 +36,7 @@ void Meteorite::scaleRadius(float factor) void Meteorite::calc_forces_and_drags() { Body::calc_forces_and_drags(); - if(R().z < 0 || colliding()){ // ñòîëêíîâåíèå ñ ïîâåðõíîñòüþ + if(R().z < 0 || colliding()){ // ������������ � ������������ setTrans(R_prev); kill(); return; diff --git a/MechoSoma/Xreal/MultiBodyCollision.cpp b/MechoSoma/Xreal/MultiBodyCollision.cpp index 7539961e..e803154b 100644 --- a/MechoSoma/Xreal/MultiBodyCollision.cpp +++ b/MechoSoma/Xreal/MultiBodyCollision.cpp @@ -10,14 +10,14 @@ // ContactingBodies ///////////////////////////////////////////////////////// -ContactingBodies& ContactingBodiesList::search_group(Body* body) +std::vector::iterator ContactingBodiesList::search_group(Body* body) { iterator gi; FOR_EACH(*this, gi) if(find(gi -> begin(), gi -> end(), body) != gi -> end()) - return *gi; + return gi; assert(0); - return *end(); + return end(); } void ContactingBodiesList::insert_pair(Body* body1, Body* body2) @@ -29,17 +29,17 @@ void ContactingBodiesList::insert_pair(Body* body1, Body* body2) back().push_back(body2); break; case 1: // add body2 to body1's group - search_group(body1).push_back(body2); + search_group(body1)->push_back(body2); break; case 2: // add body1 to body2's group - search_group(body2).push_back(body1); + search_group(body2)->push_back(body1); break; case 3: { // join 2 groups - ContactingBodies& group1 = search_group(body1); - ContactingBodies& group2 = search_group(body2); - if(&group1 != &group2){ - group1.insert(group1.end(), group2.begin(), group2.end()); - erase(&group2); + auto group1 = search_group(body1); + auto group2 = search_group(body2); + if(group1 != group2){ + group1->insert(group1->end(), group2->begin(), group2->end()); + erase(group2); } break; } diff --git a/MechoSoma/Xreal/MultibodyContact.h b/MechoSoma/Xreal/MultibodyContact.h index 8943a84f..5d9c5e85 100644 --- a/MechoSoma/Xreal/MultibodyContact.h +++ b/MechoSoma/Xreal/MultibodyContact.h @@ -1,7 +1,7 @@ #ifndef _MULTIBODY_CONTACT_ #define _MULTIBODY_CONTACT_ -class ContactingBodies : public vector +class ContactingBodies : public std::vector { TotalContactList total_contacts; @@ -11,9 +11,9 @@ class ContactingBodies : public vector void evolve(float dt); }; -class ContactingBodiesList : public vector +class ContactingBodiesList : public std::vector { - ContactingBodies& search_group(Body* body); + std::vector::iterator search_group(Body* body); public: ContactingBodiesList(){} diff --git a/MechoSoma/Xreal/Part.cpp b/MechoSoma/Xreal/Part.cpp index 0a841467..49581a37 100644 --- a/MechoSoma/Xreal/Part.cpp +++ b/MechoSoma/Xreal/Part.cpp @@ -5,13 +5,13 @@ #include "Mesh3ds.h" #include "BodyDispatcher.h" #include "sound.h" -#include "params.h" +#include "Params.h" #include "MechosPrm.h" #include "ArcansPrm.h" /////////////////////////////////////////////////////// -// ×àñòü ìåõîñà +// ����� ������ /////////////////////////////////////////////////////// Part::Part(cMesh* geometry_, int formic_) : Body(geometry_), @@ -82,7 +82,7 @@ void Part::post_quant() } ////////////////////////////////////////////////////////////////// -// Îáùèå ñâîéñòâà +// ����� �������� ////////////////////////////////////////////////////////////////// void Part::quant() { diff --git a/MechoSoma/Xreal/Part.h b/MechoSoma/Xreal/Part.h index 8773ec85..8a4d0ae2 100644 --- a/MechoSoma/Xreal/Part.h +++ b/MechoSoma/Xreal/Part.h @@ -1,13 +1,19 @@ ////////////////////////////////////////////////////////////////// -// Îáðàùåíèå ê ÷àñòÿì ìåõîñà +// ��������� � ������ ������ ////////////////////////////////////////////////////////////////// -#include "base.h" +#include "Base.h" -// Èíäåêñ äëÿ îáðàùåíèÿ ê ìàññèâó äåòàëåé (0-engine, front, back, rfw, rbw, lfw, lbw) +#ifndef _WIN32 +#include "port.h" +#endif + +// ������ ��� ��������� � ������� ������� (0-engine, front, back, rfw, rbw, lfw, lbw) inline int PART_INDEX(int type) { return BitSR(M3D_TYPE(type)); } +class Mechos; + ////////////////////////////////////////////////////////////////// -// ×àñòü ìåõîñà +// ����� ������ ////////////////////////////////////////////////////////////////// class Part : public Body { friend class Mechos; @@ -20,7 +26,7 @@ class Part : public Body { int character; float distance_to_mechos; int do_merge_to_mechos; - cMesh* formic; // Ìóðàâåé + cMesh* formic; // ������� DurationTimer colliding_timer; AverageConditionTimer stopping_detection_timer; diff --git a/MechoSoma/Xreal/Pig.cpp b/MechoSoma/Xreal/Pig.cpp index 3ebbe105..48868f5e 100644 --- a/MechoSoma/Xreal/Pig.cpp +++ b/MechoSoma/Xreal/Pig.cpp @@ -4,7 +4,7 @@ #include "SimpleClip.h" #include "Pig.h" #include "Ball.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" Pig::Pig() : Body(myM3DType(24), CenteredBottomAlignmentedBound), diff --git a/MechoSoma/Xreal/PointControlledObject.cpp b/MechoSoma/Xreal/PointControlledObject.cpp index 41aff316..2b7f782d 100644 --- a/MechoSoma/Xreal/PointControlledObject.cpp +++ b/MechoSoma/Xreal/PointControlledObject.cpp @@ -3,7 +3,7 @@ #include "PointControlledObject.h" #include "Params.h" #include "MechosPrm.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "BodyDispatcher.h" #include "DebugPrm.h" @@ -158,7 +158,7 @@ void PointControlledObject::point_control() // Check if point is passed if(fabs(T.x) < catch_width && fabs(T.y) < catch_length){ - target_achieved(); // Ïîäáîð ñåìåíè + target_achieved(); // ������ ������ setRudder(0); return; } @@ -166,7 +166,7 @@ void PointControlledObject::point_control() // Calc rudder & traction if(backward_maneuver() || (T.y < 0 && T.y > -back_moving_ymax && fabs(T.x/T.y) < back_moving_kmax)){ // Backward moving - if(Vlocal().y > 0) // Åùå íå îñòàíîâèëñÿ + if(Vlocal().y > 0) // ��� �� ����������� setRudder(0); else{ Vect3f D(T.x, T.y, 0); @@ -179,10 +179,10 @@ void PointControlledObject::point_control() else{ float r = 2*acos(D.y)/M_PI; setRudder(D.x > 0 ? r : -r); - // Ïðîâåðêà íà âûêëþ÷åíèå ìàíåâðà + // �������� �� ���������� ������� if(backward_maneuver_obstacle_timer(backwardObstacle(), backward_maneuver_obstacle_timer_duration) - || fabs(r) < backward_maneuver_threshold // Âûðîâíÿëñÿ íà öåëü - || backward_maneuver_velocity_timer(velocity_y_avr < velocity_y_avr_zero && traction_avr < -traction_avr_zero, backward_maneuver_velocity_timer_duration)){ // Åñòü òÿãà, íî íåò õîäà + || fabs(r) < backward_maneuver_threshold // ���������� �� ���� + || backward_maneuver_velocity_timer(velocity_y_avr < velocity_y_avr_zero && traction_avr < -traction_avr_zero, backward_maneuver_velocity_timer_duration)){ // ���� ����, �� ��� ���� backward_maneuver_obstacle_timer.stop(); backward_maneuver.stop(); velocity_y_avr = traction_avr = 0; @@ -196,7 +196,7 @@ void PointControlledObject::point_control() } else{ // Forward moving - // Ïðîâåðêà íà ïðåïÿòñòâèå + // �������� �� ����������� if(backward_maneuver_obstacle_timer(forwardObstacle(), backward_maneuver_obstacle_timer_duration) || backward_maneuver_velocity_timer(velocity_y_avr < velocity_y_avr_zero && traction_avr > traction_avr_zero, backward_maneuver_velocity_timer_duration)){ backward_maneuver_obstacle_timer.stop(); @@ -208,7 +208,7 @@ void PointControlledObject::point_control() return; } - // Ïðîâåðêà íà î÷åíü êðóòûå ïîâîðîòû + // �������� �� ����� ������ �������� // CurvatureInterval curv0(T.x, T.y, allowed_width); // if(fabs(curv0.min()) > max_curvature){ // backward_maneuver.start(1500); @@ -217,7 +217,7 @@ void PointControlledObject::point_control() // return; // } - if(T.y > -40 && (fabs(T.x)/(fabs(T.y) + FLT_EPS) < front_moving_kmax || fabs(T.x) < allowed_width)){ // Ïåðåäíÿÿ çîíà - îïòèìèçàöèÿ + if(T.y > -40 && (fabs(T.x)/(fabs(T.y) + FLT_EPS) < front_moving_kmax || fabs(T.x) < allowed_width)){ // �������� ���� - ����������� CurvatureInterval curv; int n = 0; ControlPointList::iterator pi; @@ -270,7 +270,7 @@ void PointControlledObject::point_control() // setRudder(curv.avr()*curvature_factor); } - else{ // Çàäíÿÿ çîíà - ìàêñèìàëüíûé ðóëü + else{ // ������ ���� - ������������ ���� setRudder(T.x <= 0 ? 1 : -1); control_description = "Fwd max"; if(Vlocal().y > brake_lower_speed){ @@ -331,7 +331,7 @@ void PointControlledObject::control() float psi_curr = psi(); float dl = getDist(R_prev, R()).norm(); - actual_curvature = dl > 1e-7 ? getDist(psi_prev, psi_curr, 2*M_PI)/dl : 0; + actual_curvature = dl > 1e-7 ? getDist_f(psi_prev, psi_curr, 2*M_PI)/dl : 0; psi_prev = psi_curr; // average( actual_curvature_, (Vglobal() % Wglobal() % Vglobal())/(pow(Vglobal().norm(), 3) + FLT_EPS), curvature_avr_tau); diff --git a/MechoSoma/Xreal/Polyhedron.cpp b/MechoSoma/Xreal/Polyhedron.cpp index 8335bae5..ce61b53e 100644 --- a/MechoSoma/Xreal/Polyhedron.cpp +++ b/MechoSoma/Xreal/Polyhedron.cpp @@ -1,8 +1,10 @@ +#include + #include "StdAfx.h" #include "Polyhedron.h" #include "Mesh3ds.h" #include "Xreal_utl.h" -#include "Mechosoma.h" +#include "mechosoma.h" template<> struct hash { @@ -11,7 +13,7 @@ struct hash { Polyhedron::Polyhedron(const Polyhedron& poly, const Vect3f& scale, const Vect3f& displace) { - hash_map indexedVerts(poly.verts().size()*2); + std::unordered_map indexedVerts(poly.verts().size()*2); list::const_iterator vi; FOR_EACH(poly.verts(), vi) indexedVerts[&*vi] = addVertex(vi -> name(), vi -> coords()*scale + displace ); @@ -48,7 +50,7 @@ static inline void quantize(Vect3f& v, float eps) void Polyhedron::setMesh(cMesh& mesh, int recursive) { - string name = mesh.GetFileName() ? mesh.GetFileName() : mesh.GetGeneralParent() -> GetFileName(); + string name = mesh.GetFileName() ? mesh.GetFileName().ptr() : mesh.GetGeneralParent() -> GetFileName().ptr(); int dot_pos = name.find("."); int slash_pos = name.rfind("\\", dot_pos); name.replace(dot_pos, 4, recursive ? string(".hul") : string("_") + string(mesh.GetName()) + ".hul"); @@ -156,7 +158,7 @@ void Polyhedron::load(const char* fname, const Vect3f& scale) int n_verts; in > n_verts; - hash_map indexedVerts(n_verts); + std::unordered_map indexedVerts(n_verts); char name_buf[256]; Vect3f coords; int i; diff --git a/MechoSoma/Xreal/PolyhedronClip.cpp b/MechoSoma/Xreal/PolyhedronClip.cpp index 532991c9..b335a3f5 100644 --- a/MechoSoma/Xreal/PolyhedronClip.cpp +++ b/MechoSoma/Xreal/PolyhedronClip.cpp @@ -69,7 +69,7 @@ class PolyhedronClipOp if(put_contacts == 1){ body1 -> contacts.push_back( Contact() ); body1 -> contacts.back().set(distance, cp1, cp2, normal, &sphere, 0, body1, body2); - body2 -> contacts2.push_back( ContactRef(&body1 -> contacts.back() - body1 -> contacts.begin(), body1 -> contacts) ); + body2 -> contacts2.push_back( ContactRef(body1 -> contacts.size() - 1, body1 -> contacts) ); } else if(distance < 0){ @@ -98,7 +98,7 @@ class PolyhedronClipOp if(put_contacts == 1){ body1 -> contacts.push_back( Contact() ); body1 -> contacts.back().set(dist_abs, cp1, cp2, normal, &sphere, 0, body1, body2); - body2 -> contacts2.push_back( ContactRef(&body1 -> contacts.back() - body1 -> contacts.begin(), body1 -> contacts) ); + body2 -> contacts2.push_back( ContactRef(body1 -> contacts.size() - 1, body1 -> contacts) ); } else if(dist_abs < 0){ diff --git a/MechoSoma/Xreal/ResourceDispatcher.cpp b/MechoSoma/Xreal/ResourceDispatcher.cpp index 850ba024..38e85160 100644 --- a/MechoSoma/Xreal/ResourceDispatcher.cpp +++ b/MechoSoma/Xreal/ResourceDispatcher.cpp @@ -1,8 +1,8 @@ #include "StdAfx.h" #include "ResourceDispatcher.h" -#include "xreal_utl.h" -#include "statistics.h" -#include "Terra.h" +#include "Xreal_utl.h" +#include "Statistics.h" +#include "TERRA.H" int ResourceUser::IDs; diff --git a/MechoSoma/Xreal/SST_Reader.h b/MechoSoma/Xreal/SST_Reader.h index a2535e15..e9001271 100644 --- a/MechoSoma/Xreal/SST_Reader.h +++ b/MechoSoma/Xreal/SST_Reader.h @@ -1,6 +1,8 @@ #ifndef __SST_READER__ #define __SST_READER__ +#include + struct UsualRecord { int x, y; @@ -16,7 +18,7 @@ struct DirectedRecord : UsualRecord int vmapOpenResource(char* fname,XStream& fh); template -class SST_Reader : public list +class SST_Reader : public std::list { public: @@ -43,11 +45,10 @@ SST_Reader(char* fname) break; ++buffer; } - push_back(Record()); - back().read(buffer); + this->push_back(Record()); + this->back().read(buffer); } } }; #endif // __SST_READER__ - \ No newline at end of file diff --git a/MechoSoma/Xreal/SimpleClip.cpp b/MechoSoma/Xreal/SimpleClip.cpp index b07f53dc..c635c90c 100644 --- a/MechoSoma/Xreal/SimpleClip.cpp +++ b/MechoSoma/Xreal/SimpleClip.cpp @@ -3,11 +3,11 @@ #include "Mesh3ds.h" #include "CycledMath.h" #include "IVisGeneric.h" -#include "terra.h" -#include "xreal_utl.h" +#include "TERRA.H" +#include "Xreal_utl.h" #include "SST_Reader.h" #include "CameraPrm.h" -#include "Mechosoma.h" +#include "mechosoma.h" #include "Statistics.h" #include "DebugPrm.h" #include "Params.h" @@ -618,7 +618,7 @@ float Triangle::area() const MatXf TriangleMap::getPlacementPose(const Vect3f& center, int disabled_triangles_mask) { - const float dz = 0; //ïðèïîäíèìàåò íàä ïîâåðõíîñòüþ + const float dz = 0; //������������ ��� ������������ const Triangle* tri = 0; float s, smax = 0; SList& list = (*this)(center.xi(), center.yi()); @@ -675,8 +675,8 @@ class ClosetNonVerticalTriangleSearchOp MatXf getPlacementPose(const Vect3f& center) { - const float dz = 3; //ïðèïîäíèìàåò íàä ïîâåðõíîñòüþ - float radius = 20; // ðàäèóñ îêðåñòíîñòè äëÿ ïîèñêà (÷åì áîëüøå - òåì ìåäëåííåé) + const float dz = 3; //������������ ��� ������������ + float radius = 20; // ������ ����������� ��� ������ (��� ������ - ��� ���������) const Triangle* tri; while(1){ ClosetNonVerticalTriangleSearchOp op(center); diff --git a/MechoSoma/Xreal/SimpleClip.h b/MechoSoma/Xreal/SimpleClip.h index 42ec1ae5..4c10ac57 100644 --- a/MechoSoma/Xreal/SimpleClip.h +++ b/MechoSoma/Xreal/SimpleClip.h @@ -109,7 +109,7 @@ class Triangle : public fPlane, public Grid2DElement ////////////////////////////////////// // TriangleBrush ////////////////////////////////////// -class TriangleBrush : vector +class TriangleBrush : std::vector { const MatXf& pose; iRectangle bound; @@ -160,11 +160,11 @@ class SphereList : public vector {}; ////////////////////////////////////////// // Triangle Map ////////////////////////////////////////// -class TriangleMap : public slist, public Grid2D +class TriangleMap : public std::list, public Grid2D { - typedef slist List; + typedef std::list List; typedef Grid2D Grid; - typedef hash_map SpotMap; + typedef std::unordered_map SpotMap; SpotMap spot_map; diff --git a/MechoSoma/Xreal/SmartMissile.cpp b/MechoSoma/Xreal/SmartMissile.cpp index 684317c8..4d194a8e 100644 --- a/MechoSoma/Xreal/SmartMissile.cpp +++ b/MechoSoma/Xreal/SmartMissile.cpp @@ -4,7 +4,7 @@ #include "FlyingObject.h" #include "SmartMissile.h" #include "BodyDispatcher.h" -#include "m3d_Effects.h" +#include "M3d_Effects.h" #include "sound.h" //////////////////////////////////////////////////////// @@ -62,7 +62,7 @@ void SmartMissile::set_owner(int ID, int duration) void SmartMissile::quant() { - if(!time_to_live || test_collision(0)){ // ñòîëêíîâåíèå ñ ïîâåðõíîñòüþ + if(!time_to_live || test_collision(0)){ // ������������ � ������������ kill(); } } diff --git a/MechoSoma/Xreal/SmartStone.cpp b/MechoSoma/Xreal/SmartStone.cpp index 533fc7e1..b763ead3 100644 --- a/MechoSoma/Xreal/SmartStone.cpp +++ b/MechoSoma/Xreal/SmartStone.cpp @@ -2,9 +2,9 @@ #include "Body.h" #include "PointControlledObject.h" #include "SmartStone.h" -#include "params.h" +#include "Params.h" #include "AnimalsPrm.h" -#include "Sound.h" +#include "sound.h" #include "SimpleClip.h" void fxlabStoneDust(Vect3f& p,float r); @@ -76,7 +76,10 @@ void SmartStoneRacer::quant() switch(state){ case Rolling: state = Flying; - fxlabStoneDust(Vect3f(R()), radius()); + { + Vect3f v1(R()); + fxlabStoneDust(v1, radius()); + } break; case Flying: state = Rolling; diff --git a/MechoSoma/Xreal/Spider.cpp b/MechoSoma/Xreal/Spider.cpp index 04cd7b57..ecfb39a4 100644 --- a/MechoSoma/Xreal/Spider.cpp +++ b/MechoSoma/Xreal/Spider.cpp @@ -1,9 +1,9 @@ #include "StdAfx.h" #include "Body.h" #include "Spider.h" -#include "m3d_effects.h" +#include "M3d_effects.h" #include "sound.h" -#include "params.h" +#include "Params.h" #include "AnimalsPrm.h" #include "SimpleClip.h" diff --git a/MechoSoma/Xreal/StdAfx.cpp b/MechoSoma/Xreal/StdAfx.cpp index c4f87efd..3f6a7b0b 100644 --- a/MechoSoma/Xreal/StdAfx.cpp +++ b/MechoSoma/Xreal/StdAfx.cpp @@ -2,5 +2,5 @@ // DEDemo.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information -#include "stdafx.h" +#include "StdAfx.h" diff --git a/MechoSoma/Xreal/StdAfx.h b/MechoSoma/Xreal/StdAfx.h index fa3efcfe..c9c8dd82 100644 --- a/MechoSoma/Xreal/StdAfx.h +++ b/MechoSoma/Xreal/StdAfx.h @@ -10,11 +10,15 @@ #pragma once #endif // _MSC_VER > 1000 +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include #define DIRECTINPUT_VERSION 0x0700 #include +#endif + // Standart includes #include #include @@ -24,7 +28,7 @@ #include #include -#include +#include #include @@ -32,18 +36,16 @@ #include #include //#include "slist.h" -#include "hash_map.h" +#include //#include #include -#include "my_STL.h" - // XTool #include "Handle.h" -#include "_xtool.h" -#include "xgr.h" +#include "xtool.h" +#include "XGR.h" #include "xmath.h" -#include "cycledMath.h" +#include "CycledMath.h" #include "Timers.h" #include "Mesh3ds.h" diff --git a/MechoSoma/Xreal/Stone.cpp b/MechoSoma/Xreal/Stone.cpp index f62ddffc..06c5be7f 100644 --- a/MechoSoma/Xreal/Stone.cpp +++ b/MechoSoma/Xreal/Stone.cpp @@ -76,7 +76,8 @@ void Stone::damage(float decr,int damage_style) void Stone::kill() { Body::kill(); - fxlabStoneDust(Vect3f(R()), radius()); + Vect3f v1(R()); + fxlabStoneDust(v1, radius()); startSound(EFF_ROCK_BREAK); }; diff --git a/MechoSoma/Xreal/TitaniumBall.cpp b/MechoSoma/Xreal/TitaniumBall.cpp index 28b0b234..3573506a 100644 --- a/MechoSoma/Xreal/TitaniumBall.cpp +++ b/MechoSoma/Xreal/TitaniumBall.cpp @@ -1,13 +1,13 @@ //////////////////////////////////////////////////////////////////// -// Òèòàíîâûé øàðèê +// ��������� ����� //////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "BodyDispatcher.h" #include "Mechos.h" #include "TitaniumBall.h" #include "Params.h" -#include "mesh3ds.h" -#include "m3d_effects.h" +#include "Mesh3ds.h" +#include "M3d_effects.h" #include "sound.h" #include "AnimalArcansPrm.h" diff --git a/MechoSoma/Xreal/TnT/FMAT.H b/MechoSoma/Xreal/TnT/FMAT.H index 24173406..e4fd3a55 100644 --- a/MechoSoma/Xreal/TnT/FMAT.H +++ b/MechoSoma/Xreal/TnT/FMAT.H @@ -13,14 +13,14 @@ #ifndef FMAT_H #define FMAT_H -#include "subscrpt.h" -#include "vec.h" +#include "SUBSCRPT.H" +#include "VEC.H" #include #include -#include -#include +#include +#include #ifdef TNT_USE_REGIONS -#include "region2d.h" +#include "REGION2D.H" #endif // simple 1-based, column oriented Matrix class diff --git a/MechoSoma/Xreal/TnT/INDEX.H b/MechoSoma/Xreal/TnT/INDEX.H index ada02528..29414ab9 100644 --- a/MechoSoma/Xreal/TnT/INDEX.H +++ b/MechoSoma/Xreal/TnT/INDEX.H @@ -13,7 +13,7 @@ #ifndef INDEX_H #define INDEX_H -#include "subscrpt.h" +#include "SUBSCRPT.H" namespace TNT { diff --git a/MechoSoma/Xreal/TnT/QR.H b/MechoSoma/Xreal/TnT/QR.H index 288f7420..2c90a8c0 100644 --- a/MechoSoma/Xreal/TnT/QR.H +++ b/MechoSoma/Xreal/TnT/QR.H @@ -33,7 +33,7 @@ #include //for sqrt() & fabs() -#include "tntmath.h" // for sign() +#include "TNTMATH.H" // for sign() // Classical QR factorization, based on Stewart[1973]. // diff --git a/MechoSoma/Xreal/TnT/REGION2D.H b/MechoSoma/Xreal/TnT/REGION2D.H index 57b25ca3..48b35c29 100644 --- a/MechoSoma/Xreal/TnT/REGION2D.H +++ b/MechoSoma/Xreal/TnT/REGION2D.H @@ -12,8 +12,8 @@ #ifndef REGION2D_H #define REGION2D_H -#include "index.h" -#include +#include "INDEX.H" +#include #include namespace TNT diff --git a/MechoSoma/Xreal/TnT/TNT.H b/MechoSoma/Xreal/TnT/TNT.H index defe70ac..8466f5ce 100644 --- a/MechoSoma/Xreal/TnT/TNT.H +++ b/MechoSoma/Xreal/TnT/TNT.H @@ -19,7 +19,7 @@ //--------------------------------------------------------------------- // Include current version //--------------------------------------------------------------------- -#include "version.h" +#include "VERSION.H" //--------------------------------------------------------------------- // Define the data type used for matrix and vector Subscripts. @@ -31,7 +31,7 @@ // See subscrpt.h for details. //--------------------------------------------------------------------- -#include "subscrpt.h" +#include "SUBSCRPT.H" @@ -69,7 +69,7 @@ // //#define __NEED_ABS_MIN_MAX_ -#include "tntmath.h" +#include "TNTMATH.H" #endif diff --git a/MechoSoma/Xreal/TnT/TRANSV.H b/MechoSoma/Xreal/TnT/TRANSV.H index 205d3dbf..32f1c059 100644 --- a/MechoSoma/Xreal/TnT/TRANSV.H +++ b/MechoSoma/Xreal/TnT/TRANSV.H @@ -13,9 +13,9 @@ #ifndef TRANSV_H #define TRANSV_H -#include +#include #include -#include "vec.h" +#include "VEC.H" namespace TNT { diff --git a/MechoSoma/Xreal/TnT/TRISLV.H b/MechoSoma/Xreal/TnT/TRISLV.H index a90229aa..00580206 100644 --- a/MechoSoma/Xreal/TnT/TRISLV.H +++ b/MechoSoma/Xreal/TnT/TRISLV.H @@ -14,7 +14,7 @@ #define TRISLV_H -#include "triang.h" +#include "TRIANG.H" namespace TNT { diff --git a/MechoSoma/Xreal/TnT/VEC.H b/MechoSoma/Xreal/TnT/VEC.H index cdf2e663..9c0047ea 100644 --- a/MechoSoma/Xreal/TnT/VEC.H +++ b/MechoSoma/Xreal/TnT/VEC.H @@ -14,11 +14,11 @@ #ifndef VEC_H #define VEC_H -#include "subscrpt.h" +#include "SUBSCRPT.H" #include #include -#include -#include +#include +#include namespace TNT { diff --git a/MechoSoma/Xreal/Tomato.cpp b/MechoSoma/Xreal/Tomato.cpp index 8c3747bf..0b1ccfcc 100644 --- a/MechoSoma/Xreal/Tomato.cpp +++ b/MechoSoma/Xreal/Tomato.cpp @@ -1,16 +1,16 @@ //////////////////////////////////////////////////////////////////// -// Êðèñòàëë +// �������� //////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "Body.h" #include "Tomato.h" #include "Contact.h" -#include "mesh3ds.h" -#include "m3d_effects.h" +#include "Mesh3ds.h" +#include "M3d_effects.h" #include "sound.h" #include "AnimalArcansPrm.h" -#include "params.h" +#include "Params.h" static const float overlap_decrement = 0.005f; @@ -63,7 +63,8 @@ void Tomato::body_overlap_reaction(Body& body) void Tomato::kill() { - fxlabTomatoBurst(Vect3f(R())); + Vect3f v1(R()); + fxlabTomatoBurst(v1); startSound(EFF_TOMATO_ADD); Body::kill(); } diff --git a/MechoSoma/Xreal/TrackIterator.cpp b/MechoSoma/Xreal/TrackIterator.cpp index d71093b5..1fbca483 100644 --- a/MechoSoma/Xreal/TrackIterator.cpp +++ b/MechoSoma/Xreal/TrackIterator.cpp @@ -1,7 +1,7 @@ #include "StdAfx.h" #include "TrackIterator.h" -#include "Track.h" -#include "Race.h" +#include "track.h" +#include "race.h" #include "SimpleClip.h" #undef assert @@ -64,7 +64,7 @@ TrackIterator& TrackIterator::operator ++ () cp = mch_raceD -> cpLst -> first(); assert(cp); br = cp -> getTrack(); - xassert("Ïëîõîé òðýê!!!" && br); + xassert("������ ����!!!" && br); el = br -> pointLst -> first(); } element = el; @@ -86,7 +86,7 @@ TrackIterator& TrackIterator::operator -- () cp = cp -> prev; assert(cp); br = cp -> getTrack(); - xassert("Ïëîõîé òðýê!!!" && br); + xassert("������ ����!!!" && br); el = br -> pointLst -> last(); } element = el; diff --git a/MechoSoma/Xreal/TrackSpline.cpp b/MechoSoma/Xreal/TrackSpline.cpp index 42997a9a..5e1c6bb1 100644 --- a/MechoSoma/Xreal/TrackSpline.cpp +++ b/MechoSoma/Xreal/TrackSpline.cpp @@ -1,7 +1,7 @@ #include "StdAfx.h" #include "TrackSpline.h" #include "CycledMath.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" TrackSpline::TrackSpline(float avr_dist, int step_) { @@ -76,8 +76,8 @@ TrackSpline& TrackSpline::operator -= (float dt) Vect3f TrackSpline::operator()() const { - return CYCLE((3.0f/2.0f*P[1]-3.0f/2.0f*P[2]-P[0]/2.0f+P[3]/2.0f)*t*t*t + - (2.0f*P[2]+P[0]-P[3]/2.0f-5.0f/2.0f*P[1])*t*t + (P[2]/2.0f-P[0]/2.0f)*t + P[1]); + Vect3f v1((3.0f/2.0f*P[1]-3.0f/2.0f*P[2]-P[0]/2.0f+P[3]/2.0f)*t*t*t + (2.0f*P[2]+P[0]-P[3]/2.0f-5.0f/2.0f*P[1])*t*t + (P[2]/2.0f-P[0]/2.0f)*t + P[1]); + return CYCLE(v1); } Vect3f TrackSpline::deriv() const diff --git a/MechoSoma/Xreal/WorldDispatcher.cpp b/MechoSoma/Xreal/WorldDispatcher.cpp index abe7b225..bb202ec3 100644 --- a/MechoSoma/Xreal/WorldDispatcher.cpp +++ b/MechoSoma/Xreal/WorldDispatcher.cpp @@ -1,7 +1,7 @@ #include "StdAfx.h" #include "BodyDispatcher.h" #include "XrealWorlds.h" -#include "xreal_utl.h" +#include "Xreal_utl.h" #include "SST_Reader.h" #include "PointControlledObject.h" #include "BonusMan.h" diff --git a/MechoSoma/Xreal/Worm.cpp b/MechoSoma/Xreal/Worm.cpp index 2fa45654..cf2575f2 100644 --- a/MechoSoma/Xreal/Worm.cpp +++ b/MechoSoma/Xreal/Worm.cpp @@ -5,7 +5,7 @@ #include "CrawlingObject.h" #include "Worm.h" #include "Mesh3ds.h" -#include "Sound.h" +#include "sound.h" void fxlabGreenSlime(const Vect3f& v, const MatXf& mat); void fxlabYellowSlime1(const Vect3f& v, const MatXf& mat); diff --git a/MechoSoma/Xreal/Xreal.cpp b/MechoSoma/Xreal/Xreal.cpp index ee1fbc81..b28b00b9 100644 --- a/MechoSoma/Xreal/Xreal.cpp +++ b/MechoSoma/Xreal/Xreal.cpp @@ -4,13 +4,15 @@ #include "Mechos.h" #include "SimpleClip.h" //#include "PrmEdit.h" -#include "params.h" -#include "terra.h" +#include "Params.h" +#include "TERRA.H" #include "IVisGeneric.h" #include "Dispatcher.h" -#include "Mechosoma.h" +#include "mechosoma.h" +#ifdef _WIN32 #include "d3dtypes.h" -#include "xreal_utl.h" +#endif +#include "Xreal_utl.h" #include "FieldGrid.h" #include "XGR.h" #include "PolyhedronLibrary.h" @@ -43,8 +45,10 @@ int mechos_default_config_counter = 0; int Xreal_key_active = 0; +#ifdef _WIN32 int controlfp_flags = _PC_24; int controlfp_mask = _MCW_PC; +#endif void Xreal_init() { @@ -78,7 +82,7 @@ void Xreal_init() CONTROL_FP(); } - // Âñå ïîòîêè - â ôàéëû + // ��� ������ - � ����� //cerr = *(new ofstream("cerr")); // cerr //_iob[1] = *fopen( "stdout", "w" ); // stdout //_iob[2] = *fopen( "stderr", "w" ); // stderr @@ -318,6 +322,7 @@ void BodyDispatcher::draw_handler() void draw_text(char* text) { +#ifdef _WIN32 HDC hdc; RECT rect = { gameWnd -> PosX, gameWnd -> PosY, gameWnd -> PosX + gameWnd -> SizeX , gameWnd -> PosY + + gameWnd -> SizeY }; GetBackBufferDC(&hdc); @@ -333,10 +338,12 @@ void draw_text(char* text) // xrealIGR -> SetViewColor(0, 0, 100, 80); // mchA_d3dOutString(gameWnd -> PosX + 5,gameWnd -> PosY + 5, 1.4f, 1.4f, msg_buf, RGB_MAKE(255,255,255), 255, 2, 0, 0.6f, 0); // } +#endif } const char* check_command_line(const char* switch_str) { +#ifdef _WIN32 for(int i = 1; i < __argc; i ++){ const char* s = strstr(__argv[i], switch_str); if(s){ @@ -347,6 +354,7 @@ const char* check_command_line(const char* switch_str) } cont:; } +#endif return 0; } diff --git a/MechoSoma/Xreal/XrealWorlds.h b/MechoSoma/Xreal/XrealWorlds.h index d5b6ff4c..d52f1f4d 100644 --- a/MechoSoma/Xreal/XrealWorlds.h +++ b/MechoSoma/Xreal/XrealWorlds.h @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////// // Worlds ///////////////////////////////////////////////////////////////////// -#include "params.h" +#include "Params.h" class WaterWorld : public WorldDispatcher { diff --git a/MechoSoma/Xreal/Xreal_utl.cpp b/MechoSoma/Xreal/Xreal_utl.cpp index 46a29a78..f756a5b2 100644 --- a/MechoSoma/Xreal/Xreal_utl.cpp +++ b/MechoSoma/Xreal/Xreal_utl.cpp @@ -4,11 +4,11 @@ #include "SimpleClip.h" #include "mechosoma.h" #include "XGR.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "IVisGeneric.h" #include "IGraph3d.h" #include "Xreal_utl.h" -#include "params.h" +#include "Params.h" #include "DebugPrm.h" int XCOL(int color, int intensity, int alpha) diff --git a/MechoSoma/Xreal/Xreal_utl.h b/MechoSoma/Xreal/Xreal_utl.h index 3eaabc65..bda206dc 100644 --- a/MechoSoma/Xreal/Xreal_utl.h +++ b/MechoSoma/Xreal/Xreal_utl.h @@ -3,7 +3,11 @@ extern int controlfp_flags; extern int controlfp_mask; +#ifdef _WIN32 #define CONTROL_FP() _controlfp(controlfp_flags, controlfp_mask); +#else +#define CONTROL_FP() +#endif //////////////////////////////////////////////////////////////////////////////////////////////////// // Extern Symbols diff --git a/MechoSoma/iScreen/ACI_SCR.H b/MechoSoma/iScreen/ACI_SCR.H index d9c9338c..b1b983bf 100644 --- a/MechoSoma/iScreen/ACI_SCR.H +++ b/MechoSoma/iScreen/ACI_SCR.H @@ -605,9 +605,9 @@ float dValue, dValueCur; float period; acsTimer(float st,float pr,float d); -void acsTimer::Quant(float dt); -float acsTimer::Value(void); -float acsTimer::Phase(void); +void Quant(float dt); +float Value(void); +float Phase(void); void acsShowSlotInfo(void); }; diff --git a/MechoSoma/iScreen/ACS_CORE.CPP b/MechoSoma/iScreen/ACS_CORE.CPP index 6db67e85..1b6bc17c 100644 --- a/MechoSoma/iScreen/ACS_CORE.CPP +++ b/MechoSoma/iScreen/ACS_CORE.CPP @@ -1,22 +1,22 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include "hfont.h" +#include "HFONT.H" #include "sound.h" -#include "aci_evnt.h" -#include "aci_scr.h" +#include "ACI_EVNT.H" +#include "ACI_SCR.H" -#include "keys.h" +#include "KEYS.H" #include "arcane_menu.h" #include "arcane_menu_d3d.h" #include "I-World.h" -#include "xJoystick.h" +#include "XJoystick.h" -#include "xgr.h" +#include "XGR.h" #include "IGraph3d.h" #include "LocalVersion.h" diff --git a/MechoSoma/iScreen/ACS_EXT.CPP b/MechoSoma/iScreen/ACS_EXT.CPP index 9102281b..8dda60e2 100644 --- a/MechoSoma/iScreen/ACS_EXT.CPP +++ b/MechoSoma/iScreen/ACS_EXT.CPP @@ -3,16 +3,18 @@ #include "hbm.h" -#include "hfont.h" +#include "HFONT.H" #include "mechosoma.h" +#ifdef _WIN32 #include "win32f.h" +#endif #include "arcane_menu.h" -#include "aci_ids.h" -#include "aci_evnt.h" -#include "aci_scr.h" -#include "keys.h" +#include "ACI_IDS.H" +#include "ACI_EVNT.H" +#include "ACI_SCR.H" +#include "KEYS.H" #include "sound.h" #include "sound_api.h" @@ -20,10 +22,10 @@ #include "race.h" -#include "_xsound.h" +#include "xsound.h" #include "controls.h" -#include "xJoystick.h" +#include "XJoystick.h" #include "I-World.h" #include "GameClient.h" @@ -33,6 +35,10 @@ #include "mch_common.h" // For far target #include "IGraph3d.h" // For far target +#ifndef _WIN32 +#define MK_LBUTTON 0x0001 +#endif + /* ----------------------------- STRUCT SECTION ----------------------------- */ const int KEY_CONFIG_MAX = 3; @@ -2821,7 +2827,7 @@ void acsSaveScreenState(XBuffer* xb,aciScreen* scr) ev = (aciScreenEvent*)scr -> events -> fPtr; while(ev){ if(ev -> flags & ACS_EVENT_ACTIVE){ - *xb < (int)ev < ev -> flags < ev -> CurTimer; + *xb < (long)ev < ev -> flags < ev -> CurTimer; cm = (aciScreenEventCommand*)ev -> commSeq -> fPtr; while(cm){ *xb < cm -> flags; @@ -2836,7 +2842,7 @@ void acsSaveScreenState(XBuffer* xb,aciScreen* scr) ev = (aciScreenEvent*)obj -> events -> fPtr; while(ev){ if(ev -> flags & ACS_EVENT_ACTIVE){ - *xb < (int)ev < ev -> flags < ev -> CurTimer; + *xb < (long)ev < ev -> flags < ev -> CurTimer; cm = (aciScreenEventCommand*)ev -> commSeq -> fPtr; while(cm){ *xb < cm -> flags; diff --git a/MechoSoma/iScreen/HFONT.CPP b/MechoSoma/iScreen/HFONT.CPP index 35735389..1be8d773 100644 --- a/MechoSoma/iScreen/HFONT.CPP +++ b/MechoSoma/iScreen/HFONT.CPP @@ -2,8 +2,8 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include "hfont.h" -#include "aci_scr.h" +#include "HFONT.H" +#include "ACI_SCR.H" #include "mch_common.h" // For far target diff --git a/MechoSoma/iScreen/I-World.cpp b/MechoSoma/iScreen/I-World.cpp index 86312c23..a1a860f5 100644 --- a/MechoSoma/iScreen/I-World.cpp +++ b/MechoSoma/iScreen/I-World.cpp @@ -4,26 +4,26 @@ #include "SST_Reader.h" -#include "mch_rto.h" +#include "mch_rto.H" #include "mechosoma.h" #include "race.h" -#include "mesh3ds.h" -#include "xreal.h" -#include "terra.h" +#include "Mesh3ds.h" +#include "Xreal.h" +#include "TERRA.H" #include "arcane.h" #include "SpriteDispatcher.h" #include "arcane_menu.h" #include "sound.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" #include "iText.h" -#include "aci_ids.h" -#include "aci_evnt.h" -#include "aci_scr.h" -#include "hfont.h" -#include "keys.h" +#include "ACI_IDS.H" +#include "ACI_EVNT.H" +#include "ACI_SCR.H" +#include "HFONT.H" +#include "KEYS.H" #include "LocalVersion.h" @@ -41,7 +41,7 @@ #include "parts_pool.h" #include "aci_parser.h" -#include "scr_defs.h" +#include "SCR_DEFS.H" #include "PlayWSC.h" @@ -255,7 +255,8 @@ void iWorldDispatcher::CreateTeleports(void) tpLst.append(tp); - fxlabCreateTeleport(it -> World,it -> Track,Vect3f(it -> PosX,it -> PosY,0),1); + Vect3f v1(it -> PosX,it -> PosY,0); + fxlabCreateTeleport(it -> World,it -> Track,v1,1); } } @@ -602,9 +603,10 @@ void iWorldDispatcher::Quant(void) iwArrowPos -> Quant(dt); R = iwAssembly_R; - R.z = iwAssembly_Z0 + 30.0f + 20.0f * iwArrowPos -> Value(); + R.z = iwAssembly_Z0 + 30.0f + 20.0f * iwArrowPos -> Value(); - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)iwAssembly_Arrow,&R,&Vect3f(90.0f,iwArrowRot -> Phase()*180.0f/M_PI,0.0f)); + Vect3f v1(90.0f,iwArrowRot -> Phase()*180.0f/M_PI,0.0f); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)iwAssembly_Arrow,&R,&v1); if(iwHideArrows || mode == IW_ASSEMBLY || (mchSplitScreenGame && iworld_D2 -> AssemblyMode())) iwAssembly_Arrow -> SetVisible(0); @@ -613,9 +615,10 @@ void iWorldDispatcher::Quant(void) R = iwElect_R; - R.z = iwElect_Z0 + 30.0f + 20.0f * iwArrowPos -> Value(); + R.z = iwElect_Z0 + 30.0f + 20.0f * iwArrowPos -> Value(); - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)iwElectionary_Arrow,&R,&Vect3f(90.0f,iwArrowRot -> Phase()*180.0f/M_PI,0.0f)); + Vect3f v2(90.0f,iwArrowRot -> Phase()*180.0f/M_PI,0.0f); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)iwElectionary_Arrow,&R,&v2); if(iwHideArrows || mode == IW_ELECTIONARY || (mchSplitScreenGame && iworld_D2 -> ElectionaryMode())) iwElectionary_Arrow -> SetVisible(0); @@ -627,7 +630,8 @@ void iWorldDispatcher::Quant(void) if(tp -> arrow){ d = ZV(XCYCL(tp -> PosX),YCYCL(tp -> PosY)) + 50.0f + 20.0f * iwArrowPos -> Value(); R = Vect3f(tp -> PosX,tp -> PosY,d); - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)tp -> arrow,&R,&Vect3f(90.0f,iwArrowRot -> Phase()*180.0f/M_PI,0.0f)); + Vect3f v3(90.0f,iwArrowRot -> Phase()*180.0f/M_PI,0.0f); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)tp -> arrow,&R,&v3); if(iwHideArrows || (mode == IW_TELEPORT && nextWorld == tp -> World && nextTrack == tp -> Track) || (mchSplitScreenGame && iworld_D2 -> TeleportMode() && iworld_D2 -> NextWorld() == tp -> World && iworld_D2 -> NextTrack() == tp -> Track)) tp -> arrow -> SetVisible(0); @@ -1832,7 +1836,9 @@ void iWorldDispatcher::AssemblyQuant(void) iwAssembly_CurPartAngle += da; if(iwAssembly_CurPartAngle > 360.0f) iwAssembly_CurPartAngle -= 360.0f; - gb_IVisGeneric -> dSetObjectPosition((cUnknownClass*)parts[curPartType][curPart],&Vect3f(0,0,0),&Vect3f(0,0,iwAssembly_CurPartAngle)); + Vect3f v1(0,0,0); + Vect3f v2(0,0,iwAssembly_CurPartAngle); + gb_IVisGeneric -> dSetObjectPosition((cUnknownClass*)parts[curPartType][curPart],&v1,&v2); aciScreenObject* p; p = curScreen -> GetObject(10); @@ -2326,7 +2332,9 @@ void iwInitWorld(void) z += (obj -> Real.Max[2] - obj -> Real.Min[2]) / 2.0f; - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)obj,&Vect3f(x,y,z),&Vect3f(0,0,al * 180.0f / M_PI + 90.0f)); + Vect3f v1(x,y,z); + Vect3f v2(0,0,al * 180.0f / M_PI + 90.0f); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)obj,&v1,&v2); iwFigures[i] = obj; } @@ -2563,7 +2571,9 @@ void iWorldDispatcher::InitFigures(void) z += (figures[i] -> Real.Max[2] - figures[i] -> Real.Min[2]) / 2.0f; - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)figures[i],&Vect3f(x,y,z),&Vect3f(0,0,al * 180.0f / M_PI + 90.0f)); + Vect3f v1(x,y,z); + Vect3f v2(0,0,al * 180.0f / M_PI + 90.0f); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)figures[i],&v1,&v2); n ++; SetFigureAnimation(i,0); @@ -3080,7 +3090,9 @@ void iWorldDispatcher::AssemblyCoordsQuant(void) y = iwAssembly_R.y + r1 * sin(al); z = iwPartsB[i][j].X(); - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)m,&Vect3f(x,y,z),&Vect3f(0,0,al * 180.0f / M_PI - 90.0f)); + Vect3f v1(x,y,z); + Vect3f v2(0,0,al * 180.0f / M_PI - 90.0f); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)m,&v1,&v2); if(i == curPartType && fabs(iwPartsB[i][j].X() - iwAssembly_Z0) < 10.0f) fxlabPartWave(x,y); diff --git a/MechoSoma/iScreen/acs_quant.cpp b/MechoSoma/iScreen/acs_quant.cpp index 5b719526..3e37bcc4 100644 --- a/MechoSoma/iScreen/acs_quant.cpp +++ b/MechoSoma/iScreen/acs_quant.cpp @@ -2,9 +2,9 @@ #include "StdAfx.h" #include "iText.h" -#include "mesh3ds.h" +#include "Mesh3ds.h" -#include "hfont.h" +#include "HFONT.H" #include "arcane_menu.h" #include "arcane_menu_d3d.h" @@ -17,16 +17,16 @@ #include "parts_pool.h" #include "race.h" -#include "aci_evnt.h" -#include "aci_scr.h" -#include "aci_ids.h" +#include "ACI_EVNT.H" +#include "ACI_SCR.H" +#include "ACI_IDS.H" -#include "keys.h" +#include "KEYS.H" #include "sound.h" -#include "xJoystick.h" +#include "XJoystick.h" -#include "Mechosoma.h" +#include "mechosoma.h" #include "mch_common.h" // For far target #include "IGraph3d.h" @@ -291,8 +291,8 @@ int acsDistRnd; acsScreenMatrix acsScr0; acsScreenMatrix acsScr1; -char* mchIscreenINI = "RESOURCE\\ISCREEN\\iscreen.ini"; -char* mchLocalINI = "RESOURCE\\ISCREEN\\local.ini"; +char* mchIscreenINI = "RESOURCE/ISCREEN/iscreen.ini"; +char* mchLocalINI = "RESOURCE/ISCREEN/local.ini"; acsTextureMosaic* acsTM = NULL; acsEssenceData** acsBody = NULL; @@ -604,16 +604,17 @@ void mchA_OutChar3D(float x,float y,float z,int fnt,int ch,float r,float g,float scale_x = (float)XGR_MAXX / 640.0f; scale_y = (float)XGR_MAXY / 480.0f; - gb_IVisGeneric -> SetObjectScale((cUnknownClass*)acsFont3D[ch], - &Vect3f(acsFont3D_ScaleX[fnt] * scale_x * sc,acsFont3D_ScaleY[fnt] * scale_y * sc,acsFont3D_ScaleZ[fnt] * sc)); + Vect3f v1(acsFont3D_ScaleX[fnt] * scale_x * sc,acsFont3D_ScaleY[fnt] * scale_y * sc,acsFont3D_ScaleZ[fnt] * sc); + gb_IVisGeneric -> SetObjectScale((cUnknownClass*)acsFont3D[ch],&v1); rr = Vect3f(0,0,0); r0 = Vect3f(x,y,z); if(rr.norm() > 3.0f) rr.normalize(3.0f); - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)acsFont3D[ch], - &Vect3f(r0.x,r0.y,r0.z),&Vect3f(0,0,0)); + Vect3f v2(r0.x,r0.y,r0.z); + Vect3f v3(0,0,0); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)acsFont3D[ch],&v2,&v3); if(mat_fl) acsFont3D[ch] -> SetOrientation(mat); @@ -634,8 +635,8 @@ void acsOutChar3D(float x,float y,float z,int fnt,int ch,float r,float g,float b scale_x = (float)XGR_MAXX / 640.0f; scale_y = (float)XGR_MAXY / 480.0f; - gb_IVisGeneric -> SetObjectScale((cUnknownClass*)acsFont3D[ch], - &Vect3f(acsFont3D_ScaleX[fnt] * scale_x * sc,acsFont3D_ScaleY[fnt] * scale_y * sc,acsFont3D_ScaleZ[fnt] * sc)); + Vect3f v1(acsFont3D_ScaleX[fnt] * scale_x * sc,acsFont3D_ScaleY[fnt] * scale_y * sc,acsFont3D_ScaleZ[fnt] * sc); + gb_IVisGeneric -> SetObjectScale((cUnknownClass*)acsFont3D[ch],&v1); rr = Vect3f(0,0,0); r0 = Vect3f(x,y,z); @@ -645,8 +646,9 @@ void acsOutChar3D(float x,float y,float z,int fnt,int ch,float r,float g,float b if(rr.norm() > 3.0f) rr.normalize(3.0f); // r0 += z0 * rr; - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)acsFont3D[ch], - &Vect3f(r0.x,r0.y,r0.z),&Vect3f(0,0,0)); + Vect3f v2(r0.x,r0.y,r0.z); + Vect3f v3(0,0,0); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)acsFont3D[ch],&v2,&v3); if(z0 > 0.5f) z0 = 0.5f; if(z0 < -0.5f) z0 = -0.5f; @@ -773,7 +775,8 @@ void acsOutMouse3D(void) x = XGR_MouseObj.PosX + XGR_MouseObj.SizeX/2; y = XGR_MouseObj.PosY + XGR_MouseObj.SizeY/2; - gb_IVisGeneric -> SetObjectScale((cUnknownClass*)acsMouse3D,&Vect3f(acsMouseScale)); + Vect3f v1(acsMouseScale); + gb_IVisGeneric -> SetObjectScale((cUnknownClass*)acsMouse3D,&v1); f = acsCalcForce(acsMouseZ - acsMouse3D -> rmaxTotal()/2.0f,acsMouseZ + acsMouse3D -> rmaxTotal()/2.0f,acsWaterZ); acsMouseVz += f * acs_dT; @@ -791,8 +794,9 @@ void acsOutMouse3D(void) Vect3f r = getDist(target, pos); Mat3f M = Mat3f(M_PI/2 + r.psi(), Z_AXIS)*Mat3f(r.theta(), X_AXIS); - gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)acsMouse3D, - &Vect3f(x,y,acsMouseZ),&Vect3f(0,0,0)); + Vect3f v2(x,y,acsMouseZ); + Vect3f v3(0,0,0); + gb_IVisGeneric -> SetObjectPosition((cUnknownClass*)acsMouse3D,&v2,&v3); acsMouse3D -> SetOrientation(M); BaseObject_SurfaceReflection_WaveWarp(acsMouse3D->x(),acsMouse3D->y(),acsMouse3D->z()); @@ -1776,15 +1780,20 @@ void acsExtSetCamera(int zbuf_flag) acsCameraR.x = XGR_MAXX/2; acsCameraR.y = XGR_MAXY/2; - gb_IVisGeneric->SetCameraPosition(iCamera, - &Vect3f(acsCameraR.x,acsCameraR.y,acsCameraR.z), - &Vect3f(acsCameraA.x,acsCameraA.y,acsCameraA.z)); + Vect3f v1(acsCameraR.x,acsCameraR.y,acsCameraR.z); + Vect3f v2(acsCameraA.x,acsCameraA.y,acsCameraA.z); + gb_IVisGeneric->SetCameraPosition(iCamera,&v1,&v2); + Vect2f v3(0.5f,0.5f); + sRectangle4f r1(-0.499f,-0.499f,0.499f,0.499f); + Vect2f v4((float)acsCameraFocus/XGR_MAXX,(float)acsCameraFocus/XGR_MAXX); + Vect2f v5(10.0f,3000.0f); + Vect2f v6(0.0f,z); gb_IVisGeneric->SetCameraFrustum(iCamera, // ��������������� �������� ��������� - &Vect2f(0.5f,0.5f), // ����� ������ - &sRectangle4f(-0.499f,-0.499f,0.499f,0.499f), // ������� ������� ������ - &Vect2f((float)acsCameraFocus/XGR_MAXX,(float)acsCameraFocus/XGR_MAXX),// ����� ������ - &Vect2f(10.0f,3000.0f), // ��������� � ������� z-��������� ��������� - &Vect2f(0.0f,z)); // zNear � zFar ��� ����������� � zBuffer + &v3, // ����� ������ + &r1, // ������� ������� ������ + &v4,// ����� ������ + &v5, // ��������� � ������� z-��������� ��������� + &v6); // zNear � zFar ��� ����������� � zBuffer if(acsCameraPerspective) gb_IVisGeneric->SetCameraAttribute(iCamera,ATTRIBUTE_CAMERA_PERSPECTIVE); else gb_IVisGeneric->ClearCameraAttribute(iCamera,ATTRIBUTE_CAMERA_PERSPECTIVE); } @@ -1898,8 +1907,8 @@ void acsInitShop(int pl) acsShopPlayer = pl; acsMechos = new MechosForSale(hsPlayers[acsShopPlayer].configStr,Vect3f(x,y,80)); - gb_IVisGeneric -> SetObjectScale((cUnknownClass*)acsMechos -> getGeometry(), - &Vect3f(SHOP_MECH_SCALE * mchA_d3dResX)); + Vect3f v1(SHOP_MECH_SCALE * mchA_d3dResX); + gb_IVisGeneric -> SetObjectScale((cUnknownClass*)acsMechos -> getGeometry(),&v1); acsMechos -> rotate(1,0); acsMechos -> rotate(-1,0); diff --git a/MechoSoma/iScreen/iScript.cpp b/MechoSoma/iScreen/iScript.cpp index 531d8d32..5dc8be82 100644 --- a/MechoSoma/iScreen/iScript.cpp +++ b/MechoSoma/iScreen/iScript.cpp @@ -1,12 +1,12 @@ /* ---------------------------- INCLUDE SECTION ----------------------------- */ #include "StdAfx.h" -#include "hfont.h" +#include "HFONT.H" -#include "aci_evnt.h" -#include "aci_scr.h" +#include "ACI_EVNT.H" +#include "ACI_SCR.H" -#include "SCRIPTS\scr_defs.h" +#include "SCR_DEFS.H" #include "aci_parser.h" #include "mch_common.h" // For far target diff --git a/MechoSoma/iScreen/iText.cpp b/MechoSoma/iScreen/iText.cpp index 3230e8e5..aac830d1 100644 --- a/MechoSoma/iScreen/iText.cpp +++ b/MechoSoma/iScreen/iText.cpp @@ -2,7 +2,7 @@ #include "StdAfx.h" #include "iText.h" -#include "scr_defs.h" +#include "SCR_DEFS.H" #include "aci_parser.h" #include "mch_common.h" // For far target diff --git a/MechoSoma/iScreen/savegame.cpp b/MechoSoma/iScreen/savegame.cpp index b3feb68b..33c06979 100644 --- a/MechoSoma/iScreen/savegame.cpp +++ b/MechoSoma/iScreen/savegame.cpp @@ -7,10 +7,10 @@ #include "TrackDispatcher.h" #include "I-World.h" -#include "aci_ids.h" -#include "aci_evnt.h" -#include "aci_scr.h" -#include "keys.h" +#include "ACI_IDS.H" +#include "ACI_EVNT.H" +#include "ACI_SCR.H" +#include "KEYS.H" #include "iText.h" @@ -20,7 +20,20 @@ #include "demo_dispatcher.h" +#ifdef _WIN32 #include "win32f.h" +#else +#define DBGCHECK +char *_strtime(char *timestr) +{ + return nullptr; +} + +char *_strdate(char *timestr) +{ + return nullptr; +} +#endif #include "mch_common.h" // For far target diff --git a/MechoSoma/macOS/EnumArray.h b/MechoSoma/macOS/EnumArray.h new file mode 100644 index 00000000..46e4f015 --- /dev/null +++ b/MechoSoma/macOS/EnumArray.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +template +class EnumArray final +{ +public: + T& operator[](E e) + { + return _array[static_cast(e)]; + } + + const T& operator[](E e) const + { + return _array[static_cast(e)]; + } + +private: + std::array _array; +}; diff --git a/MechoSoma/macOS/GameViewController.h b/MechoSoma/macOS/GameViewController.h new file mode 100644 index 00000000..a067aee8 --- /dev/null +++ b/MechoSoma/macOS/GameViewController.h @@ -0,0 +1,4 @@ +#import + +@interface GameViewController: NSViewController +@end diff --git a/MechoSoma/macOS/GameViewController.mm b/MechoSoma/macOS/GameViewController.mm new file mode 100644 index 00000000..8a26f5b0 --- /dev/null +++ b/MechoSoma/macOS/GameViewController.mm @@ -0,0 +1,269 @@ +#import "GameViewController.h" + +#import +#import + +#include "KeyboardCodeConversion.h" +#include "Renderer.h" + +#include "KEYS.H" +#include "xgraph.h" +#include "xtool.h" + +@interface GameViewController() + +@property (nonatomic, retain) MTKView *metalView; +@property (nonatomic, retain) id library; +#ifdef METAL_FRAME_CAPTURE +@property (nonatomic, retain) MTLCaptureDescriptor *captureDescriptor; +@property (nonatomic) BOOL canCapture; +#endif + +@end + +@implementation GameViewController +{ + int _id; + int _previous_id; + XRuntimeObject *_current_rto; +} + +- (void)loadView +{ + self.metalView = [MTKView new]; + self.view = self.metalView; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.metalView.device = MTLCreateSystemDefaultDevice(); + self.metalView.delegate = self; + self.metalView.clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0); + self.metalView.depthStencilPixelFormat = MTLPixelFormatDepth32Float; + self.metalView.frame = NSMakeRect(0, 0, 800, 600); + self.metalView.preferredFramesPerSecond = 30; + + self.library = [self.metalView.device newDefaultLibrary]; + if (self.library == nil) + { + return; + } + + // create a tracking area to keep track of the mouse movements and events + NSTrackingAreaOptions options = (NSTrackingActiveAlways + | NSTrackingInVisibleRect + | NSTrackingMouseEnteredAndExited + | NSTrackingMouseMoved); + NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:self.view.bounds + options:options + owner:self.view + userInfo:nil]; + [self.view addTrackingArea:area]; + +#ifdef METAL_FRAME_CAPTURE + MTLCaptureManager *captureManager = MTLCaptureManager.sharedCaptureManager; + if ([captureManager supportsDestination:MTLCaptureDestinationGPUTraceDocument]) + { + NSLog(@"DEBUG: GPU trace document"); + self.captureDescriptor = [MTLCaptureDescriptor new]; + self.captureDescriptor.destination = MTLCaptureDestinationGPUTraceDocument; + self.captureDescriptor.captureObject = self.metalView.device; + + self.canCapture = NO; + } +#endif + graphics::Renderer::shared = std::make_unique( + self.metalView.device, + self.library + ); + + _previous_id = 0; + _id = xtInitApplication(); + _current_rto = xtGetRuntimeObject(_id); +} + +- (BOOL)acceptsFirstResponder +{ + return YES; +} + +- (void)keyDown:(NSEvent *)event +{ + const auto key = platform::KeyboardCodeFromNSEvent(event); + XKey.PressFnc(key, 1); + KeyBuf->put(VK_SPACE, KBD_CUR_KEY_PRESSED); + +#ifdef METAL_FRAME_CAPTURE + if (key == VK_LEFT) + { + self.canCapture = YES; + + NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:NSTemporaryDirectory()]; + const auto time = (long)([NSDate date].timeIntervalSince1970); + NSString *name = [NSString stringWithFormat:@"Trace_%ld.gputrace", time]; + self.captureDescriptor.outputURL = [outputURL URLByAppendingPathComponent:name]; + } +#endif + + [super keyDown:event]; +} + +- (void)keyUp:(NSEvent *)event +{ + const auto key = platform::KeyboardCodeFromNSEvent(event); + XKey.UnPressFnc(key, 1); + KeyBuf->put(key, KBD_CUR_KEY_UNPRESSED); + + [super keyUp:event]; +} + +- (void)mouseDown:(NSEvent *)event +{ + [self handleMouseEvent:event]; + [super mouseDown:event]; +} + +- (void)mouseUp:(NSEvent *)event +{ + [self handleMouseEvent:event]; + [super mouseUp:event]; +} + +- (void)mouseMoved:(NSEvent *)event +{ + [self handleMouseEvent:event]; + [super mouseMoved:event]; +} + +- (void)mouseEntered:(NSEvent *)event +{ + [NSCursor hide]; +} + +- (void)mouseExited:(NSEvent *)event +{ + [NSCursor unhide]; +} + +- (void)handleMouseEvent:(NSEvent *)event +{ + const auto x = static_cast(event.locationInWindow.x); + const auto y = static_cast(self.metalView.frame.size.height - event.locationInWindow.y); + + switch (event.type) + { + case NSEventTypeMouseMoved: + { + const int x1 = XGR_MouseObj.PosX; + const int y1 = XGR_MouseObj.PosY; + + XGR_MouseObj.InitPos(x, y); + + XGR_MouseObj.MovementX = x - x1; + XGR_MouseObj.MovementY = y - y1; + + XGR_MouseObj.Move(0, XGR_MouseObj.PosX, XGR_MouseObj.PosY); + if (XGR_MouseVisible()) + { + XGR_MouseRedraw(); + } + break; + } + + case NSEventTypeLeftMouseDown: + { + XGR_MouseInitPos(x, y); + XGR_MousePress(XGM_LEFT_BUTTON, 0, XGR_MouseObj.PosX, XGR_MouseObj.PosY); + break; + } + + case NSEventTypeRightMouseDown: + { + XGR_MouseInitPos(x, y); + XGR_MousePress(XGM_RIGHT_BUTTON, 0, XGR_MouseObj.PosX, XGR_MouseObj.PosY); + break; + } + + case NSEventTypeLeftMouseUp: + { + XGR_MouseInitPos(x, y); + XGR_MouseUnPress(XGM_LEFT_BUTTON, 0, XGR_MouseObj.PosX, XGR_MouseObj.PosY); + break; + } + + case NSEventTypeRightMouseUp: + { + XGR_MouseInitPos(x, y); + XGR_MouseUnPress(XGM_RIGHT_BUTTON, 0, XGR_MouseObj.PosX, XGR_MouseObj.PosY); + break; + } + + default: + break; + } +} + +- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size +{ +} + +- (void)drawInMTKView:(MTKView *)view +{ + [self startCapture]; + + graphics::Renderer::shared->begin(view); + + if (_id) + { + _current_rto->Init(_previous_id); + _previous_id = _id; + _id = 0; + } + else + { + _id = _current_rto->Quant(); + if (_id) + { + _current_rto->Finit(); + _current_rto = xtGetRuntimeObject(_id); + } + } + + graphics::Renderer::shared->end(); + + [self stopCapture]; +} + +- (void)startCapture +{ +#ifdef METAL_FRAME_CAPTURE + if (!self.canCapture) + { + return; + } + + NSError *error = nil; + BOOL success = [MTLCaptureManager.sharedCaptureManager startCaptureWithDescriptor:self.captureDescriptor error:&error]; + if (!success) + { + NSLog(@"ERROR: %@", error); + } +#endif +} + +- (void)stopCapture +{ +#ifdef METAL_FRAME_CAPTURE + if (!self.canCapture) + { + return; + } + self.canCapture = NO; + + [MTLCaptureManager.sharedCaptureManager stopCapture]; +#endif +} + +@end diff --git a/MechoSoma/macOS/KeyboardCodeConversion.h b/MechoSoma/macOS/KeyboardCodeConversion.h new file mode 100644 index 00000000..8195498d --- /dev/null +++ b/MechoSoma/macOS/KeyboardCodeConversion.h @@ -0,0 +1,10 @@ +#pragma once + +#import + +namespace platform +{ + +int KeyboardCodeFromNSEvent(NSEvent* event); + +} diff --git a/MechoSoma/macOS/KeyboardCodeConversion.mm b/MechoSoma/macOS/KeyboardCodeConversion.mm new file mode 100644 index 00000000..b2b45d07 --- /dev/null +++ b/MechoSoma/macOS/KeyboardCodeConversion.mm @@ -0,0 +1,284 @@ +#include "KeyboardCodeConversion.h" + +#include "xtool.h" + +// Translates from character code to keyboard code. +int KeyboardCodeFromCharCode(unichar charCode) +{ + switch (charCode) + { + case 8: case 0x7F: return VK_BACK; + case 9: return VK_TAB; + case 0xD: case 3: return VK_RETURN; + case 0x1B: return VK_ESCAPE; + case ' ': return VK_SPACE; + case NSHomeFunctionKey: return VK_HOME; + case NSEndFunctionKey: return VK_END; + case NSPageUpFunctionKey: return VK_PRIOR; + case NSPageDownFunctionKey: return VK_NEXT; + case NSUpArrowFunctionKey: return VK_UP; + case NSDownArrowFunctionKey: return VK_DOWN; + case NSLeftArrowFunctionKey: return VK_LEFT; + case NSRightArrowFunctionKey: return VK_RIGHT; + case NSDeleteFunctionKey: return VK_DELETE; + + case '0': case ')': return VK_0; + case '1': case '!': return VK_1; + case '2': case '@': return VK_2; + case '3': case '#': return VK_3; + case '4': case '$': return VK_4; + case '5': case '%': return VK_5; + case '6': case '^': return VK_6; + case '7': case '&': return VK_7; + case '8': case '*': return VK_8; + case '9': case '(': return VK_9; + + case 'a': case 'A': return VK_A; + case 'b': case 'B': return VK_B; + case 'c': case 'C': return VK_C; + case 'd': case 'D': return VK_D; + case 'e': case 'E': return VK_E; + case 'f': case 'F': return VK_F; + case 'g': case 'G': return VK_G; + case 'h': case 'H': return VK_H; + case 'i': case 'I': return VK_I; + case 'j': case 'J': return VK_J; + case 'k': case 'K': return VK_K; + case 'l': case 'L': return VK_L; + case 'm': case 'M': return VK_M; + case 'n': case 'N': return VK_N; + case 'o': case 'O': return VK_O; + case 'p': case 'P': return VK_P; + case 'q': case 'Q': return VK_Q; + case 'r': case 'R': return VK_R; + case 's': case 'S': return VK_S; + case 't': case 'T': return VK_T; + case 'u': case 'U': return VK_U; + case 'v': case 'V': return VK_V; + case 'w': case 'W': return VK_W; + case 'x': case 'X': return VK_X; + case 'y': case 'Y': return VK_Y; + case 'z': case 'Z': return VK_Z; + + case NSPauseFunctionKey: return VK_PAUSE; + case NSSelectFunctionKey: return VK_SELECT; + case NSPrintFunctionKey: return VK_PRINT; + case NSExecuteFunctionKey: return VK_EXECUTE; + case NSPrintScreenFunctionKey: return VK_SNAPSHOT; + case NSInsertFunctionKey: return VK_INSERT; + case NSHelpFunctionKey: return VK_INSERT; + + case NSF1FunctionKey: return VK_F1; + case NSF2FunctionKey: return VK_F2; + case NSF3FunctionKey: return VK_F3; + case NSF4FunctionKey: return VK_F4; + case NSF5FunctionKey: return VK_F5; + case NSF6FunctionKey: return VK_F6; + case NSF7FunctionKey: return VK_F7; + case NSF8FunctionKey: return VK_F8; + case NSF9FunctionKey: return VK_F9; + case NSF10FunctionKey: return VK_F10; + case NSF11FunctionKey: return VK_F11; + case NSF12FunctionKey: return VK_F12; + case NSF13FunctionKey: return VK_F13; + case NSF14FunctionKey: return VK_F14; + case NSF15FunctionKey: return VK_F15; + case NSF16FunctionKey: return VK_F16; + case NSF17FunctionKey: return VK_F17; + case NSF18FunctionKey: return VK_F18; + case NSF19FunctionKey: return VK_F19; + case NSF20FunctionKey: return VK_F20; + + case NSF21FunctionKey: return VK_F21; + case NSF22FunctionKey: return VK_F22; + case NSF23FunctionKey: return VK_F23; + case NSF24FunctionKey: return VK_F24; + case NSScrollLockFunctionKey: return VK_SCROLL; + + // U.S. Specific mappings. Mileage may vary. + case ';': case ':': return VK_OEM_1; + case '=': case '+': return VK_OEM_PLUS; + case ',': case '<': return VK_OEM_COMMA; + case '-': case '_': return VK_OEM_MINUS; + case '.': case '>': return VK_OEM_PERIOD; + case '/': case '?': return VK_OEM_2; + case '`': case '~': return VK_OEM_3; + case '[': case '{': return VK_OEM_4; + case '\\': case '|': return VK_OEM_5; + case ']': case '}': return VK_OEM_6; + case '\'': case '"': return VK_OEM_7; + } + + return VK_UNKNOWN; +} + +int KeyboardCodeFromKeyCode(unsigned short keyCode) +{ + static const int kKeyboardCodes[] = { + /* 0 */ VK_A, + /* 1 */ VK_S, + /* 2 */ VK_D, + /* 3 */ VK_F, + /* 4 */ VK_H, + /* 5 */ VK_G, + /* 6 */ VK_Z, + /* 7 */ VK_X, + /* 8 */ VK_C, + /* 9 */ VK_V, + /* 0x0A */ VK_OEM_3, // Section key. + /* 0x0B */ VK_B, + /* 0x0C */ VK_Q, + /* 0x0D */ VK_W, + /* 0x0E */ VK_E, + /* 0x0F */ VK_R, + /* 0x10 */ VK_Y, + /* 0x11 */ VK_T, + /* 0x12 */ VK_1, + /* 0x13 */ VK_2, + /* 0x14 */ VK_3, + /* 0x15 */ VK_4, + /* 0x16 */ VK_6, + /* 0x17 */ VK_5, + /* 0x18 */ VK_OEM_PLUS, // =+ + /* 0x19 */ VK_9, + /* 0x1A */ VK_7, + /* 0x1B */ VK_OEM_MINUS, // -_ + /* 0x1C */ VK_8, + /* 0x1D */ VK_0, + /* 0x1E */ VK_OEM_6, // ]} + /* 0x1F */ VK_O, + /* 0x20 */ VK_U, + /* 0x21 */ VK_OEM_4, // {[ + /* 0x22 */ VK_I, + /* 0x23 */ VK_P, + /* 0x24 */ VK_RETURN, // Return + /* 0x25 */ VK_L, + /* 0x26 */ VK_J, + /* 0x27 */ VK_OEM_7, // '" + /* 0x28 */ VK_K, + /* 0x29 */ VK_OEM_1, // ;: + /* 0x2A */ VK_OEM_5, // \| + /* 0x2B */ VK_OEM_COMMA, // ,< + /* 0x2C */ VK_OEM_2, // /? + /* 0x2D */ VK_N, + /* 0x2E */ VK_M, + /* 0x2F */ VK_OEM_PERIOD, // .> + /* 0x30 */ VK_TAB, + /* 0x31 */ VK_SPACE, + /* 0x32 */ VK_OEM_3, // `~ + /* 0x33 */ VK_BACK, // Backspace + /* 0x34 */ VK_UNKNOWN, // n/a + /* 0x35 */ VK_ESCAPE, + /* 0x36 */ VK_APPS, // Right Command + /* 0x37 */ VK_LWIN, // Left Command + /* 0x38 */ VK_SHIFT, // Left Shift + /* 0x39 */ VK_CAPITAL, // Caps Lock + /* 0x3A */ VK_MENU, // Left Option + /* 0x3B */ VK_CONTROL, // Left Ctrl + /* 0x3C */ VK_SHIFT, // Right Shift + /* 0x3D */ VK_MENU, // Right Option + /* 0x3E */ VK_CONTROL, // Right Ctrl + /* 0x3F */ VK_UNKNOWN, // fn + /* 0x40 */ VK_F17, + /* 0x41 */ VK_DECIMAL, // Num Pad . + /* 0x42 */ VK_UNKNOWN, // n/a + /* 0x43 */ VK_MULTIPLY, // Num Pad * + /* 0x44 */ VK_UNKNOWN, // n/a + /* 0x45 */ VK_ADD, // Num Pad + + /* 0x46 */ VK_UNKNOWN, // n/a + /* 0x47 */ VK_CLEAR, // Num Pad Clear + /* 0x48 */ VK_VOLUME_UP, + /* 0x49 */ VK_VOLUME_DOWN, + /* 0x4A */ VK_VOLUME_MUTE, + /* 0x4B */ VK_DIVIDE, // Num Pad / + /* 0x4C */ VK_RETURN, // Num Pad Enter + /* 0x4D */ VK_UNKNOWN, // n/a + /* 0x4E */ VK_SUBTRACT, // Num Pad - + /* 0x4F */ VK_F18, + /* 0x50 */ VK_F19, + /* 0x51 */ VK_OEM_PLUS, // Num Pad =. + /* 0x52 */ VK_NUMPAD0, + /* 0x53 */ VK_NUMPAD1, + /* 0x54 */ VK_NUMPAD2, + /* 0x55 */ VK_NUMPAD3, + /* 0x56 */ VK_NUMPAD4, + /* 0x57 */ VK_NUMPAD5, + /* 0x58 */ VK_NUMPAD6, + /* 0x59 */ VK_NUMPAD7, + /* 0x5A */ VK_F20, + /* 0x5B */ VK_NUMPAD8, + /* 0x5C */ VK_NUMPAD9, + /* 0x5D */ VK_UNKNOWN, // Yen (JIS Keyboard Only) + /* 0x5E */ VK_UNKNOWN, // Underscore (JIS Keyboard Only) + /* 0x5F */ VK_UNKNOWN, // KeypadComma (JIS Keyboard Only) + /* 0x60 */ VK_F5, + /* 0x61 */ VK_F6, + /* 0x62 */ VK_F7, + /* 0x63 */ VK_F3, + /* 0x64 */ VK_F8, + /* 0x65 */ VK_F9, + /* 0x66 */ VK_UNKNOWN, // Eisu (JIS Keyboard Only) + /* 0x67 */ VK_F11, + /* 0x68 */ VK_UNKNOWN, // Kana (JIS Keyboard Only) + /* 0x69 */ VK_F13, + /* 0x6A */ VK_F16, + /* 0x6B */ VK_F14, + /* 0x6C */ VK_UNKNOWN, // n/a + /* 0x6D */ VK_F10, + /* 0x6E */ VK_UNKNOWN, // n/a (Windows95 key?) + /* 0x6F */ VK_F12, + /* 0x70 */ VK_UNKNOWN, // n/a + /* 0x71 */ VK_F15, + /* 0x72 */ VK_INSERT, // Help + /* 0x73 */ VK_HOME, // Home + /* 0x74 */ VK_PRIOR, // Page Up + /* 0x75 */ VK_DELETE, // Forward Delete + /* 0x76 */ VK_F4, + /* 0x77 */ VK_END, // End + /* 0x78 */ VK_F2, + /* 0x79 */ VK_NEXT, // Page Down + /* 0x7A */ VK_F1, + /* 0x7B */ VK_LEFT, // Left Arrow + /* 0x7C */ VK_RIGHT, // Right Arrow + /* 0x7D */ VK_DOWN, // Down Arrow + /* 0x7E */ VK_UP, // Up Arrow + /* 0x7F */ VK_UNKNOWN // n/a + }; + + if (keyCode >= 0x80) + { + return VK_UNKNOWN; + } + + return kKeyboardCodes[keyCode]; +} + +int platform::KeyboardCodeFromNSEvent(NSEvent* event) +{ + int code = VK_UNKNOWN; + + if (event.type == NSKeyDown || event.type == NSKeyUp) + { + NSString* characters = event.characters; + if (characters.length > 0) + { + code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); + } + if (code) + { + return code; + } + + characters = [event charactersIgnoringModifiers]; + if (characters.length > 0) + { + code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); + } + if (code) + { + return code; + } + } + + return KeyboardCodeFromKeyCode(event.keyCode); +} diff --git a/MechoSoma/macOS/Library.metal b/MechoSoma/macOS/Library.metal new file mode 100644 index 00000000..c11087c1 --- /dev/null +++ b/MechoSoma/macOS/Library.metal @@ -0,0 +1,78 @@ +#include +#include + +#include "ShaderCommon.h" + +using namespace metal; +using namespace simd; + +struct InputVertex +{ + float3 position [[attribute(0)]]; + float4 color [[attribute(1)]]; + float2 uv [[attribute(2)]]; +}; + +struct ProjectedVertex +{ + float4 position [[position]]; + float4 color; + float2 uv; +}; + +vertex ProjectedVertex vertex_shader +( + InputVertex input_vertex [[stage_in]], + constant BasicUniforms& uniforms [[buffer(3)]] +) +{ + ProjectedVertex output; + output.position = uniforms.projection_matrix * float4(input_vertex.position, 1.0f); + output.color = input_vertex.color; + output.uv = input_vertex.uv; + return output; +} + +fragment half4 fragment_shader +( + ProjectedVertex input [[stage_in]], + constant FragmentShaderParameters& parameters [[buffer(0)]], + texture2d texture_1 [[texture(0)]], + texture2d texture_2 [[texture(1)]] +) +{ + constexpr sampler s_repeat(address::repeat, filter::linear); + constexpr sampler s_clamp(address::clamp_to_edge, filter::linear); + + float4 result_color; + switch (parameters.color_operation_1) + { + case TextureColorOperation::Disable: + { + result_color = input.color; + break; + } + + case TextureColorOperation::Texture: + { + result_color = texture_1.sample(s_repeat, input.uv); + break; + } + + case TextureColorOperation::Modulate: + { + result_color = texture_1.sample(s_repeat, input.uv) * input.color; + break; + } + + default: + result_color = 0.0f; + } + + if (parameters.color_operation_2 == TextureColorOperation::Modulate) + { + result_color *= texture_2.sample(s_clamp, input.uv); + } + + return half4(result_color); +} diff --git a/MechoSoma/macOS/Matrix.cpp b/MechoSoma/macOS/Matrix.cpp new file mode 100644 index 00000000..ec86b6c7 --- /dev/null +++ b/MechoSoma/macOS/Matrix.cpp @@ -0,0 +1,95 @@ +#include "Matrix.h" + +using namespace graphics; + +simd_float4x4 matrix_make_rows(float m00, float m10, float m20, float m30, + float m01, float m11, float m21, float m31, + float m02, float m12, float m22, float m32, + float m03, float m13, float m23, float m33) +{ + return (simd_float4x4){ + { + { m00, m01, m02, m03 }, // each line here provides column data + { m10, m11, m12, m13 }, + { m20, m21, m22, m23 }, + { m30, m31, m32, m33 } + } + }; +} + +simd_float4x4 matrix::make_perspective_projection(float fov_y, float aspect, float near, float far) +{ + float y_scale = 1.0f / tanf(fov_y * 0.5f); + float x_scale = y_scale / aspect; + float z_scale = far / (far - near); + + return matrix_make_rows( + x_scale, 0, 0, 0, + 0, y_scale, 0, 0, + 0, 0, z_scale, -near * z_scale, + 0, 0, 1.0f, 0 + ); +} + +simd_float4x4 matrix::make_ortho_projection(float left, float right, float bottom, float top, float near, float far) +{ + return matrix_make_rows( + 2.0f / (right - left), 0, 0, (left + right) / (left - right), + 0, 2.0f / (top - bottom), 0, (top + bottom) / (bottom - top), + 0, 0, 1.0f / (far - near), near / (near - far), + 0, 0, 0, 1.0f + ); +} + +simd_float4x4 matrix::make_look_at(simd_float3 eye, simd_float3 target, simd_float3 up) +{ + simd_float3 z = simd_normalize(target - eye); + simd_float3 x = simd_normalize(simd_cross(up, z)); + simd_float3 y = simd_cross(z, x); + simd_float3 t{-simd_dot(x, eye), -simd_dot(y, eye), -simd_dot(z, eye)}; + + return matrix_make_rows( + x.x, x.y, x.z, t.x, + y.x, y.y, y.z, t.y, + z.x, z.y, z.z, t.z, + 0, 0, 0, 1.0f + ); +} + +simd_float4x4 matrix::make_rotation(simd_float3 axis, float radians) +{ + axis = vector_normalize(axis); + float ct = cosf(radians); + float st = sinf(radians); + float ci = 1.0f - ct; + float x = axis.x; + float y = axis.y; + float z = axis.z; + + return matrix_make_rows( + ct + x * x * ci, x * y * ci - z * st, x * z * ci + y * st, 0, + y * x * ci + z * st, ct + y * y * ci, y * z * ci - x * st, 0, + z * x * ci - y * st, z * y * ci + x * st, ct + z * z * ci, 0, + 0, 0, 0, 1.0f + ); +} + +simd_float4x4 matrix::make_scale(simd_float3 s) +{ + return matrix_make_rows( + s.x, 0, 0, 0, + 0, s.y, 0, 0, + 0, 0, s.z, 0, + 0, 0, 0, 1.0f + ); +} + +simd_float4x4 matrix::make_transform(simd_float3 t) +{ + return matrix_make_rows( + 1.0f, 0, 0, t.x, + 0, 1.0f, 0, t.y, + 0, 0, 1.0f, t.z, + 0, 0, 0, 1.0f + ); +} diff --git a/MechoSoma/macOS/Matrix.h b/MechoSoma/macOS/Matrix.h new file mode 100644 index 00000000..94e478a8 --- /dev/null +++ b/MechoSoma/macOS/Matrix.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +namespace graphics::matrix +{ + +// left hand +simd_float4x4 make_perspective_projection(float fov_y, float aspect, float near, float far); + +// left hand +simd_float4x4 make_ortho_projection(float left, float right, float bottom, float top, float near, float far); + +// left hand +simd_float4x4 make_look_at(simd_float3 eye, simd_float3 target, simd_float3 up); + +simd_float4x4 make_rotation(simd_float3 axis, float angle); +simd_float4x4 make_scale(simd_float3 s); +simd_float4x4 make_transform(simd_float3 t); + +} diff --git a/MechoSoma/macOS/Md3d.cpp b/MechoSoma/macOS/Md3d.cpp new file mode 100644 index 00000000..97fe849a --- /dev/null +++ b/MechoSoma/macOS/Md3d.cpp @@ -0,0 +1,355 @@ +#include "Md3d.h" + +#include + +#include "RendererInterface.h" +#include "TextureManagerInterface.h" + +BOOL g_bInitialized = FALSE; +BOOL g_bInScene = FALSE; // TRUE when in BeginScene/EndScene bracket + +BOOL g_bActive = FALSE; + +extern MD3DERROR __d3dInitSpriteManager(); + +MD3DERROR d3dEnumVideoMode(int* pnumvideomode,MD3DMODE** ppArray) +{ + return MD3D_OK; +} + +MD3DERROR d3dGetAvailableVidMem(DWORD* allvideomem) +{ + return MD3D_OK; +} + +MD3DERROR d3dInit(DWORD dwWidth, DWORD dwHeight, DWORD dwBpp, DWORD dwInitFlags, HINSTANCE hInst, HICON hIcon, TCHAR *szTitle) +{ + assert(!g_bInitialized); + + MD3DERROR hr = MD3D_OK; + + // Initialize sprite manager + if (FAILED(hr = __d3dInitSpriteManager())) + { + return hr; + } + + g_bInitialized = TRUE; + g_bActive = TRUE; + + return hr; +} + +MD3DERROR d3dReInit(DWORD dwWidth, DWORD dwHeight, DWORD dwBpp, DWORD dwInitFlags, HINSTANCE hInst, HICON hIcon, TCHAR *szTitle) +{ + return MD3D_OK; +} + +MD3DERROR d3dClose() +{ + assert(g_bInitialized); + g_bInitialized = FALSE; + return MD3D_OK; +} + +MD3DERROR d3dQueryCaps(MD3DCAPS Caps, DWORD *dwData) +{ + return MD3D_OK; +} + +MD3DERROR d3dGetWindowHandle(HWND *hWnd) +{ + return MD3D_OK; +} + +MD3DERROR d3dClear(DWORD dwColor) +{ + return graphics::get_renderer().d3dClear(dwColor); +} + +MD3DERROR d3dFlip(bool WaitVerticalBlank) +{ + return MD3D_OK; +} + +MD3DERROR d3dFlipToGdiSurface() +{ + return MD3D_OK; +} + +MD3DERROR d3dCreateBackBuffer() +{ + return MD3D_OK; +} + +MD3DERROR d3dReleaseBackBuffer() +{ + return MD3D_OK; +} + +MD3DERROR d3dGetBackBufferFormat(DWORD *dwFormat) +{ + return MD3D_OK; +} + +MD3DERROR d3dLockBackBuffer(VOID **lplpSurface, DWORD *lpdwPitch) +{ + return MD3D_OK; +} + +MD3DERROR d3dUnlockBackBuffer() +{ + return MD3D_OK; +} + +MD3DERROR d3dFlushBackBuffer(RECT *lprcRect) +{ + return MD3D_OK; +} + +MD3DERROR d3dSetBackBufferColorKey(DWORD dwColor) +{ + return MD3D_OK; +} + +MD3DERROR d3dEnableBackBufferColorKey(BOOL bEnable) +{ + return MD3D_OK; +} + +MD3DERROR d3dScreenShot(VOID *lpBuffer, DWORD dwSize) +{ + return MD3D_OK; +} + +MD3DERROR d3dEndScene() +{ + if (g_bInScene == FALSE) + { + return MD3D_OK; + } + + g_bInScene = FALSE; + + return graphics::get_renderer().d3dEndScene(); +} + +MD3DERROR d3dBeginScene() +{ + if (g_bInScene == TRUE) + { + return MD3D_OK; + } + + g_bInScene = TRUE; + + return graphics::get_renderer().d3dBeginScene(); +} + +MD3DERROR d3dTestCooperativeLevel() +{ + return MD3D_OK; +} + +MD3DERROR d3dSetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState) +{ + return graphics::get_renderer().d3dSetRenderState(dwRenderStateType, dwRenderState); +} + +MD3DERROR d3dGetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD *lpdwRenderState) +{ + return graphics::get_renderer().d3dGetRenderState(dwRenderStateType, lpdwRenderState); +} + +MD3DERROR d3dSetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue) +{ + return graphics::get_renderer().d3dSetTextureStageState(dwStage, dwState, dwValue); +} + +MD3DERROR d3dTriangles(DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwVertexCount) +{ + return MD3D_OK; +} + +MD3DERROR d3dTriangleStrip(DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwVertexCount) +{ + return MD3D_OK; +} + +MD3DERROR d3dTriangleFan(DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwVertexCount) +{ + return graphics::get_renderer().d3dTriangleFan(dwVertexTypeDesc, lpvVertices, dwVertexCount); +} + +MD3DERROR d3dPoints(DWORD, LPVOID, DWORD) +{ + return MD3D_OK; +} + +MD3DERROR d3dTrianglesIndexed( + DWORD dwVertexTypeDesc, + LPVOID lpvVertices, + DWORD dwVertexCount, + LPWORD lpwIndices, + DWORD dwIndexCount +) +{ + return graphics::get_renderer().d3dTrianglesIndexed( + dwVertexTypeDesc, + lpvVertices, + dwVertexCount, + lpwIndices, + dwIndexCount + ); +} + +MD3DERROR d3dGetTextureFormatData(DWORD dwTexFormatID, M3DTEXTUREFORMAT* pData) +{ + auto& texture_manager = graphics::get_renderer().get_texture_manager(); + return texture_manager.d3dGetTextureFormatData(dwTexFormatID, pData); +} + +MD3DERROR d3dCreateTexture(DWORD dwWidth, DWORD dwHeight, DWORD dwFormat, DWORD* lpdwHandle) +{ + auto& texture_manager = graphics::get_renderer().get_texture_manager(); + return texture_manager.d3dCreateTexture(dwWidth, dwHeight, dwFormat, lpdwHandle); +} + +MD3DERROR d3dDeleteTexture(DWORD dwHandle) +{ + auto& texture_manager = graphics::get_renderer().get_texture_manager(); + return texture_manager.d3dDeleteTexture(dwHandle); +} + +MD3DERROR d3dLockTexture(DWORD dwHandle, VOID** lplpTexture, DWORD* lpPitch) +{ + auto& texture_manager = graphics::get_renderer().get_texture_manager(); + return texture_manager.d3dLockTexture(dwHandle, lplpTexture, lpPitch); +} + +MD3DERROR d3dLockTexture( + DWORD dwHandle, + DWORD dwLeft, + DWORD dwTop, + DWORD dwRight, + DWORD dwBottom, + VOID** lplpTexture, + DWORD* lpPitch +) +{ + auto& texture_manager = graphics::get_renderer().get_texture_manager(); + return texture_manager.d3dLockTexture( + dwHandle, + dwLeft, + dwTop, + dwRight, + dwBottom, + lplpTexture, + lpPitch + ); +} + +MD3DERROR d3dUnlockTexture(DWORD dwHandle) +{ + auto& texture_manager = graphics::get_renderer().get_texture_manager(); + return texture_manager.d3dUnlockTexture(dwHandle); +} + +MD3DERROR d3dSetTexture(DWORD dwHandle, DWORD dwStage) +{ + return graphics::get_renderer().d3dSetTexture(dwHandle, dwStage); +} + +MD3DERROR d3dSetTextureBlendMode(MD3DTEXTUREBLEND tbRGBBlend, MD3DTEXTUREBLEND tbAlphaBlend) +{ + return graphics::get_renderer().d3dSetTextureBlendMode(tbRGBBlend, tbAlphaBlend); +} + +MD3DERROR d3dSetAdjustedGamma(float fRGamma, float fGGamma, float fBGamma) +{ + return MD3D_OK; +} + +MD3DERROR d3dGetAdjustedGamma(float *pfRGamma, float *pfGGamma, float *pfBGamma) +{ + return MD3D_OK; +} + +MD3DERROR d3dSetGammaFxHighlight(float fRHilight, float fGHilight, float fBHilight) +{ + return MD3D_OK; +} + +MD3DERROR d3dGetGammaFxHighlight(float *pfRHilight, float *pfGHilight, float *pfBHilight) +{ + return MD3D_OK; +} + +MD3DERROR d3dSetGammaFxShadow(float fRShadow, float fGShadow, float fBShadow) +{ + return MD3D_OK; +} + +MD3DERROR d3dGetGammaFxShadow(float *pfRShadow, float *pfGShadow, float *pfBShadow) +{ + return MD3D_OK; +} + +MD3DERROR d3dSetProjectionMatrix(FLOAT fFOV, FLOAT fNearPlane, FLOAT fFarPlane) +{ + return MD3D_OK; +} + +MD3DERROR d3dSetProjectionMatrixToIdentity() +{ + return MD3D_OK; +} + +MD3DERROR d3dSetFogParameters(DWORD dwMode, DWORD dwColor, FLOAT fStart, FLOAT fEnd, FLOAT fDensity) +{ + return MD3D_OK; +} + +MD3DERROR d3dEnableFog(BOOL bEnable) +{ + return MD3D_OK; +} + +MD3DERROR d3dSetFocusLossBehavior(BOOL bSleep) +{ + return MD3D_OK; +} + +BOOL d3dIsActive() +{ + return g_bActive; +} + +MD3DERROR d3dSetClipRect(RECT* lprcClipRect) +{ + return MD3D_OK; +} + +MD3DERROR d3dTrianglesIndexed2( + DWORD dwVertexTypeDesc, + LPVOID lpvVertices, + DWORD dwVertexCount, + LPWORD lpwIndices, + DWORD dwIndexCount, + DWORD dwHandleTex0, + DWORD dwHandleTex1 +) +{ + assert(g_bInitialized); + assert(g_bInScene); + + return graphics::get_renderer().d3dTrianglesIndexed2( + dwVertexTypeDesc, + lpvVertices, + dwVertexCount, + lpwIndices, + dwIndexCount, + dwHandleTex0, + dwHandleTex1 + ); +} diff --git a/MechoSoma/macOS/Ref.h b/MechoSoma/macOS/Ref.h new file mode 100644 index 00000000..e6c98499 --- /dev/null +++ b/MechoSoma/macOS/Ref.h @@ -0,0 +1,53 @@ +#pragma once + +#import + +namespace objc +{ + template + class Ref + { + public: + Ref() = default; + + explicit Ref(T object) : _object(object) {} + + ~Ref() + { + [_object release]; + } + + Ref(const Ref& value) + { + _object = value._object; + [_object retain]; + } + + T get() const + { + return _object; + } + + Ref& operator=(const Ref& value) + { + _object = value._object; + [_object retain]; + return *this; + } + + Ref& operator=(T object) + { + [_object release]; + _object = object; + return *this; + } + + bool operator!() + { + return _object == nil; + } + + private: + T _object = nil; + }; +} diff --git a/MechoSoma/macOS/RenderState.h b/MechoSoma/macOS/RenderState.h new file mode 100644 index 00000000..61572944 --- /dev/null +++ b/MechoSoma/macOS/RenderState.h @@ -0,0 +1,105 @@ +#pragma once + +#include +#include +#include + +#include "Md3d.h" +#include "ShaderCommon.h" + +namespace graphics::d3d +{ + class RenderState final + { + public: + void set_option(D3DRENDERSTATETYPE type, DWORD value) + { + _options[type] = value; + } + + [[nodiscard]] DWORD get_option(D3DRENDERSTATETYPE type) const + { + return _options.at(type); + } + + void set_texture(DWORD handle, DWORD stage) + { + _texture_stages[stage].texture_handle = handle; + } + + [[nodiscard]] std::optional get_texture(DWORD stage) const + { + return _texture_stages[stage].texture_handle; + } + + void set_texture_stage_state(DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value) + { + _texture_stages[stage].states[state] = value; + } + + [[nodiscard]] DWORD get_texture_stage_state(DWORD stage, D3DTEXTURESTAGESTATETYPE state) const + { + return _texture_stages[stage].states.at(state); + } + + [[nodiscard]] FragmentShaderParameters get_fragment_shader_parameters() const + { + FragmentShaderParameters result; + switch (get_texture_stage_state(0, D3DTSS_COLOROP)) + { + case D3DTOP_DISABLE: + result.color_operation_1 = TextureColorOperation::Disable; + break; + + case D3DTOP_SELECTARG1: + result.color_operation_1 = TextureColorOperation::Texture; + break; + + case D3DTOP_MODULATE: + result.color_operation_1 = TextureColorOperation::Modulate; + break; + + default: + throw std::runtime_error("unsupported color operation"); + } + + switch (get_texture_stage_state(1, D3DTSS_COLOROP)) + { + case D3DTOP_DISABLE: + result.color_operation_2 = TextureColorOperation::Disable; + break; + + case D3DTOP_MODULATE: + result.color_operation_2 = TextureColorOperation::Modulate; + break; + + default: + throw std::runtime_error("unsupported color operation"); + } + + return result; + } + + bool operator==(const RenderState& other) const + { + return _options == other._options && _texture_stages == other._texture_stages; + } + + private: + std::unordered_map _options; + + struct TextureStage + { + std::optional texture_handle; + std::unordered_map states; + + TextureStage() : texture_handle(std::nullopt) {} + + bool operator==(const TextureStage& other) const + { + return texture_handle == other.texture_handle && states == other.states; + } + }; + std::array _texture_stages; + }; +} diff --git a/MechoSoma/macOS/Renderer.h b/MechoSoma/macOS/Renderer.h new file mode 100644 index 00000000..81d37f86 --- /dev/null +++ b/MechoSoma/macOS/Renderer.h @@ -0,0 +1,132 @@ +#pragma once + +#import + +#include +#include +#include + +#include "EnumArray.h" +#include "Ref.h" +#include "RendererInterface.h" +#include "RenderState.h" +#include "ShaderCommon.h" +#include "TextureManager.h" + +namespace graphics +{ + +class Renderer final : public RendererInterface +{ +public: + static std::unique_ptr shared; + + Renderer(id device, id library); + ~Renderer() override = default; + + Renderer(const Renderer&) = delete; + Renderer(Renderer&&) = delete; + Renderer& operator=(const Renderer&) = delete; + Renderer& operator=(Renderer&&) = delete; + + void begin(MTKView* view); + void end(); + + TextureManagerInterface& get_texture_manager() override; + + MD3DERROR d3dClear(DWORD dwColor) override; + MD3DERROR d3dBeginScene() override; + MD3DERROR d3dEndScene() override; + MD3DERROR d3dSetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState) override; + MD3DERROR d3dGetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD *lpdwRenderState) override; + MD3DERROR d3dSetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue) override; + MD3DERROR d3dTriangleFan(DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwVertexCount) override; + MD3DERROR d3dTrianglesIndexed( + DWORD dwVertexTypeDesc, + LPVOID lpvVertices, + DWORD dwVertexCount, + LPWORD lpwIndices, + DWORD dwIndexCount + ) override; + + MD3DERROR d3dSetTexture(DWORD dwHandle, DWORD dwStage) override; + MD3DERROR d3dSetTextureBlendMode(MD3DTEXTUREBLEND tbRGBBlend, MD3DTEXTUREBLEND tbAlphaBlend) override; + + MD3DERROR d3dTrianglesIndexed2( + DWORD dwVertexTypeDesc, + LPVOID lpvVertices, + DWORD dwVertexCount, + LPWORD lpwIndices, + DWORD dwIndexCount, + DWORD dwHandleTex0, + DWORD dwHandleTex1 + ) override; + +private: + void setup_depth_states(); + void setup_pipeline_states(); + void prepare_render_state(size_t index_count); + void add_vertex(DWORD vertex_type, LPVOID vertices, DWORD index); + +private: + const size_t _vertex_count = 35000; + + id _device; + id _library; + std::unique_ptr _texture_manager; + objc::Ref> _command_queue; + BasicUniforms _uniforms; + MTLClearColor _clear_color; + + objc::Ref> _position_buffer; + objc::Ref> _color_buffer; + objc::Ref> _uv_buffer; + objc::Ref> _index_buffer; + + MTKView* _view = nil; + id _command_buffer = nil; + + d3d::RenderState _render_state; + + enum class DepthStateType + { + Disabled, + Enabled + }; + using DepthStatePtr = objc::Ref>; + EnumArray _depth_states; + + enum class PipelineStateType + { + Default, + Blending + }; + using PipelineStatePtr = objc::Ref>; + EnumArray _pipeline_states; + + struct BufferView + { + size_t length; + size_t offset; + + [[nodiscard]] size_t end() const + { + return length + offset; + } + + [[nodiscard]] BufferView next() const + { + return BufferView{0, end()}; + } + }; + + struct DrawCommand + { + d3d::RenderState render_state; + BufferView vertex_buffer_view; + BufferView index_buffer_view; + }; + std::vector _commands; +}; + +} diff --git a/MechoSoma/macOS/Renderer.mm b/MechoSoma/macOS/Renderer.mm new file mode 100644 index 00000000..7b7502cb --- /dev/null +++ b/MechoSoma/macOS/Renderer.mm @@ -0,0 +1,509 @@ +#include "Renderer.h" + +#include "Matrix.h" +#include "VertexType.h" + +using namespace graphics; + +std::unique_ptr Renderer::shared; + +RendererInterface& graphics::get_renderer() +{ + return *Renderer::shared; +} + +Renderer::Renderer(id device, id library) : + _device(device), + _library(library), + _texture_manager(std::make_unique(device)) +{ + _command_queue = [device newCommandQueue]; + + setup_depth_states(); + setup_pipeline_states(); + + { + const auto length = _vertex_count * 3 * sizeof(float); + _position_buffer = [device newBufferWithLength:length options:MTLResourceStorageModeShared]; + } + + { + const auto length = _vertex_count * 4 * sizeof(float); + _color_buffer = [device newBufferWithLength:length options:MTLResourceStorageModeShared]; + } + + { + const auto length = _vertex_count * 2 * sizeof(float); + _uv_buffer = [device newBufferWithLength:length options:MTLResourceStorageModeShared]; + } + + { + const auto length = _vertex_count * 3 * sizeof(uint32_t); + _index_buffer = [device newBufferWithLength:length options:MTLResourceStorageModeShared]; + } +} + +TextureManagerInterface& Renderer::get_texture_manager() +{ + return *_texture_manager; +} + +void Renderer::begin(MTKView* view) +{ + _view = view; + + const auto width = static_cast(view.frame.size.width); + const auto height = static_cast(view.frame.size.height); + _uniforms.projection_matrix = matrix::make_ortho_projection(0, width, height, 0, -1, 1); + _command_buffer = [_command_queue.get() commandBuffer]; +} + +void Renderer::end() +{ + [_command_buffer presentDrawable:_view.currentDrawable]; + [_command_buffer commit]; +} + +MD3DERROR Renderer::d3dClear(DWORD dwColor) +{ + const auto red = static_cast((dwColor >> 16) & 0xFF) / 255.0f; + const auto green = static_cast((dwColor >> 8) & 0xFF) / 255.0f; + const auto blue = static_cast(dwColor & 0xFF) / 255.0f; + _clear_color = MTLClearColorMake(red, green, blue, 1.0f); + return MD3D_OK; +} + +MD3DERROR Renderer::d3dBeginScene() +{ + _commands.clear(); + return MD3D_OK; +} + +MD3DERROR Renderer::d3dEndScene() +{ + if (_commands.empty()) + { + return MD3D_OK; + } + + auto render_pass_descriptor = _view.currentRenderPassDescriptor; + if (render_pass_descriptor == nil) + { + return MD3D_OK; + } + + auto render_encoder = [_command_buffer renderCommandEncoderWithDescriptor:render_pass_descriptor]; + + // prepare pipeline + [render_encoder setVertexBuffer:_position_buffer.get() offset:0 atIndex:0]; + [render_encoder setVertexBuffer:_color_buffer.get() offset:0 atIndex:1]; + [render_encoder setVertexBuffer:_uv_buffer.get() offset:0 atIndex:2]; + + [render_encoder setVertexBytes:&_uniforms length:sizeof(BasicUniforms) atIndex:3]; + + for (const auto& command : _commands) + { + switch (command.render_state.get_option(D3DRENDERSTATE_CULLMODE)) + { + case D3DCULL_CW: + { + [render_encoder setFrontFacingWinding:MTLWindingCounterClockwise]; + [render_encoder setCullMode:MTLCullModeBack]; + break; + } + + case D3DCULL_NONE: + { + [render_encoder setFrontFacingWinding:MTLWindingCounterClockwise]; + [render_encoder setCullMode:MTLCullModeNone]; + break; + } + + default: + break; + } + + if (command.render_state.get_option(D3DRENDERSTATE_ZWRITEENABLE) == FALSE) + { + [render_encoder setDepthStencilState:_depth_states[DepthStateType::Disabled].get()]; + } + else + { + [render_encoder setDepthStencilState:_depth_states[DepthStateType::Enabled].get()]; + } + + if (command.render_state.get_option(D3DRENDERSTATE_ALPHABLENDENABLE) == FALSE) + { + [render_encoder setRenderPipelineState:_pipeline_states[PipelineStateType::Default].get()]; + } + else + { + [render_encoder setRenderPipelineState:_pipeline_states[PipelineStateType::Blending].get()]; + } + + for (DWORD i = 0; i < 2; i++) + { + auto texture_handle = command.render_state.get_texture(i); + if (texture_handle) + { + id texture = _texture_manager->get(*texture_handle); + if (texture != nil) + { + [render_encoder setFragmentTexture:texture atIndex:i]; + } + } + } + + auto parameters = command.render_state.get_fragment_shader_parameters(); + [render_encoder setFragmentBytes:¶meters length:sizeof(FragmentShaderParameters) atIndex:0]; + + if (command.index_buffer_view.length == 0) + { + const auto start = command.vertex_buffer_view.offset; + const auto count = command.vertex_buffer_view.length; + [render_encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:start vertexCount:count]; + } + else + { + const auto offset = command.index_buffer_view.offset * sizeof(uint32_t); + [render_encoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle + indexCount:command.index_buffer_view.length + indexType:MTLIndexTypeUInt32 + indexBuffer:_index_buffer.get() + indexBufferOffset:offset + ]; + } + } + + [render_encoder endEncoding]; + + return MD3D_OK; +} + +MD3DERROR Renderer::d3dSetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState) +{ + _render_state.set_option(dwRenderStateType, dwRenderState); + return MD3D_OK; +} + +MD3DERROR Renderer::d3dGetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD *lpdwRenderState) +{ + *lpdwRenderState = _render_state.get_option(dwRenderStateType); + return MD3D_OK; +} + +MD3DERROR Renderer::d3dSetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue) +{ + _render_state.set_texture_stage_state(dwStage, dwState, dwValue); + return MD3D_OK; +} + +MD3DERROR Renderer::d3dTriangleFan(DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwVertexCount) +{ + // The system uses vertices v2, v3, and v1 to draw the first triangle; + // v3, v4, and v1 to draw the second triangle; v4, v5, and v1 to draw the third triangle; and so on. + // When flat shading is enabled, the system shades the triangle with the color from its first vertex. + + if (dwVertexCount < 3) + { + return MD3DERR_ILLEGALCALL; + } + + prepare_render_state(0); + + for (DWORD i = 1; i < dwVertexCount - 1; i++) + { + add_vertex(dwVertexTypeDesc, lpvVertices, 0); + add_vertex(dwVertexTypeDesc, lpvVertices, i); + add_vertex(dwVertexTypeDesc, lpvVertices, i + 1); + } + + return MD3D_OK; +} + +MD3DERROR Renderer::d3dTrianglesIndexed( + DWORD dwVertexTypeDesc, + LPVOID lpvVertices, + DWORD dwVertexCount, + LPWORD lpwIndices, + DWORD dwIndexCount +) +{ + prepare_render_state(dwVertexCount); + + auto& last_command = _commands.back(); + const auto vertex_offset = last_command.vertex_buffer_view.end(); + + for (DWORD i = 0; i < dwVertexCount; i++) + { + add_vertex(dwVertexTypeDesc, lpvVertices, i); + } + + const auto start_index = last_command.index_buffer_view.end(); + auto p = static_cast(_index_buffer.get().contents); + for (DWORD i = 0; i < dwIndexCount; i++) + { + p[start_index + i] = vertex_offset + lpwIndices[i]; + } + last_command.index_buffer_view.length += dwIndexCount; + + return MD3D_OK; +} + +MD3DERROR Renderer::d3dSetTexture(DWORD dwHandle, DWORD dwStage) +{ + _render_state.set_texture(dwHandle, dwStage); + return MD3D_OK; +} + +MD3DERROR Renderer::d3dSetTextureBlendMode(MD3DTEXTUREBLEND tbRGBBlend, MD3DTEXTUREBLEND tbAlphaBlend) +{ + switch (tbRGBBlend) + { + case MD3DTB_DIFFUSE: + d3dSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); + break; + case MD3DTB_TEXTURE1: + d3dSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); + break; + case MD3DTB_TEXTURE1_MOD_DIFFUSE: + d3dSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); + break; + default: + return MD3DERR_INVALIDPARAM; + } + + switch (tbAlphaBlend) + { + case MD3DTB_DIFFUSE: + d3dSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); + break; + case MD3DTB_TEXTURE1: + d3dSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); + break; + case MD3DTB_TEXTURE1_MOD_DIFFUSE: + d3dSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + break; + default: + return MD3DERR_INVALIDPARAM; + } + + return MD3D_OK; +} + +MD3DERROR Renderer::d3dTrianglesIndexed2( + DWORD dwVertexTypeDesc, + LPVOID lpvVertices, + DWORD dwVertexCount, + LPWORD lpwIndices, + DWORD dwIndexCount, + DWORD dwHandleTex0, + DWORD dwHandleTex1 +) +{ + d3dSetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); + d3dSetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2); + + d3dSetTexture(dwHandleTex0, 0); + d3dSetTexture(dwHandleTex1, 1); + auto result = d3dTrianglesIndexed(dwVertexTypeDesc, lpvVertices, dwVertexCount, lpwIndices, dwIndexCount); + + d3dSetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); + d3dSetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); + + return result; +} + +void Renderer::setup_depth_states() +{ + { + objc::Ref descriptor([MTLDepthStencilDescriptor new]); + descriptor.get().depthWriteEnabled = NO; + descriptor.get().depthCompareFunction = MTLCompareFunctionLessEqual; + + DepthStatePtr depth_state([_device newDepthStencilStateWithDescriptor:descriptor.get()]); + if (!depth_state) + { + throw std::runtime_error("setup_depth_state"); + } + _depth_states[DepthStateType::Disabled] = depth_state; + } + + { + objc::Ref descriptor([MTLDepthStencilDescriptor new]); + descriptor.get().depthWriteEnabled = YES; + descriptor.get().depthCompareFunction = MTLCompareFunctionLessEqual; + + DepthStatePtr depth_state([_device newDepthStencilStateWithDescriptor:descriptor.get()]); + if (!depth_state) + { + throw std::runtime_error("setup_depth_state"); + } + _depth_states[DepthStateType::Enabled] = depth_state; + } +} + +void Renderer::setup_pipeline_states() +{ + objc::Ref vd([MTLVertexDescriptor new]); + vd.get().attributes[0].format = MTLVertexFormatFloat3; + vd.get().attributes[0].bufferIndex = 0; + vd.get().attributes[0].offset = 0; + + vd.get().attributes[1].format = MTLVertexFormatFloat4; + vd.get().attributes[1].bufferIndex = 1; + vd.get().attributes[1].offset = 0; + + vd.get().attributes[2].format = MTLVertexFormatFloat2; + vd.get().attributes[2].bufferIndex = 2; + vd.get().attributes[2].offset = 0; + + vd.get().layouts[0].stride = 12; + vd.get().layouts[0].stepFunction = MTLVertexStepFunctionPerVertex; + + vd.get().layouts[1].stride = 16; + vd.get().layouts[1].stepFunction = MTLVertexStepFunctionPerVertex; + + vd.get().layouts[2].stride = 8; + vd.get().layouts[2].stepFunction = MTLVertexStepFunctionPerVertex; + + objc::Ref> vertex_function([_library newFunctionWithName:@"vertex_shader"]); + if (!vertex_function) + { + throw std::runtime_error("vertex function"); + } + + objc::Ref> fragment_function([_library newFunctionWithName:@"fragment_shader"]); + if (!fragment_function) + { + throw std::runtime_error("fragment function"); + } + + { + objc::Ref pd([MTLRenderPipelineDescriptor new]); + pd.get().vertexFunction = vertex_function.get(); + pd.get().vertexDescriptor = vd.get(); + pd.get().fragmentFunction = fragment_function.get(); + pd.get().colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm; + pd.get().depthAttachmentPixelFormat = MTLPixelFormatDepth32Float; + + NSError* error = nil; + objc::Ref> pipeline_state( + [_device newRenderPipelineStateWithDescriptor:pd.get() error:&error] + ); + if (!pipeline_state) + { + throw std::runtime_error("new render pipeline state"); + } + _pipeline_states[PipelineStateType::Default] = pipeline_state; + } + + { + objc::Ref pd([MTLRenderPipelineDescriptor new]); + pd.get().vertexFunction = vertex_function.get(); + pd.get().vertexDescriptor = vd.get(); + pd.get().fragmentFunction = fragment_function.get(); + pd.get().colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm; + pd.get().depthAttachmentPixelFormat = MTLPixelFormatDepth32Float; + + pd.get().colorAttachments[0].blendingEnabled = YES; + + pd.get().colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactorSourceAlpha; + pd.get().colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha; + + pd.get().colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha; + pd.get().colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha; + + NSError* error = nil; + PipelineStatePtr pipeline_state( + [_device newRenderPipelineStateWithDescriptor:pd.get() error:&error] + ); + if (!pipeline_state) + { + throw std::runtime_error("new render pipeline state"); + } + _pipeline_states[PipelineStateType::Blending] = pipeline_state; + } +} + +void Renderer::prepare_render_state(size_t index_count) +{ + if (_commands.empty()) + { + _commands.emplace_back(DrawCommand{ + _render_state, + BufferView{0, 0}, + BufferView{0, 0} + }); + return; + } + + const auto& last_command = _commands.back(); + + bool use_index = index_count > 0; + bool last_use_index = last_command.index_buffer_view.length > 0; + + if (_render_state == last_command.render_state && last_use_index == use_index) + { + return; + } + + _commands.emplace_back(DrawCommand{ + _render_state, + last_command.vertex_buffer_view.next(), + last_command.index_buffer_view.next() + }); +} + +void Renderer::add_vertex(DWORD vertex_type, LPVOID vertices, DWORD index) +{ + assert(!_commands.empty()); + + auto& last_command = _commands.back(); + size_t i = last_command.vertex_buffer_view.end(); + + VertexType type{vertex_type}; + auto vertex_offset = static_cast(vertices) + type.get_vertex_size() * index; + + if (vertex_type & D3DFVF_XYZRHW) + { + auto p = reinterpret_cast(vertex_offset); + + auto position = static_cast(_position_buffer.get().contents); + position[3 * i] = p[0]; + position[3 * i + 1] = p[1]; + position[3 * i + 2] = p[2]; + + vertex_offset += type.get_offset(D3DFVF_XYZRHW); + } + + if (vertex_type & D3DFVF_DIFFUSE) + { + auto p = reinterpret_cast(vertex_offset); + const auto argb = p[0]; + + auto color = static_cast(_color_buffer.get().contents); + color[4 * i] = static_cast((argb >> 16) & 0xFF) / 255.0f; + color[4 * i + 1] = static_cast((argb >> 8) & 0xFF) / 255.0f; + color[4 * i + 2] = static_cast(argb & 0xFF) / 255.0f; + color[4 * i + 3] = static_cast((argb >> 24) & 0xFF) / 255.0f; + + vertex_offset += type.get_offset(D3DFVF_DIFFUSE); + } + + if (vertex_type & D3DFVF_SPECULAR) + { + vertex_offset += type.get_offset(D3DFVF_SPECULAR); + } + + if (vertex_type & D3DFVF_TEX1) + { + auto p = reinterpret_cast(vertex_offset); + + auto uv = static_cast(_uv_buffer.get().contents); + uv[2 * i] = p[0]; + uv[2 * i + 1] = p[1]; + } + + last_command.vertex_buffer_view.length += 1; +} diff --git a/MechoSoma/macOS/RendererInterface.h b/MechoSoma/macOS/RendererInterface.h new file mode 100644 index 00000000..b751928d --- /dev/null +++ b/MechoSoma/macOS/RendererInterface.h @@ -0,0 +1,47 @@ +#pragma once + +#include "Md3d.h" + +namespace graphics +{ + +struct TextureManagerInterface; + +struct RendererInterface +{ + virtual ~RendererInterface() = default; + + virtual TextureManagerInterface& get_texture_manager() = 0; + + virtual MD3DERROR d3dClear(DWORD dwColor) = 0; + virtual MD3DERROR d3dBeginScene() = 0; + virtual MD3DERROR d3dEndScene() = 0; + virtual MD3DERROR d3dSetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState) = 0; + virtual MD3DERROR d3dGetRenderState(D3DRENDERSTATETYPE dwRenderStateType, DWORD *lpdwRenderState) = 0; + virtual MD3DERROR d3dSetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue) = 0; + virtual MD3DERROR d3dTriangleFan(DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwVertexCount) = 0; + virtual MD3DERROR d3dTrianglesIndexed( + DWORD dwVertexTypeDesc, + LPVOID lpvVertices, + DWORD dwVertexCount, + LPWORD lpwIndices, + DWORD dwIndexCount + ) = 0; + + virtual MD3DERROR d3dSetTexture(DWORD dwHandle, DWORD dwStage) = 0; + virtual MD3DERROR d3dSetTextureBlendMode(MD3DTEXTUREBLEND tbRGBBlend, MD3DTEXTUREBLEND tbAlphaBlend) = 0; + + virtual MD3DERROR d3dTrianglesIndexed2( + DWORD dwVertexTypeDesc, + LPVOID lpvVertices, + DWORD dwVertexCount, + LPWORD lpwIndices, + DWORD dwIndexCount, + DWORD dwHandleTex0, + DWORD dwHandleTex1 + ) = 0; +}; + +RendererInterface& get_renderer(); + +} diff --git a/MechoSoma/macOS/ShaderCommon.h b/MechoSoma/macOS/ShaderCommon.h new file mode 100644 index 00000000..e2e341f7 --- /dev/null +++ b/MechoSoma/macOS/ShaderCommon.h @@ -0,0 +1,24 @@ +#ifndef SHADER_COMMON_H +#define SHADER_COMMON_H + +#include + +struct BasicUniforms +{ + simd_float4x4 projection_matrix; +}; + +enum class TextureColorOperation +{ + Disable, + Texture, + Modulate +}; + +struct FragmentShaderParameters +{ + TextureColorOperation color_operation_1; + TextureColorOperation color_operation_2; +}; + +#endif diff --git a/MechoSoma/macOS/TextureManager.h b/MechoSoma/macOS/TextureManager.h new file mode 100644 index 00000000..2db5c0a4 --- /dev/null +++ b/MechoSoma/macOS/TextureManager.h @@ -0,0 +1,62 @@ +#pragma once + +#import + +#include + +#include "Ref.h" +#include "TextureManagerInterface.h" + +namespace graphics +{ + +class TextureManager final : public TextureManagerInterface +{ +public: + explicit TextureManager(id device); + + id get(DWORD dwHandle); + + TextureManager(const TextureManager&) = delete; + TextureManager(TextureManager&&) = delete; + TextureManager& operator=(const TextureManager&) = delete; + TextureManager& operator=(TextureManager&&) = delete; + + MD3DERROR d3dGetTextureFormatData(DWORD dwTexFormatID, M3DTEXTUREFORMAT* pData) override; + MD3DERROR d3dCreateTexture(DWORD dwWidth, DWORD dwHeight, DWORD dwTexFormatID, DWORD* lpdwHandle) override; + MD3DERROR d3dDeleteTexture(DWORD dwHandle) override; + MD3DERROR d3dLockTexture(DWORD dwHandle, VOID** lplpTexture, DWORD* lpPitch) override; + MD3DERROR d3dLockTexture( + DWORD dwHandle, + DWORD dwLeft, + DWORD dwTop, + DWORD dwRight, + DWORD dwBottom, + VOID** lplpTexture, + DWORD* lpPitch + ) override; + MD3DERROR d3dUnlockTexture(DWORD dwHandle) override; + +private: + struct TextureEntry + { + DWORD original_format_id; + objc::Ref> texture; + std::vector lock_buffer; + DWORD pitch; + bool is_locked; + }; + + void update_texture(TextureEntry& entry); + +private: + id _device; + + using TextureEntryPtr = std::unique_ptr; + std::vector _textures; + + std::vector _argb_buffer; + std::vector _bgra_buffer; +}; + +} diff --git a/MechoSoma/macOS/TextureManager.mm b/MechoSoma/macOS/TextureManager.mm new file mode 100644 index 00000000..bd306b2e --- /dev/null +++ b/MechoSoma/macOS/TextureManager.mm @@ -0,0 +1,439 @@ +#include "TextureManager.h" + +#import + +#include +#include +#include + +using namespace graphics; + +struct TTextureFormat +{ + DWORD dwFormatID; + BOOL bSupported; + + DWORD dwRGBAlphaBitMask; + DWORD dwRBitMask; + DWORD dwGBitMask; + DWORD dwBBitMask; + + // This is used for matching + DWORD dwRGBBitCount; + BOOL bPalette8; + DWORD dwRBitCount; + DWORD dwGBitCount; + DWORD dwBBitCount; + DWORD dwAlphaBitCount; + + // Calculated shifts for RGBA + DWORD dwRBitShift; + DWORD dwGBitShift; + DWORD dwBBitShift; + DWORD dwAlphaBitShift; +}; + +static std::array texture_formats +{ + TTextureFormat + { + D3DTEXFMT_RGB565, + TRUE, + 0, + 0b0000000000011111, + 0b0000011111100000, + 0b1111100000000000, + 16, + FALSE, + 5, + 6, + 5, + 0, + 0, + 0, + 0, + 0 + }, + TTextureFormat + { + D3DTEXFMT_RGB555, + FALSE, + 0, + 0, + 0, + 0, + 16, + FALSE, + 5, + 5, + 5, + 0, + 0, + 0, + 0, + 0 + }, + TTextureFormat + { + D3DTEXFMT_ARGB4444, + TRUE, + 0b1111000000000000, + 0b0000000000001111, + 0b0000000011110000, + 0b0000111100000000, + 16, + FALSE, + 4, + 4, + 4, + 4, + 0, + 0, + 0, + 0 + }, + TTextureFormat + { + D3DTEXFMT_ARGB1555, + TRUE, + 0b1000000000000000, + 0b0000000000011111, + 0b0000001111100000, + 0b0111110000000000, + 16, + FALSE, + 5, + 5, + 5, + 1, + 0, + 0, + 0, + 0 + }, + TTextureFormat + { + D3DTEXFMT_RGBA8888, + TRUE, + 0x000000FF, + 0x0000FF00, + 0x00FF0000, + 0xFF000000, + 32, + FALSE, + 8, + 8, + 8, + 8, + 0, + 0, + 0, + 0 + }, + TTextureFormat + { + D3DTEXFMT_PAL8, + TRUE, + 0, + 0, + 0, + 0, + 8, + TRUE, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + } +}; + +constexpr DWORD GetMaskBitShift(DWORD dwBits) +{ + if (0 == dwBits) + { + return 0; + } + + DWORD dwShift = 0; + for (; (dwBits & 1) == 0; dwBits >>= 1) + { + dwShift++; + } + + return dwShift; +} + +constexpr DWORD GetMaskBitCount(DWORD dwBits) +{ + DWORD dwBitCount = 0; + for (; dwBits; dwBits >>= 1) + { + dwBitCount += (dwBits & 0x1); + } + + return dwBitCount; +} + +TextureManager::TextureManager(id device) : _device(device) +{ + for (auto& format : texture_formats) + { + format.dwRBitShift = GetMaskBitShift(format.dwRBitMask); + format.dwGBitShift = GetMaskBitShift(format.dwGBitMask); + format.dwBBitShift = GetMaskBitShift(format.dwBBitMask); + format.dwAlphaBitShift = GetMaskBitShift(format.dwRGBAlphaBitMask); + } +} + +id TextureManager::get(DWORD dwHandle) +{ + if (dwHandle >= _textures.size()) + { + return nil; + } + return _textures[dwHandle]->texture.get(); +} + +MD3DERROR TextureManager::d3dGetTextureFormatData(DWORD dwTexFormatID, M3DTEXTUREFORMAT* pData) +{ + for (const auto& format : texture_formats) + { + if (format.dwFormatID == dwTexFormatID && format.bSupported) + { + pData->dwTotalBitCount = format.dwRGBBitCount; + pData->bPalette8 = format.bPalette8; + + pData->dwAlphaBitCount = format.dwAlphaBitCount; + pData->dwRBitCount = format.dwRBitCount; + pData->dwGBitCount = format.dwGBitCount; + pData->dwBBitCount = format.dwBBitCount; + + pData->dwAlphaBitMask = format.dwRGBAlphaBitMask; + pData->dwRBitMask = format.dwRBitMask; + pData->dwGBitMask = format.dwGBitMask; + pData->dwBBitMask = format.dwBBitMask; + + pData->dwAlphaBitShift = format.dwAlphaBitShift; + pData->dwRBitShift = format.dwRBitShift; + pData->dwGBitShift = format.dwGBitShift; + pData->dwBBitShift = format.dwBBitShift; + + return MD3D_OK; + } + } + return MD3DERR_ILLEGALCALL; +} + +MD3DERROR TextureManager::d3dCreateTexture(DWORD dwWidth, DWORD dwHeight, DWORD dwTexFormatID, DWORD* lpdwHandle) +{ + assert(dwWidth == dwHeight); + assert(GetMaskBitCount(dwWidth) == 1); + assert(GetMaskBitCount(dwHeight) == 1); + assert(dwHeight <= 256); + assert(dwWidth <= 256); + + auto p = std::find_if(texture_formats.cbegin(), texture_formats.cend(), [&](const auto& format) { + return format.dwFormatID == dwTexFormatID && format.bSupported; + }); + if (p == texture_formats.cend()) + { + return MD3DERR_ILLEGALCALL; + } + + auto pixel_format = p->bPalette8 ? MTLPixelFormatA8Unorm : MTLPixelFormatBGRA8Unorm; + auto* descriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixel_format + width:dwWidth + height:dwHeight + mipmapped:NO]; + descriptor.storageMode = MTLStorageModeShared; + objc::Ref> texture([_device newTextureWithDescriptor:descriptor]); + + *lpdwHandle = _textures.size(); + + const DWORD pitch = dwHeight * (p->dwRGBBitCount / 8); + _textures.push_back(std::make_unique(TextureEntry{ + dwTexFormatID, + texture, + std::vector(pitch * dwHeight), + pitch, + false + })); + + return MD3D_OK; +} + +MD3DERROR TextureManager::d3dDeleteTexture(DWORD dwHandle) +{ + if (dwHandle >= _textures.size()) + { + return MD3DERR_ILLEGALCALL; + } + + return MD3D_OK; +} + +MD3DERROR TextureManager::d3dLockTexture(DWORD dwHandle, VOID** lplpTexture, DWORD* lpPitch) +{ + if (dwHandle >= _textures.size()) + { + return MD3DERR_ILLEGALCALL; + } + + auto entry = _textures[dwHandle].get(); + if (entry->is_locked) + { + return MD3DERR_ILLEGALCALL; + } + entry->is_locked = true; + + *lplpTexture = reinterpret_cast(entry->lock_buffer.data()); + *lpPitch = entry->pitch; + + return MD3D_OK; +} + +MD3DERROR TextureManager::d3dLockTexture( + DWORD dwHandle, + DWORD dwLeft, + DWORD dwTop, + DWORD dwRight, + DWORD dwBottom, + VOID** lplpTexture, + DWORD* lpPitch +) +{ + return d3dLockTexture(dwHandle, lplpTexture, lpPitch); +} + +MD3DERROR TextureManager::d3dUnlockTexture(DWORD dwHandle) +{ + if (dwHandle >= _textures.size()) + { + return MD3DERR_ILLEGALCALL; + } + + auto entry = _textures[dwHandle].get(); + if (!entry->is_locked) + { + return MD3DERR_ILLEGALCALL; + } + + update_texture(*entry); + entry->is_locked = false; + + return MD3D_OK; +} + +void TextureManager::update_texture(TextureEntry& entry) +{ + auto t = entry.texture.get(); + const auto image_height = t.height; + const auto image_width = t.width; + + switch (entry.original_format_id) + { + case D3DTEXFMT_RGB565: + { + vImage_Buffer source; + source.data = entry.lock_buffer.data(); + source.height = image_height; + source.width = image_width; + source.rowBytes = entry.pitch; + + vImage_Buffer target; + _argb_buffer.resize(4 * image_width * image_height); + target.data = _argb_buffer.data(); + target.height = image_height; + target.width = image_width; + target.rowBytes = 4 * image_width; + + vImageConvert_RGB565toARGB8888(255, &source, &target, kvImageNoFlags); + break; + } + + case D3DTEXFMT_ARGB4444: + { + const auto input = reinterpret_cast(entry.lock_buffer.data()); + + _argb_buffer.resize(4 * image_width * image_height); + auto output = reinterpret_cast(_argb_buffer.data()); + + const uint16_t alpha_mask = 0b1111000000000000; + const uint16_t red_mask = 0b0000000000001111; + const uint16_t green_mask = 0b0000000011110000; + const uint16_t blue_mask = 0b0000111100000000; + + const size_t count = entry.lock_buffer.size() / sizeof(uint16_t); + std::array channels{ 0 }; + for (size_t i = 0; i < count; i++) + { + const auto color = input[i]; + + channels[0] = (color & alpha_mask) >> 12; + channels[1] = color & red_mask; + channels[2] = (color & green_mask) >> 4; + channels[3] = (color & blue_mask) >> 8; + + uint32_t result = 0; + int shift = 0; + for (auto c8 : channels) + { + uint32_t c32 = (c8 * 255 + 7) / 15; + result |= c32 << shift; + shift += 8; + } + output[i] = result; + } + break; + } + + case D3DTEXFMT_RGB555: + case D3DTEXFMT_ARGB1555: + { + vImage_Buffer source; + source.data = entry.lock_buffer.data(); + source.height = image_height; + source.width = image_width; + source.rowBytes = entry.pitch; + + vImage_Buffer target; + _argb_buffer.resize(4 * image_width * image_height); + target.data = _argb_buffer.data(); + target.height = image_height; + target.width = image_width; + target.rowBytes = 4 * image_width; + + vImageConvert_ARGB1555toARGB8888(&source, &target, kvImageNoFlags); + break; + } + + default: + break; + } + + _bgra_buffer.resize(4 * image_width * image_height); + + vImage_Buffer source; + source.data = _argb_buffer.data(); + source.height = image_height; + source.width = image_width; + source.rowBytes = 4 * image_width; + + vImage_Buffer target; + target.data = _bgra_buffer.data(); + target.height = image_height; + target.width = image_width; + target.rowBytes = 4 * image_width; + + // from ARGB (0, 1, 2, 3) to BGRA + const uint8_t permute_map[4] = {3, 2, 1, 0}; + vImagePermuteChannels_ARGB8888(&source, &target, permute_map, kvImageNoFlags); + + MTLRegion region = MTLRegionMake2D(0, 0, image_width, image_height); + const void* pixel_bytes = _bgra_buffer.data(); + [t replaceRegion:region mipmapLevel:0 withBytes:pixel_bytes bytesPerRow:4 * image_width]; +} diff --git a/MechoSoma/macOS/TextureManagerInterface.h b/MechoSoma/macOS/TextureManagerInterface.h new file mode 100644 index 00000000..8d0bad83 --- /dev/null +++ b/MechoSoma/macOS/TextureManagerInterface.h @@ -0,0 +1,29 @@ +#pragma once + +#include "Md3d.h" + +namespace graphics +{ + +struct TextureManagerInterface +{ + virtual ~TextureManagerInterface() = default; + + virtual MD3DERROR d3dGetTextureFormatData(DWORD dwTexFormatID, M3DTEXTUREFORMAT* pData) = 0; + virtual MD3DERROR d3dCreateTexture(DWORD dwWidth, DWORD dwHeight, DWORD dwTexFormatID, DWORD* lpdwHandle) = 0; + virtual MD3DERROR d3dDeleteTexture(DWORD dwHandle) = 0; + virtual MD3DERROR d3dLockTexture(DWORD dwHandle, VOID** lplpTexture, DWORD* lpPitch) = 0; + virtual MD3DERROR d3dLockTexture( + DWORD dwHandle, + DWORD dwLeft, + DWORD dwTop, + DWORD dwRight, + DWORD dwBottom, + VOID** lplpTexture, + DWORD* lpPitch + ) = 0; + virtual MD3DERROR d3dUnlockTexture(DWORD dwHandle) = 0; + +}; + +} diff --git a/MechoSoma/macOS/VertexType.h b/MechoSoma/macOS/VertexType.h new file mode 100644 index 00000000..bf02f625 --- /dev/null +++ b/MechoSoma/macOS/VertexType.h @@ -0,0 +1,90 @@ +#pragma once + +#include + +#include "Md3d.h" + +namespace graphics +{ + +struct VertexType +{ + explicit VertexType(DWORD vertex_type) + { + if (vertex_type & D3DFVF_XYZRHW) + { + // float, float, float, float + _offsets[0] = 4 * sizeof(float); + _vertex_size += _offsets[0]; + } + + if (vertex_type & D3DFVF_XYZ) + { + // float, float, float + _offsets[0] = 3 * sizeof(float); + _vertex_size += _offsets[0]; + } + + if (vertex_type & D3DFVF_DIFFUSE) + { + // DWORD in ARGB order + _offsets[1] = sizeof(DWORD); + _vertex_size += _offsets[1]; + } + + if (vertex_type & D3DFVF_SPECULAR) + { + // DWORD in ARGB order + _offsets[2] = sizeof(DWORD); + _vertex_size += _offsets[2]; + } + + if (vertex_type & D3DFVF_TEX1) + { + // float, float + _offsets[3] = 2 * sizeof(float); + _vertex_size += _offsets[3]; + } + } + + [[nodiscard]] size_t get_offset(DWORD vertex_type) const + { + if (vertex_type & D3DFVF_XYZRHW) + { + return _offsets[0]; + } + + if (vertex_type & D3DFVF_XYZ) + { + return _offsets[0]; + } + + if (vertex_type & D3DFVF_DIFFUSE) + { + return _offsets[1]; + } + + if (vertex_type & D3DFVF_SPECULAR) + { + return _offsets[2]; + } + + if (vertex_type & D3DFVF_TEX1) + { + return _offsets[3]; + } + + return 0; + } + + [[nodiscard]] size_t get_vertex_size() const + { + return _vertex_size; + } + +private: + size_t _vertex_size = 0; + std::array _offsets{0}; +}; + +} diff --git a/MechoSoma/macOS/main.mm b/MechoSoma/macOS/main.mm new file mode 100644 index 00000000..324702e4 --- /dev/null +++ b/MechoSoma/macOS/main.mm @@ -0,0 +1,44 @@ +#import + +#import "GameViewController.h" + +@interface AppDelegate: NSObject + +@property (nonatomic, retain) NSWindow *window; + +@end + +@implementation AppDelegate: NSObject + +- (id)init +{ + if (self = [super init]) + { + self.window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1024, 768) + styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable + backing:NSBackingStoreBuffered + defer:NO]; + self.window.contentViewController = [[GameViewController alloc] initWithNibName:nil bundle:nil]; + [self.window makeFirstResponder:self.window.contentViewController]; + } + return self; +} + +- (void)applicationWillFinishLaunching:(NSNotification *)notification +{ + self.window.title = NSProcessInfo.processInfo.processName; + [self.window makeKeyAndOrderFront:self]; +} + +@end + +int main(int argc, const char * argv[]) +{ + @autoreleasepool { + NSApplication *application = [NSApplication sharedApplication]; + AppDelegate *appDelegate = [AppDelegate new]; + application.delegate = appDelegate; + [application run]; + } + return EXIT_SUCCESS; +}