diff --git a/build.bat b/build.bat index 2e51ddb..51fbb27 100644 --- a/build.bat +++ b/build.bat @@ -1,7 +1,7 @@ @echo off call "..\misc\compile_setup.bat" -bld --dont_compile_core +rem bld --dont_compile_core cd build core_main.exe examples/game2d.core rem bld --dont_compile_core --link=vendor/raylib/windows/raylibdll.lib diff --git a/build/modules/raylib.core b/build/modules/raylib.core index 1ed787e..a65b858 100644 --- a/build/modules/raylib.core +++ b/build/modules/raylib.core @@ -1,4 +1,8 @@ +PI :: 3.14159265358979323846 +DEG2RAD :: PI/180.0 +RAD2DEG :: 180.0/PI + Vector2 :: struct x: F32 y: F32 @@ -15,7 +19,7 @@ Vector4 :: struct w: F32 Color :: struct - r: uchar // @todo: Add C types + r: uchar g: uchar b: uchar a: uchar @@ -34,13 +38,219 @@ Image :: struct format: int Texture :: struct - id: U32 // @todo: Add C types + id: uint width: int height: int mipmaps: int format: int -Texture2D :: Texture +Texture2D :: Texture +TextureCubemap :: Texture + +RenderTexture :: struct + id: uint + texture: Texture + depth: Texture + +RenderTexture2D :: RenderTexture + +// N-Patch layout info +NPatchInfo :: struct + source: Rectangle // Texture source rectangle + left: int // Left border offset + top: int // Top border offset + right: int // Right border offset + bottom: int // Bottom border offset + layout: NPatchLayout // Layout of the n-patch: 3x3 1x3 or 3x1 + +// Font character info +GlyphInfo :: struct + value: rune // Character value (Unicode) + offsetX: int // Character offset X when drawing + offsetY: int // Character offset Y when drawing + advanceX: int // Character advance position X + image: Image // Character image data + +// Font type includes texture and charSet array data +Font :: struct + baseSize: int // Base size (default chars height) + charsCount: int // Number of characters + charsPadding: int // Padding around the chars + texture: Texture2D // Characters texture atlas + recs: *Rectangle // Characters rectangles in texture + chars: *GlyphInfo // Characters info data + +// Camera type defines a camera position/orientation in 3d space +Camera3D :: struct + position: Vector3 // Camera position + target: Vector3 // Camera target it looks-at + up: Vector3 // Camera up vector (rotation over its axis) + fovy: F32 // Camera field-of-view apperture in Y (degrees) in perspective used as near plane width in orthographic + projection: CameraProjection // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC + +Camera :: Camera3D // Camera type fallback defaults to Camera3D + +// Camera2D type defines a 2d camera +Camera2D :: struct + offset: Vector2 // Camera offset (displacement from target) + target: Vector2 // Camera target (rotation and zoom origin) + rotation: F32 // Camera rotation in degrees + zoom: F32 // Camera zoom (scaling) should be 1.0f by default + +// Vertex data definning a mesh +// NOTE: Data stored in CPU memory (and GPU) +Mesh :: struct + vertexCount: int // Number of vertices stored in arrays + triangleCount: int // Number of triangles stored (indexed or not) + + // Default vertex data + vertices: *F32 // Vertex position (XYZ - 3 components per vertex) (shader-location = 0) + texcoords: *F32 // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1) + texcoords2: *F32 // Vertex second texture coordinates (useful for lightmaps) (shader-location = 5) + normals: *F32 // Vertex normals (XYZ - 3 components per vertex) (shader-location = 2) + tangents: *F32 // Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4) + colors: *U8 // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) + indices: *U16 // Vertex indices (in case vertex data comes indexed) + + // Animation vertex data + animVertices: *F32 // Animated vertex positions (after bones transformations) + animNormals: *F32 // Animated normals (after bones transformations) + boneIds: *U8 // Vertex bone ids up to 4 bones influence by vertex (skinning) + boneWeights: *F32 // Vertex bone weight up to 4 bones influence by vertex (skinning) + + // OpenGL identifiers + vaoId: U32 // OpenGL Vertex Array Object id + vboId: *U32 // OpenGL Vertex Buffer Objects id (default vertex data) + +// Shader type (generic) +Shader :: struct + id: uint // Shader program id + locs: *int // Shader locations array (MAX_SHADER_LOCATIONS) + +// Material texture map +MaterialMap :: struct + texture: Texture2D // Material map texture + color: Color // Material map color + value: F32 // Material map value + +// Material type (generic) +Material :: struct + shader: Shader // Material shader + maps: *MaterialMap // Material maps array (MAX_MATERIAL_MAPS) + params: [4]F32 // Material generic parameters (if required) + +// Transformation properties +Transform :: struct + translation: Vector3 // Translation + rotation: Quaternion // Rotation + scale: Vector3 // Scale + +// Bone information +BoneInfo :: struct + name: [32]char // Bone name + parent: int // Bone parent + +// Model type +Model :: struct + transform: Matrix // Local transform matrix + + meshCount: int // Number of meshes + materialCount: int // Number of materials + meshes: *Mesh // Meshes array + materials: *Material // Materials array + meshMaterial: *int // Mesh material number + + // Animation data + boneCount: int // Number of bones + bones: *BoneInfo // Bones information (skeleton) + bindPose: *Transform // Bones base transformation (pose) + +// Model animation +ModelAnimation :: struct + boneCount: int // Number of bones + frameCount: int // Number of animation frames + bones: *BoneInfo // Bones information (skeleton) + framePoses: **Transform // Poses array by frame + +// Ray type (useful for raycast) +Ray :: struct + position: Vector3 // Ray position (origin) + direction: Vector3 // Ray direction + +// RayCollision ray hit information +RayCollision :: struct + hit: bool // Did the ray hit something? + distance: F32 // Distance to nearest hit + point: Vector3 // Point of nearest hit + normal: Vector3 // Surface normal of hit + +// Bounding box type +BoundingBox :: struct + min: Vector3 // Minimum vertex box-corner + max: Vector3 // Maximum vertex box-corner + +// Wave type defines audio wave data +Wave :: struct + frameCount: uint // Total number of frames (considering channels) + sampleRate: uint // Frequency (samples per second) + sampleSize: uint // Bit depth (bits per sample): 8 16 32 (24 not supported) + channels: uint // Number of channels (1-mono 2-stereo) + data: *void // Buffer data pointer + +// Audio stream type +// NOTE: Actual structs are defined internally in raudio module +AudioStream :: struct + buffer: *void // Pointer to internal data used by the audio system + processor: *void // Pointer to internal data processor useful for audio effects + + sampleRate: uint // Frequency (samples per second) + sampleSize: uint // Bit depth (bits per sample): 8 16 32 (24 not supported) + channels: uint // Number of channels (1-mono 2-stereo) + +// Sound source type +Sound :: struct + stream: AudioStream // Audio stream + frameCount: uint // Total number of frames (considering channels) + +// Music stream type (audio file streaming from memory) +// NOTE: Anything longer than ~10 seconds should be streamed +Music :: struct + stream: AudioStream // Audio stream + frameCount: uint // Total number of frames (considering channels) + looping: bool // Music looping enable + + ctxType: int // Type of music context (audio filetype) + ctxData: *void // Audio context data depends on type + +// Head-Mounted-Display device parameters +VrDeviceInfo :: struct + hResolution: int // Horizontal resolution in pixels + vResolution: int // Vertical resolution in pixels + hScreenSize: F32 // Horizontal size in meters + vScreenSize: F32 // Vertical size in meters + vScreenCenter: F32 // Screen center in meters + eyeToScreenDistance: F32 // Distance between eye and display in meters + lensSeparationDistance: F32 // Lens separation distance in meters + interpupillaryDistance: F32 // IPD (distance between pupils) in meters + lensDistortionValues: [4]F32 // Lens distortion constant parameters + chromaAbCorrection: [4]F32 // Chromatic aberration correction parameters + +// VR Stereo rendering configuration for simulator +VrStereoConfig :: struct + projection: [2]Matrix // VR projection matrices (per eye) + viewOffset: [2]Matrix // VR view offset matrices (per eye) + leftLensCenter: [2]F32 // VR left lens center + rightLensCenter: [2]F32 // VR right lens center + leftScreenCenter: [2]F32 // VR left screen center + rightScreenCenter: [2]F32 // VR right screen center + scale: [2]F32 // VR distortion scale + scaleIn: [2]F32 // VR distortion scale in + +// File path list +FilePathList :: struct + capacity: uint // Filepaths max entries + count: uint // Filepaths entries count + paths: **char // Filepaths entries // Some Basic Colors // NOTE: Custom raylib color palette for amazing visuals on WHITE background @@ -71,6 +281,30 @@ BLANK := Color{ 0, 0, 0, 0 } // Blank (Transparent) MAGENTA := Color{ 255, 0, 255, 255 } // Magenta RAYWHITE := Color{ 245, 245, 245, 255 } // My own White (raylib logo) +FLAG_VSYNC_HINT :: 0x00000040 // Set to try enabling V-Sync on GPU +FLAG_FULLSCREEN_MODE :: 0x00000002 // Set to run program in fullscreen +FLAG_WINDOW_RESIZABLE :: 0x00000004 // Set to allow resizable window +FLAG_WINDOW_UNDECORATED :: 0x00000008 // Set to disable window decoration (frame and buttons) +FLAG_WINDOW_HIDDEN :: 0x00000080 // Set to hide window +FLAG_WINDOW_MINIMIZED :: 0x00000200 // Set to minimize window (iconify) +FLAG_WINDOW_MAXIMIZED :: 0x00000400 // Set to maximize window (expanded to monitor) +FLAG_WINDOW_UNFOCUSED :: 0x00000800 // Set to window non focused +FLAG_WINDOW_TOPMOST :: 0x00001000 // Set to window always on top +FLAG_WINDOW_ALWAYS_RUN :: 0x00000100 // Set to allow windows running while minimized +FLAG_WINDOW_TRANSPARENT :: 0x00000010 // Set to allow transparent framebuffer +FLAG_WINDOW_HIGHDPI :: 0x00002000 // Set to support HighDPI +FLAG_WINDOW_MOUSE_PASSTHROUGH :: 0x00004000 // Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED +FLAG_MSAA_4X_HINT :: 0x00000020 // Set to try enabling MSAA 4X +FLAG_INTERLACED_HINT :: 0x00010000 // Set to try enabling interlaced video format (for V3D) + +LOG_ALL :: 0 // Display all logs +LOG_TRACE :: 1 // Trace logging, intended for internal use only +LOG_DEBUG :: 2 // Debug logging, used for internal debugging, it should be disabled on release builds +LOG_INFO :: 3 // Info logging, used for program execution info +LOG_WARNING :: 4 // Warning logging, used on recoverable failures +LOG_ERROR :: 5 // Error logging, used on unrecoverable failures +LOG_FATAL :: 6 // Fatal logging, used to abort program: exit(EXIT_FAILURE) +LOG_NONE :: 7 // Disable logging KEY_NULL :: 0 // Key: NULL, used for no key pressed // Alphanumeric keys @@ -701,6 +935,7 @@ TextLength :: #foreign (text: *char): uint // TextFormat is defined at the bottom of this file +TextFormat :: #foreign (str: *char, ...): *char TextSubtext :: #foreign (text: *char, position: int, length: int): *char // Get a piece of a text string TextReplace :: #foreign (text: *uchar, replace: *char, by: *char): *uchar // Replace text string (WARNING: memory must be freed!) TextInsert :: #foreign (text: *char, insert: *char, position: int): *uchar // Insert text in a position (WARNING: memory must be freed!) @@ -745,7 +980,6 @@ DrawGrid :: #foreign (slices: int, spacing: F32) //------------------------------------------------------------------------------------ // Model 3d Loading and Drawing Functions (Module: models) //------------------------------------------------------------------------------------ -/* // Model management functions @@ -780,14 +1014,14 @@ GenMeshTangents :: #foreign (mesh: *Mesh) // Mesh generation functions GenMeshPoly :: #foreign (sides: int, radius: F32): Mesh // Generate polygonal mesh -GenMeshPlane :: #foreign (width, lengthL: F32, resX, resZ: int): Mesh // Generate plane mesh (with subdivisions) -GenMeshCube :: #foreign (width, height, length: F32): Mesh // Generate cuboid mesh -GenMeshSphere :: #foreign (radius: F32, rings, slices: int): Mesh // Generate sphere mesh (standard sphere) -GenMeshHemiSphere :: #foreign (radius: F32, rings, slices: int): Mesh // Generate half-sphere mesh (no bottom cap) -GenMeshCylinder :: #foreign (radius, height: F32, slices: int): Mesh // Generate cylinder mesh -GenMeshCone :: #foreign (radius, height: F32, slices: int): Mesh // Generate cone/pyramid mesh -GenMeshTorus :: #foreign (radius, size: F32, radSeg, sides: int): Mesh // Generate torus mesh -GenMeshKnot :: #foreign (radius, size: F32, radSeg, sides: int): Mesh // Generate trefoil knot mesh +GenMeshPlane :: #foreign (width: F32, lengthL: F32, resX: int, resZ: int): Mesh // Generate plane mesh (with subdivisions) +GenMeshCube :: #foreign (width: F32, height: F32, length: F32): Mesh // Generate cuboid mesh +GenMeshSphere :: #foreign (radius: F32, rings: int, slices: int): Mesh // Generate sphere mesh (standard sphere) +GenMeshHemiSphere :: #foreign (radius: F32, rings: int, slices: int): Mesh // Generate half-sphere mesh (no bottom cap) +GenMeshCylinder :: #foreign (radius: F32, height: F32, slices: int): Mesh // Generate cylinder mesh +GenMeshCone :: #foreign (radius: F32, height: F32, slices: int): Mesh // Generate cone/pyramid mesh +GenMeshTorus :: #foreign (radius: F32, size: F32, radSeg: int, sides: int): Mesh // Generate torus mesh +GenMeshKnot :: #foreign (radius: F32, size: F32, radSeg: int, sides: int): Mesh // Generate trefoil knot mesh GenMeshHeightmap :: #foreign (heightmap: Image, size: Vector3): Mesh // Generate heightmap mesh from image data GenMeshCubicmap :: #foreign (cubicmap: Image, cubeSize: Vector3): Mesh // Generate cubes-based map mesh from image data @@ -811,13 +1045,13 @@ IsModelAnimationValid :: #foreign (model: Model, anim: ModelAnimation): bool // Collision detection functions CheckCollisionSpheres :: #foreign (center1: Vector3, radius1: F32, center2: Vector3, radius2: F32): bool // Check collision between two spheres -CheckCollisionBoxes :: #foreign (box1, box2: BoundingBox): bool // Check collision between two bounding boxes +CheckCollisionBoxes :: #foreign (box1: BoundingBox, box2: BoundingBox): bool // Check collision between two bounding boxes CheckCollisionBoxSphere :: #foreign (box: BoundingBox, center: Vector3, radius: F32): bool // Check collision between box and sphere GetRayCollisionSphere :: #foreign (ray: Ray, center: Vector3, radius: F32): RayCollision // Get collision info between ray and sphere GetRayCollisionBox :: #foreign (ray: Ray, box: BoundingBox): RayCollision // Get collision info between ray and box GetRayCollisionMesh :: #foreign (ray: Ray, mesh: Mesh, transform: Matrix): RayCollision // Get collision info between ray and mesh -GetRayCollisionTriangle :: #foreign (ray: Ray, p1, p2, p3: Vector3): RayCollision // Get collision info between ray and triangle -GetRayCollisionQuad :: #foreign (ray: Ray, p1, p2, p3, p4: Vector3): RayCollision // Get collision info between ray and quad +GetRayCollisionTriangle :: #foreign (ray: Ray, p1: Vector3, p2: Vector3, p3: Vector3): RayCollision // Get collision info between ray and triangle +GetRayCollisionQuad :: #foreign (ray: Ray, p1: Vector4, p2: Vector4, p3: Vector4, p4: Vector3): RayCollision // Get collision info between ray and quad //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) @@ -855,8 +1089,8 @@ SetSoundVolume :: #foreign (sound: Sound, volume: F32) SetSoundPitch :: #foreign (sound: Sound, pitch: F32) // Set pitch for a sound (1.0 is base level) SetSoundPan :: #foreign (sound: Sound, pan: F32) // Set pan for a sound (0.5 is center) WaveCopy :: #foreign (wave: Wave): Wave // Copy a wave to a new wave -WaveCrop :: #foreign (wave: *Wave, initSample, finalSample: int) // Crop a wave to defined samples range -WaveFormat :: #foreign (wave: *Wave, sampleRate, sampleSize: int, channels: int) // Convert wave data to desired format +WaveCrop :: #foreign (wave: *Wave, initSample: int, finalSample: int) // Crop a wave to defined samples range +WaveFormat :: #foreign (wave: *Wave, sampleRate: int, sampleSize: int, channels: int) // Convert wave data to desired format LoadWaveSamples :: #foreign (wave: Wave): *F32 // Load samples data from wave as a 32bit float data array UnloadWaveSamples :: #foreign (samples: *F32) // Unload samples data loaded with LoadWaveSamples() @@ -881,7 +1115,7 @@ GetMusicTimePlayed :: #foreign (music: Music): F32 // AudioStream management functions -LoadAudioStream :: #foreign (sampleRate, sampleSize: uint, channels: uint): AudioStream // Load audio stream (to stream raw audio pcm data) +LoadAudioStream :: #foreign (sampleRate: uint, sampleSize: uint, channels: uint): AudioStream // Load audio stream (to stream raw audio pcm data) IsAudioStreamReady :: #foreign (stream: AudioStream): bool // Checks if an audio stream is ready UnloadAudioStream :: #foreign (stream: AudioStream) // Unload audio stream and free memory UpdateAudioStream :: #foreign (stream: AudioStream, data: *void, frameCount: int) // Update audio stream buffers with data @@ -902,4 +1136,3 @@ DetachAudioStreamProcessor :: #foreign (stream: AudioStream, processor: AudioCal AttachAudioMixedProcessor :: #foreign (processor: AudioCallback) // Attach audio stream processor to the entire audio pipeline DetachAudioMixedProcessor :: #foreign (processor: AudioCallback) // Detach audio stream processor from the entire audio pipeline -*/ \ No newline at end of file diff --git a/build/examples/game2d.core b/build/rtsgame/main.core similarity index 97% rename from build/examples/game2d.core rename to build/rtsgame/main.core index 73de16c..a010d7b 100644 --- a/build/examples/game2d.core +++ b/build/rtsgame/main.core @@ -20,8 +20,6 @@ thing := 1 thing2 := thing :goto_block: for - - */ /* @@ -61,7 +59,6 @@ Add :: (a: *Array($T), item: T) a.data = realloc(a.data, SizeOf(T) * a.cap->U64) a.data[a.len++] = item -TextFormat :: #foreign (str: *char, ...): *char main :: (): int guys: Array(Guy) diff --git a/core_parsing.cpp b/core_parsing.cpp index 5f8c146..46bef6b 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -70,7 +70,7 @@ String core_stringify_message(Core_Ctx *pctx, Allocator *allocator, Core_Message for (S64 i = 0; i < buff_cap(msg->tokens); i += 1) { Token *it = msg->tokens[i]; if (it) { - b.addf("\n%s:%d", it->file.str, (S64)it->line + 1); + b.addf("\n%s(%d): error", it->file.str, (S64)it->line + 1); } }